From 485e60edb6629326d273977f4c14ccc492d848eb Mon Sep 17 00:00:00 2001 From: Chris Mackey Date: Tue, 27 Aug 2024 11:02:47 -0700 Subject: [PATCH] fix(face): Add method to determine if Face3D overlaps with another --- ladybug_geometry/geometry3d/face.py | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/ladybug_geometry/geometry3d/face.py b/ladybug_geometry/geometry3d/face.py index 3e4a2ffb..2926f24f 100644 --- a/ladybug_geometry/geometry3d/face.py +++ b/ladybug_geometry/geometry3d/face.py @@ -707,6 +707,26 @@ def is_horizontal(self, tolerance): """ return self.max.z - self.min.z <= tolerance + def is_coplanar(self, face, tolerance): + """Check whether a this face is coplanar with another given tolerance. + + This method will only evaluate the distance between the other face's + vertices and this face's plane so it does not rely on a check based + on angle tolerance. + + Args: + face: A neighboring Face3D for which co-planarity will be checked. + tolerance: The minimum difference between the coordinate values of two + vertices at which they can be considered equivalent. + + Returns: + True if the face is coplanar with this one. False if it is not. + """ + for pt in face.vertices: + if self.plane.distance_to_point(pt) > tolerance: + return False + return True + def is_geometrically_equivalent(self, face, tolerance): """Check whether a given face is geometrically equivalent to this Face. @@ -786,6 +806,29 @@ def is_centered_adjacent(self, face, tolerance): return True return False + def is_overlapping(self, face, tolerance): + """Check whether a this face overlaps with another given tolerance. + + Overlapping faces must not only be coplanar but they also have overlapping + polygons when evaluated within the same plane. Note that, if the face + is a sub-face of this one, this method will return True. + + Args: + face: A neighboring Face3D for which overlaps will be checked. + tolerance: The minimum difference between the coordinate values of two + vertices at which they can be considered equivalent. + + Returns: + True if the face is overlapping with this one. False if it is not. + """ + if not self.is_coplanar(face, tolerance): + return False + verts2d = tuple(self.plane.xyz_to_xy(_v) for _v in face.vertices) + other_poly = Polygon2D(verts2d) + if self.polygon2d.polygon_relationship(other_poly, tolerance) == -1: + return False + return True + def is_sub_face(self, face, tolerance, angle_tolerance): """Check whether a given face is a sub-face of this face.