Skip to content

Commit 993b51e

Browse files
committed
move matrices
1 parent c4ba2ef commit 993b51e

File tree

5 files changed

+164
-151
lines changed

5 files changed

+164
-151
lines changed

src/compas/datastructures/graph/graph.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from compas.geometry import Point
1919
from compas.geometry import Vector
2020
from compas.geometry import Line
21+
from compas.geometry import Box
2122
from compas.geometry import centroid_points
2223
from compas.geometry import subtract_vectors
2324
from compas.geometry import distance_point_point
@@ -26,6 +27,8 @@
2627
from compas.geometry import add_vectors
2728
from compas.geometry import scale_vector
2829
from compas.geometry import transform_points
30+
from compas.geometry import bounding_box
31+
from compas.geometry import oriented_bounding_box
2932
from compas.topology import astar_shortest_path
3033
from compas.topology import breadth_first_traverse
3134
from compas.topology import connected_components
@@ -2245,7 +2248,7 @@ def edge_length(self, edge):
22452248
return distance_point_point(a, b)
22462249

22472250
# --------------------------------------------------------------------------
2248-
# Transformations
2251+
# Transformations and BBox
22492252
# --------------------------------------------------------------------------
22502253

22512254
def transform(self, transformation):
@@ -2266,6 +2269,28 @@ def transform(self, transformation):
22662269
for point, node in zip(points, self.nodes()):
22672270
self.node_attributes(node, "xyz", point)
22682271

2272+
def aabb(self):
2273+
"""Calculate the axis aligned bounding box of the graph.
2274+
2275+
Returns
2276+
-------
2277+
:class:`compas.geometry.Box`
2278+
2279+
"""
2280+
nodes = self.nodes_attributes("xyz")
2281+
return Box.from_bounding_box(bounding_box(nodes))
2282+
2283+
def obb(self):
2284+
"""Calculate the oriented bounding box of the graph.
2285+
2286+
Returns
2287+
-------
2288+
:class:`compas.geometry.Box`
2289+
2290+
"""
2291+
nodes = self.nodes_attributes("xyz")
2292+
return Box.from_bounding_box(oriented_bounding_box(nodes))
2293+
22692294
# --------------------------------------------------------------------------
22702295
# Other Methods
22712296
# --------------------------------------------------------------------------
@@ -2380,7 +2405,7 @@ def adjacency_matrix(self, rtype="array"):
23802405
Constructed adjacency matrix.
23812406
23822407
"""
2383-
from compas.topology import adjacency_matrix
2408+
from compas.matrices import adjacency_matrix
23842409

23852410
node_index = self.node_index()
23862411
adjacency = [[node_index[nbr] for nbr in self.neighbors(key)] for key in self.nodes()]
@@ -2400,7 +2425,7 @@ def connectivity_matrix(self, rtype="array"):
24002425
Constructed connectivity matrix.
24012426
24022427
"""
2403-
from compas.topology import connectivity_matrix
2428+
from compas.matrices import connectivity_matrix
24042429

24052430
node_index = self.node_index()
24062431
edges = [(node_index[u], node_index[v]) for u, v in self.edges()]
@@ -2420,7 +2445,7 @@ def degree_matrix(self, rtype="array"):
24202445
Constructed degree matrix.
24212446
24222447
"""
2423-
from compas.topology import degree_matrix
2448+
from compas.matrices import degree_matrix
24242449

24252450
node_index = self.node_index()
24262451
adjacency = [[node_index[nbr] for nbr in self.neighbors(key)] for key in self.nodes()]
@@ -2448,7 +2473,7 @@ def laplacian_matrix(self, normalize=False, rtype="array"):
24482473
vectors could be used in a more natural way ``c = xyz + d``.
24492474
24502475
"""
2451-
from compas.topology import laplacian_matrix
2476+
from compas.matrices import laplacian_matrix
24522477

24532478
node_index = self.node_index()
24542479
edges = [(node_index[u], node_index[v]) for u, v in self.edges()]

src/compas/datastructures/mesh/mesh.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from compas.geometry import Circle
2929
from compas.geometry import Frame
3030
from compas.geometry import Polyhedron
31+
from compas.geometry import Box
3132
from compas.geometry import angle_points
3233
from compas.geometry import area_polygon
3334
from compas.geometry import bestfit_plane
@@ -3927,24 +3928,22 @@ def aabb(self):
39273928
39283929
Returns
39293930
-------
3930-
list[[float, float, float]]
3931-
XYZ coordinates of 8 points defining a box.
3931+
:class:`compas.geometry.Box`
39323932
39333933
"""
39343934
xyz = self.vertices_attributes("xyz")
3935-
return bounding_box(xyz)
3935+
return Box.from_bounding_box(bounding_box(xyz))
39363936

39373937
def obb(self):
39383938
"""Calculate the oriented bounding box of the mesh.
39393939
39403940
Returns
39413941
-------
3942-
list[[float, float, float]]
3943-
XYZ coordinates of 8 points defining a box.
3942+
:class:`compas.geometry.Box`
39443943
39453944
"""
39463945
xyz = self.vertices_attributes("xyz")
3947-
return oriented_bounding_box(xyz)
3946+
return Box.from_bounding_box(oriented_bounding_box(xyz))
39483947

39493948
# --------------------------------------------------------------------------
39503949
# Vertex geometry
@@ -4842,7 +4841,7 @@ def adjacency_matrix(self, rtype="array"):
48424841
The adjacency matrix.
48434842
48444843
"""
4845-
from compas.topology import adjacency_matrix
4844+
from compas.matrices import adjacency_matrix
48464845

48474846
vertex_index = self.vertex_index()
48484847
adjacency = [[vertex_index[nbr] for nbr in self.vertex_neighbors(vertex)] for vertex in self.vertices()]
@@ -4862,7 +4861,7 @@ def connectivity_matrix(self, rtype="array"):
48624861
The connectivity matrix.
48634862
48644863
"""
4865-
from compas.topology import connectivity_matrix
4864+
from compas.matrices import connectivity_matrix
48664865

48674866
vertex_index = self.vertex_index()
48684867
adjacency = [[vertex_index[nbr] for nbr in self.vertex_neighbors(vertex)] for vertex in self.vertices()]
@@ -4882,7 +4881,7 @@ def degree_matrix(self, rtype="array"):
48824881
The degree matrix.
48834882
48844883
"""
4885-
from compas.topology import degree_matrix
4884+
from compas.matrices import degree_matrix
48864885

48874886
vertex_index = self.vertex_index()
48884887
adjacency = [[vertex_index[nbr] for nbr in self.vertex_neighbors(vertex)] for vertex in self.vertices()]
@@ -4936,7 +4935,7 @@ def face_matrix(self, rtype="array"):
49364935
True
49374936
49384937
"""
4939-
from compas.topology import face_matrix
4938+
from compas.matrices import face_matrix
49404939

49414940
vertex_index = self.vertex_index()
49424941
faces = [[vertex_index[vertex] for vertex in self.face_vertices(face)] for face in self.faces()]
@@ -4993,7 +4992,7 @@ def laplacian_matrix(self, rtype="array"):
49934992
>>> d = L.dot(xyz)
49944993
49954994
"""
4996-
from compas.topology import laplacian_matrix
4995+
from compas.matrices import laplacian_matrix
49974996

49984997
vertex_index = self.vertex_index()
49994998
adjacency = [[vertex_index[nbr] for nbr in self.vertex_neighbors(vertex)] for vertex in self.vertices()]

src/compas/datastructures/volmesh/volmesh.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from compas.geometry import Line
2020
from compas.geometry import Polygon
2121
from compas.geometry import Polyhedron
22+
from compas.geometry import Box
2223
from compas.geometry import add_vectors
2324
from compas.geometry import bestfit_plane
2425
from compas.geometry import centroid_points
@@ -33,6 +34,7 @@
3334
from compas.geometry import subtract_vectors
3435
from compas.geometry import bounding_box
3536
from compas.geometry import transform_points
37+
from compas.geometry import oriented_bounding_box
3638

3739
from compas.utilities import linspace
3840
from compas.utilities import pairwise
@@ -951,12 +953,22 @@ def aabb(self):
951953
952954
Returns
953955
-------
954-
list[[float, float, float]]
955-
XYZ coordinates of 8 points defining a box.
956+
:class:`compas.geometry.Box`
956957
957958
"""
958959
xyz = self.vertices_attributes("xyz")
959-
return bounding_box(xyz)
960+
return Box.from_bounding_box(bounding_box(xyz))
961+
962+
def obb(self):
963+
"""Calculate the oriented bounding box of the datastructure.
964+
965+
Returns
966+
-------
967+
:class:`compas.geometry.Box`
968+
969+
"""
970+
xyz = self.vertices_attributes("xyz")
971+
return Box.from_bounding_box(oriented_bounding_box(xyz))
960972

961973
# --------------------------------------------------------------------------
962974
# VolMesh Topology

0 commit comments

Comments
 (0)