Skip to content

Commit 0423ec6

Browse files
committed
change boundary options to texts to improve semantic
1 parent 7a40dd9 commit 0423ec6

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/compas/datastructures/mesh/duality.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
PI2 = 2.0 * pi
1212

1313

14-
def mesh_dual(mesh, cls=None, boundary=0):
14+
def mesh_dual(mesh, cls=None, include_boundary=False, preserve_boundary_vertices=False, preserve_corner_vertices=False):
1515
"""Construct the dual of a mesh.
1616
1717
Parameters
@@ -21,12 +21,15 @@ def mesh_dual(mesh, cls=None, boundary=0):
2121
cls : Type[:class:`~compas.datastructures.Mesh`], optional
2222
The type of the dual mesh.
2323
Defaults to the type of the provided mesh object.
24-
boundary: float, optional
25-
boundary mode for the dual mesh
26-
Default mode is 0, not create faces on boundaries.
27-
1, create faces on mesh edges, not include original mesh boundary vertices.
28-
2. create faces on mesh edges and include original mesh boundary vertices on the corner.
29-
3. create faces on mesh edges and include all original mesh boundary vertices.
24+
include_boundary: str, optional
25+
Whether to include boundary faces for the dual mesh
26+
Default mode is False, don't create faces on boundaries.
27+
preserve_boundary_vertices: str, optional
28+
Whether to preserve boundary vertices from the original mesh
29+
Default mode is False, include the boundary without the original vertices.
30+
preserve_corner_vertices: str, optional
31+
Whether to preserve corner vertices (only connect to one face) from the original mesh
32+
Default mode is False, include the boundary with the original vertices only on corners.
3033
3134
Returns
3235
-------
@@ -43,7 +46,7 @@ def mesh_dual(mesh, cls=None, boundary=0):
4346
>>> mesh.delete_face(7)
4447
>>> mesh.quads_to_triangles()
4548
>>> mesh = mesh.subdivide('corner')
46-
>>> dual = mesh.dual(boundary=3)
49+
>>> dual = mesh.dual(include_boundary=True, preserve_boundary_vertices=True, preserve_corner_vertices=False)
4750
4851
"""
4952
if not cls:
@@ -68,12 +71,9 @@ def mesh_dual(mesh, cls=None, boundary=0):
6871
vertex_xyz[face] = face_centroid[face]
6972
face_vertices[vertex] = faces
7073

71-
if not boundary:
74+
if not include_boundary:
7275
continue
7376

74-
if boundary > 3:
75-
raise ValueError("edge mode from 0 to 3!")
76-
7777
if vertex not in outer or len(faces) < 1:
7878
continue
7979

@@ -88,13 +88,13 @@ def mesh_dual(mesh, cls=None, boundary=0):
8888
continue
8989
pt = mesh.edge_midpoint(vertex, nbr_vertex)
9090

91-
if num_faces not in vertex_xyz and len(faces) == 1 and corner_count == 0 and (boundary == 2 or boundary == 3):
91+
if num_faces not in vertex_xyz and len(faces) == 1 and corner_count == 0 and (preserve_corner_vertices or preserve_boundary_vertices):
9292
vertex_xyz[num_faces] = mesh.vertex_coordinates(vertex)
9393
current_face = num_faces
9494
num_faces += 1
9595
corner_count += 1
9696

97-
if num_faces not in vertex_xyz and len(faces) != 1 and edge_count == 0 and boundary == 3:
97+
if num_faces not in vertex_xyz and len(faces) != 1 and edge_count == 0 and preserve_boundary_vertices:
9898
vertex_xyz[num_faces] = mesh.vertex_coordinates(vertex)
9999
current_face = num_faces
100100
num_faces += 1
@@ -110,10 +110,10 @@ def mesh_dual(mesh, cls=None, boundary=0):
110110
else:
111111
boundary_fids.append(edge_vertex[vertex, nbr_vertex])
112112

113-
if vertex in outer and len(faces) == 1 and (boundary == 2 or boundary == 3):
113+
if vertex in outer and len(faces) == 1 and (preserve_corner_vertices or preserve_boundary_vertices):
114114
boundary_fids.insert(len(faces) + 1, current_face)
115115

116-
if vertex in outer and len(faces) != 1 and boundary == 3:
116+
if vertex in outer and len(faces) != 1 and preserve_boundary_vertices:
117117
boundary_fids.insert(len(faces) + 1, current_face)
118118

119119
face_vertices[vertex] = boundary_fids

0 commit comments

Comments
 (0)