Skip to content

Commit ad78cd0

Browse files
committed
updating types
1 parent f6490b1 commit ad78cd0

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/compas_cgal/straight_skeleton_2.py

+28-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import Tuple
2+
from typing import Union
3+
14
import numpy as np
25
from compas.datastructures import Graph
36
from compas.geometry import Polygon
@@ -6,19 +9,23 @@
69

710
from compas_cgal._cgal import straight_skeleton_2
811

12+
from .types import IntNx1
13+
from .types import IntNx2
14+
from .types import VerticesNumpy
15+
916

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:
1118
"""Create a graph from the skeleton data.
1219
1320
Parameters
1421
----------
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`
1825
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`
2229
The type per edge, `0` for inner bisector, `1` for bisector, and `2` for boundary.
2330
2431
Returns
@@ -41,13 +48,15 @@ def graph_from_skeleton_data(points, indices, edges, edge_types) -> Graph:
4148
return graph
4249

4350

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]]:
4552
"""Compute the skeleton of a polygon.
4653
4754
Parameters
4855
----------
4956
points : list of point coordinates or :class:`compas.geometry.Polygon`
5057
The points of the polygon.
58+
as_graph : bool, optional
59+
Whether the skeleton should be returned as a graph, defaults to `True`.
5160
5261
Returns
5362
-------
@@ -64,10 +73,13 @@ def create_interior_straight_skeleton(points) -> Graph:
6473
if not TOL.is_allclose(normal, [0, 0, 1]):
6574
raise ValueError("The normal of the polygon should be [0, 0, 1]. The normal of the provided polygon is {}".format(normal))
6675
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
6880

6981

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]]:
7183
"""Compute the skeleton of a polygon with holes.
7284
7385
Parameters
@@ -76,6 +88,8 @@ def create_interior_straight_skeleton_with_holes(points, holes) -> Graph:
7688
The points of the polygon.
7789
holes : list of list of point coordinates or list of :class:`compas.geometry.Polygon`
7890
The holes of the polygon.
91+
as_graph : bool, optional
92+
Whether the skeleton should be returned as a graph, defaults to `True`.
7993
8094
Returns
8195
-------
@@ -102,7 +116,10 @@ def create_interior_straight_skeleton_with_holes(points, holes) -> Graph:
102116
raise ValueError("The normal of the hole should be [0, 0, -1]. The normal of the provided {}-th hole is {}".format(i, normal_hole))
103117
hole = np.asarray(points, dtype=np.float64)
104118
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
106123

107124

108125
def create_offset_polygons_2(points, offset) -> list[Polygon]:

src/compas_cgal/types.py

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
FloatNx3 = Annotated[NDArray[float64], Literal["N", 3]]
1414
IntNx3 = Annotated[NDArray[int64], Literal["N", 3]]
15+
IntNx2 = Annotated[NDArray[int64], Literal["N", 2]]
16+
IntNx1 = Annotated[NDArray[int64], Literal["N", 1]]
1517

1618
VerticesNumpy = FloatNx3
1719
"""An array of vertices, with each vertex defined by 3 spatial coordinates."""

0 commit comments

Comments
 (0)