From b01e93161e16b11ba3f5bfaf654e50dc0b05811c Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 8 Aug 2024 08:24:03 +1000 Subject: [PATCH] Use vertex buffer for more efficient centroids --- src/ifcopenshell-python/ifcopenshell/util/shape.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/shape.py b/src/ifcopenshell-python/ifcopenshell/util/shape.py index 4c3fd756fa..eae0394dcf 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/shape.py +++ b/src/ifcopenshell-python/ifcopenshell/util/shape.py @@ -175,7 +175,7 @@ def get_bbox_centroid(geometry: ShapeType) -> tuple[float, float, float]: :return: A tuple representing the XYZ centroid :rtype: tuple[float, float, float] """ - vertices_array = np.array(geometry.verts).reshape(-1, 3) + vertices_array = get_vertices(geometry) return (np.min(vertices_array, axis=0) + np.max(vertices_array, axis=0)) / 2 @@ -189,7 +189,7 @@ def get_vert_centroid(geometry: ShapeType) -> tuple[float, float, float]: :return: A tuple representing the XYZ centroid :rtype: tuple[float, float, float] """ - return np.mean(np.array(geometry.verts).reshape(-1, 3), axis=0) + return np.mean(get_vertices(geometry), axis=0) def get_element_bbox_centroid(element: ifcopenshell.entity_instance, geometry) -> npt.NDArray[np.float64]: