From ba5b27d03c3ff707f2829effe860bb6ded9c5b88 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 9 Sep 2024 12:41:09 +1000 Subject: [PATCH] Support getting 2D coordinates in util.shape.get_vertices --- src/ifcopenshell-python/ifcopenshell/util/shape.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/shape.py b/src/ifcopenshell-python/ifcopenshell/util/shape.py index eae0394dcf..2f5387a511 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/shape.py +++ b/src/ifcopenshell-python/ifcopenshell/util/shape.py @@ -229,7 +229,7 @@ def get_shape_bbox_centroid(shape: ShapeType, geometry: ShapeType) -> npt.NDArra return (get_shape_matrix(shape) @ np.array([*centroid, 1.0]))[0:3] -def get_vertices(geometry: ShapeType) -> npt.NDArray[np.float64]: +def get_vertices(geometry: ShapeType, is_2d: bool = False) -> npt.NDArray[np.float64]: """Get all the vertices as a numpy array Vertices are in local coordinates. @@ -238,9 +238,12 @@ def get_vertices(geometry: ShapeType) -> npt.NDArray[np.float64]: :param geometry: Geometry output calculated by IfcOpenShell :type geometry: geometry + :param is_2d: Set to True to to get XY coordinates only. :return: A numpy array listing all the vertices. Each vertex is a numpy array with XYZ coordinates. :rtype: np.array[np.array[float]] """ + if is_2d: + return np.frombuffer(geometry.verts_buffer, "d").reshape(-1, 3)[:, :2] return np.frombuffer(geometry.verts_buffer, "d").reshape(-1, 3)