@@ -1029,7 +1029,8 @@ def polygons_full(self):
10291029 children = [closed [child ]
10301030 for child in enclosure [root ].keys ()]
10311031 # all polygons_closed are CCW, so for interiors reverse them
1032- holes = [np .array (p .exterior .coords )[::- 1 ] for p in children ]
1032+ holes = [np .array (p .exterior .coords )[::- 1 ]
1033+ for p in children ]
10331034 # a single Polygon object
10341035 shell = closed [root ].exterior
10351036 # create a polygon with interiors
@@ -1095,6 +1096,36 @@ def extrude(self, height, **kwargs):
10951096 return result [0 ]
10961097 return result
10971098
1099+ def triangulate (self , ** kwargs ):
1100+ """
1101+ Create a region- aware triangulation of the 2D path.
1102+
1103+ Parameters
1104+ -------------
1105+ **kwargs : dict
1106+ Passed to trimesh.creation.triangulate_polygon
1107+
1108+ Returns
1109+ -------------
1110+ vertices : (n, 2) float
1111+ 2D vertices of triangulation
1112+ faces : (n, 3) int
1113+ Indexes of vertices for triangles
1114+ """
1115+ from ..creation import triangulate_polygon
1116+
1117+ # append vertices and faces into sequence
1118+ v_seq = []
1119+ f_seq = []
1120+
1121+ # loop through polygons with interiors
1122+ for polygon in self .polygons_full :
1123+ v , f = triangulate_polygon (polygon , ** kwargs )
1124+ v_seq .append (v )
1125+ f_seq .append (f )
1126+
1127+ return util .append_faces (v_seq , f_seq )
1128+
10981129 def medial_axis (self , resolution = None , clip = None ):
10991130 """
11001131 Find the approximate medial axis based
@@ -1103,16 +1134,15 @@ def medial_axis(self, resolution=None, clip=None):
11031134
11041135 Parameters
11051136 ----------
1106- resolution: target distance between each sample on the polygon boundary
1107- clip: [minimum number of samples, maximum number of samples]
1108- specifying a very fine resolution can cause the sample count to
1109- explode, so clip specifies a minimum and maximum number of samples
1110- to use per boundary region. To not clip, this can be specified as:
1111- [0, np.inf]
1137+ resolution : None or float
1138+ Distance between each sample on the polygon boundary
1139+ clip : None, or (2,) float
1140+ Min, max number of samples
11121141
11131142 Returns
11141143 ----------
11151144 medial : Path2D object
1145+ Contains only medial axis of Path
11161146 """
11171147 if resolution is None :
11181148 resolution = self .scale / 1000.0
@@ -1124,23 +1154,27 @@ def medial_axis(self, resolution=None, clip=None):
11241154
11251155 def connected_paths (self , path_id , include_self = False ):
11261156 """
1127- Given an index of self.paths, find other paths which overlap with
1128- that path.
1157+ Given an index of self.paths find other paths which
1158+ overlap with that path.
11291159
11301160 Parameters
11311161 -----------
1132- path_id: int, index of self.paths
1133- include_self: bool, should the result include path_id or not
1162+ path_id : int
1163+ Index of self.paths
1164+ include_self : bool
1165+ Should the result include path_id or not
11341166
11351167 Returns
11361168 -----------
1137- path_ids: (n,) int, indexes of self.paths that overlap input path_id
1169+ path_ids : (n, ) int
1170+ Indexes of self.paths that overlap input path_id
11381171 """
11391172 if len (self .root ) == 1 :
11401173 path_ids = np .arange (len (self .polygons_closed ))
11411174 else :
1142- path_ids = list (nx .node_connected_component (self .enclosure ,
1143- path_id ))
1175+ path_ids = list (nx .node_connected_component (
1176+ self .enclosure ,
1177+ path_id ))
11441178 if include_self :
11451179 return np .array (path_ids )
11461180 return np .setdiff1d (path_ids , [path_id ])
@@ -1152,7 +1186,7 @@ def simplify(self, **kwargs):
11521186
11531187 Returns
11541188 ---------
1155- simplified: Path2D object
1189+ simplified : Path2D object
11561190 """
11571191 return simplify .simplify_basic (self , ** kwargs )
11581192
@@ -1162,8 +1196,10 @@ def simplify_spline(self, path_indexes=None, smooth=.0002):
11621196
11631197 Parameters
11641198 -----------
1165- path_indexes: (n) int list of indexes for self.paths
1166- smooth: float, how much the spline should smooth the curve
1199+ path_indexes : (n) int
1200+ List of indexes of self.paths to convert
1201+ smooth : float
1202+ How much the spline should smooth the curve
11671203
11681204 Returns
11691205 ------------
@@ -1180,7 +1216,8 @@ def split(self):
11801216
11811217 Returns
11821218 ----------
1183- split: (n,) list of Path2D objects
1219+ split: (n,) list of Path2D objects
1220+ Each connected region and interiors
11841221 """
11851222 return traversal .split (self )
11861223
0 commit comments