1
+ from typing import Tuple
2
+ from typing import Union
3
+
1
4
import numpy as np
2
5
from compas .datastructures import Graph
3
6
from compas .geometry import Polygon
6
9
7
10
from compas_cgal ._cgal import straight_skeleton_2
8
11
12
+ from .types import IntNx1
13
+ from .types import IntNx2
14
+ from .types import VerticesNumpy
15
+
9
16
10
- def graph_from_skeleton_data (points , indices , edges , edge_types ) -> Graph :
17
+ def graph_from_skeleton_data (points : VerticesNumpy , indices : IntNx1 , edges : IntNx2 , edge_types : IntNx1 ) -> Graph :
11
18
"""Create a graph from the skeleton data.
12
19
13
20
Parameters
14
21
----------
15
- points : list of point coordinates
16
- The vertices of the skeleton.
17
- indices : list of int
22
+ points : :class:`numpy.ndarray`
23
+ The vertices of the skeleton, each vertex defined by 3 spatial coordinates .
24
+ indices : :class:`numpy.ndarray`
18
25
The vertex indices of the skeleton, corresponding to the points.
19
- edges : list of tuple of int
20
- The edges of the skeleton.
21
- edge_types : list of int
26
+ edges : :class:`numpy.ndarray`
27
+ The edges of the skeleton, each edge defined by 2 vertex indices .
28
+ edge_types : :class:`numpy.ndarray`
22
29
The type per edge, `0` for inner bisector, `1` for bisector, and `2` for boundary.
23
30
24
31
Returns
@@ -41,13 +48,15 @@ def graph_from_skeleton_data(points, indices, edges, edge_types) -> Graph:
41
48
return graph
42
49
43
50
44
- def create_interior_straight_skeleton (points ) -> Graph :
51
+ def create_interior_straight_skeleton (points , as_graph = True ) -> Union [ Graph , Tuple [ VerticesNumpy , IntNx1 , IntNx2 , IntNx1 ]] :
45
52
"""Compute the skeleton of a polygon.
46
53
47
54
Parameters
48
55
----------
49
56
points : list of point coordinates or :class:`compas.geometry.Polygon`
50
57
The points of the polygon.
58
+ as_graph : bool, optional
59
+ Whether the skeleton should be returned as a graph, defaults to `True`.
51
60
52
61
Returns
53
62
-------
@@ -64,10 +73,13 @@ def create_interior_straight_skeleton(points) -> Graph:
64
73
if not TOL .is_allclose (normal , [0 , 0 , 1 ]):
65
74
raise ValueError ("The normal of the polygon should be [0, 0, 1]. The normal of the provided polygon is {}" .format (normal ))
66
75
V = np .asarray (points , dtype = np .float64 )
67
- return graph_from_skeleton_data (* straight_skeleton_2 .create_interior_straight_skeleton (V ))
76
+ points , indices , edges , edge_types = straight_skeleton_2 .create_interior_straight_skeleton (V )
77
+ if as_graph :
78
+ return graph_from_skeleton_data (points , indices , edges , edge_types )
79
+ return points , indices , edges , edge_types
68
80
69
81
70
- def create_interior_straight_skeleton_with_holes (points , holes ) -> Graph :
82
+ def create_interior_straight_skeleton_with_holes (points , holes , as_graph = True ) -> Union [ Graph , Tuple [ VerticesNumpy , IntNx1 , IntNx2 , IntNx1 ]] :
71
83
"""Compute the skeleton of a polygon with holes.
72
84
73
85
Parameters
@@ -76,6 +88,8 @@ def create_interior_straight_skeleton_with_holes(points, holes) -> Graph:
76
88
The points of the polygon.
77
89
holes : list of list of point coordinates or list of :class:`compas.geometry.Polygon`
78
90
The holes of the polygon.
91
+ as_graph : bool, optional
92
+ Whether the skeleton should be returned as a graph, defaults to `True`.
79
93
80
94
Returns
81
95
-------
@@ -102,7 +116,10 @@ def create_interior_straight_skeleton_with_holes(points, holes) -> Graph:
102
116
raise ValueError ("The normal of the hole should be [0, 0, -1]. The normal of the provided {}-th hole is {}" .format (i , normal_hole ))
103
117
hole = np .asarray (points , dtype = np .float64 )
104
118
H .append (hole )
105
- return graph_from_skeleton_data (* straight_skeleton_2 .create_interior_straight_skeleton_with_holes (V , H ))
119
+ points , indices , edges , edge_types = straight_skeleton_2 .create_interior_straight_skeleton_with_holes (V , H )
120
+ if as_graph :
121
+ return graph_from_skeleton_data (points , indices , edges , edge_types )
122
+ return points , indices , edges , edge_types
106
123
107
124
108
125
def create_offset_polygons_2 (points , offset ) -> list [Polygon ]:
0 commit comments