From e27980f74692999a70c4ac711df24729e5e46bfc Mon Sep 17 00:00:00 2001 From: VDobranov <112861900+VDobranov@users.noreply.github.com> Date: Fri, 19 Jul 2024 22:26:26 +0500 Subject: [PATCH] Update shape.py Following the discussion in Live Chat about length of all edges in a given geometry: https://matrix.to/#/!ssOmSJysZpXBupsgjO:matrix.org/$0ZHjIFCtpwQl06xdGWlQ9ymsiKWpPuLMczVJnNYmN84?via=matrix.org&via=crossbach.de&via=infeeeee.duckdns.org --- src/ifcopenshell-python/ifcopenshell/util/shape.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/shape.py b/src/ifcopenshell-python/ifcopenshell/util/shape.py index e41c5a5b5b..65caa09151 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/shape.py +++ b/src/ifcopenshell-python/ifcopenshell/util/shape.py @@ -730,3 +730,16 @@ def get_extrusions(element: ifcopenshell.entity_instance) -> list[ifcopenshell.e else: break return extrusions + + +def get_total_edge_length(geometry: ShapeType) -> float: + """Calculates the total length of edges in a given geometry. + + :param geometry: Geometry output calculated by IfcOpenShell + :type geometry: geometry + :return: The total length of all edges in the geometry. + :rtype: float + """ + vertices = get_vertices(geometry) + edges = get_edges(geometry) + return sum([np.linalg.norm(vertices[e[0]] - vertices[e[1]]) for e in edges])