From 54951d210250163fd69860e101956c2eb3c088c3 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 28 May 2024 17:29:52 +1000 Subject: [PATCH] Add convenience max/min functions for xyz and side_area shape calculations --- .../ifcopenshell/util/shape.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/shape.py b/src/ifcopenshell-python/ifcopenshell/util/shape.py index 1915c6cde0..8780d63920 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/shape.py +++ b/src/ifcopenshell-python/ifcopenshell/util/shape.py @@ -117,6 +117,28 @@ def get_z(geometry) -> float: return max(z_values) - min(z_values) +def get_max_xyz(geometry) -> float: + """Gets the maximum X, Y, or Z length of the geometry + + :param geometry: Geometry output calculated by IfcOpenShell + :type geometry: geometry + :return: The maximum possible value out of the X, Y, and Z dimension + :rtype: float + """ + return max(get_x(geometry), get_y(geometry), get_z(geometry)) + + +def get_min_xyz(geometry) -> float: + """Gets the minimum X, Y, or Z length of the geometry + + :param geometry: Geometry output calculated by IfcOpenShell + :type geometry: geometry + :return: The minimum possible value out of the X, Y, and Z dimension + :rtype: float + """ + return min(get_x(geometry), get_y(geometry), get_z(geometry)) + + def get_shape_matrix(shape) -> MatrixType: """Formats the transformation matrix of a shape as a 4x4 numpy array @@ -486,6 +508,19 @@ def get_side_area( return get_area_vf(vertices, filtered_faces) +def get_max_side_area(geometry) -> float: + """Returns the maximum X, Y, or Z side area + + See :func:`get_side_area` for how side area is calculated. + + :param geometry: Geometry output calculated by IfcOpenShell + :type geometry: geometry + :return: The maximum surface area from either the X, Y, or Z axis. + :rtype: float + """ + return max(get_side_area(geometry, axis="X"), get_side_area(geometry, axis="Y"), get_side_area(geometry, axis="Z")) + + def get_footprint_area( geometry, axis: AXIS_LITERAL = "Z",