Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(face): Snap hole polygons together before intersection #390

Merged
merged 2 commits into from Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions ladybug_geometry/geometry3d/face.py
Expand Up @@ -2037,10 +2037,22 @@ def coplanar_split(face1, face2, tolerance, angle_tolerance):
# get BooleanPolygons of the two faces
f1_polys = [(pb.BooleanPoint(pt.x, pt.y) for pt in f1_poly.vertices)]
f2_polys = [(pb.BooleanPoint(pt.x, pt.y) for pt in s2_poly.vertices)]
if face1.has_holes:
if face1.has_holes and face2.has_holes: # snap corresponding holes together
f1h_polys = face1.hole_polygon2d
f2h_polys = [Polygon2D(tuple(prim_pl.xyz_to_xy(pt) for pt in h_pts))
for h_pts in face2.holes]
for f1hp in f1h_polys:
for hi, f2hp in enumerate(f2h_polys):
if f1hp.center.distance_to_point(f2hp.center) < tolerance:
f2h_polys[hi] = f1hp.snap_to_polygon(f2hp, tolerance)
for hole in f1h_polys:
f1_polys.append((pb.BooleanPoint(pt.x, pt.y) for pt in hole.vertices))
for hole in f2h_polys:
f2_polys.append((pb.BooleanPoint(pt.x, pt.y) for pt in hole.vertices))
elif face1.has_holes:
for hole in face1.hole_polygon2d:
f1_polys.append((pb.BooleanPoint(pt.x, pt.y) for pt in hole.vertices))
if face2.has_holes:
elif face2.has_holes:
for hole in face2.holes:
h_pt2d = (prim_pl.xyz_to_xy(pt) for pt in hole)
f2_polys.append((pb.BooleanPoint(pt.x, pt.y) for pt in h_pt2d))
Expand Down
3 changes: 2 additions & 1 deletion ladybug_geometry/interop/obj.py
Expand Up @@ -372,7 +372,8 @@ def to_file(self, folder, name, triangulate_quads=False, include_mtl=False):

# add material file name if include_mtl is true
if self._material_structure is not None or include_mtl:
outfile.write('mtllib ' + mtl_file + '\n')
if include_mtl:
outfile.write('mtllib ' + mtl_file + '\n')
if self._material_structure is None:
outfile.write('usemtl diffuse_0\n')

Expand Down
1 change: 0 additions & 1 deletion tests/obj/two_material_cubes_edit.obj
@@ -1,6 +1,5 @@
# Rhino

mtllib two_material_cubes.mtl
v 10 0 -20
v 10 10 -20
v 10 0 -10
Expand Down