@@ -6,7 +6,7 @@ use tracing::instrument;
6
6
7
7
use crate :: spade:: { ConstrainedDelaunayTriangulation , Point2 , Triangulation as SpadeTriangulation } ;
8
8
pub use geo:: LineString ;
9
- use geo:: { Contains , Coord , Polygon as GeoPolygon , SimplifyVwPreserve } ;
9
+ use geo:: { self , Contains , Coord , SimplifyVwPreserve } ;
10
10
use glam:: { vec2, Vec2 } ;
11
11
12
12
use crate :: { Layer , Mesh , Polygon , Vertex } ;
@@ -21,9 +21,9 @@ enum AgentRadius {
21
21
/// An helper to create a [`Mesh`] from a list of edges and obstacle, using a constrained Delaunay triangulation.
22
22
#[ derive( Clone ) ]
23
23
pub struct Triangulation {
24
- inner : GeoPolygon < f32 > ,
24
+ inner : geo :: Polygon < f32 > ,
25
25
prebuilt : Option < (
26
- GeoPolygon < f32 > ,
26
+ geo :: Polygon < f32 > ,
27
27
ConstrainedDelaunayTriangulation < Point2 < f64 > > ,
28
28
) > ,
29
29
base_layer : Option < Layer > ,
@@ -40,10 +40,23 @@ impl std::fmt::Debug for Triangulation {
40
40
}
41
41
42
42
impl Triangulation {
43
+ /// Create a new triangulation from a [`geo::Polygon`].
44
+ ///
45
+ /// The exterior of the polygon will be used as the outer edge of the triangulation,
46
+ /// and inner polygons will be used as obstacles.
47
+ pub fn from_geo_polygon ( polygon : geo:: Polygon < f32 > ) -> Triangulation {
48
+ Self {
49
+ inner : polygon,
50
+ prebuilt : None ,
51
+ base_layer : None ,
52
+ agent_radius : AgentRadius :: None ,
53
+ }
54
+ }
55
+
43
56
/// Create a new triangulation from a the list of points on its outer edges.
44
57
pub fn from_outer_edges ( edges : & [ Vec2 ] ) -> Triangulation {
45
58
Self {
46
- inner : GeoPolygon :: new (
59
+ inner : geo :: Polygon :: new (
47
60
LineString :: from ( edges. iter ( ) . map ( |v| ( v. x , v. y ) ) . collect :: < Vec < _ > > ( ) ) ,
48
61
vec ! [ ] ,
49
62
) ,
@@ -56,7 +69,7 @@ impl Triangulation {
56
69
/// Create a new triangulation from an existing `Mesh`, cloning the specified [`Layer`].
57
70
pub fn from_mesh ( mesh : & Mesh , layer : u8 ) -> Triangulation {
58
71
Self {
59
- inner : GeoPolygon :: new ( LineString :: new ( Vec :: new ( ) ) , vec ! [ ] ) ,
72
+ inner : geo :: Polygon :: new ( LineString :: new ( Vec :: new ( ) ) , vec ! [ ] ) ,
60
73
prebuilt : None ,
61
74
base_layer : Some ( mesh. layers [ layer as usize ] . clone ( ) ) ,
62
75
agent_radius : AgentRadius :: None ,
@@ -66,7 +79,7 @@ impl Triangulation {
66
79
/// Create a new triangulation from an existing `Layer` of a [`Mesh`].
67
80
pub fn from_mesh_layer ( layer : Layer ) -> Triangulation {
68
81
Self {
69
- inner : GeoPolygon :: new ( LineString :: new ( Vec :: new ( ) ) , vec ! [ ] ) ,
82
+ inner : geo :: Polygon :: new ( LineString :: new ( Vec :: new ( ) ) , vec ! [ ] ) ,
70
83
prebuilt : None ,
71
84
base_layer : Some ( layer) ,
72
85
agent_radius : AgentRadius :: None ,
@@ -142,10 +155,12 @@ impl Triangulation {
142
155
& mut self ,
143
156
obstacles : impl IntoIterator < Item = impl IntoIterator < Item = Vec2 > > ,
144
157
) {
145
- let ( exterior, interiors) =
146
- std:: mem:: replace ( & mut self . inner , GeoPolygon :: new ( LineString ( vec ! [ ] ) , vec ! [ ] ) )
147
- . into_inner ( ) ;
148
- self . inner = GeoPolygon :: new (
158
+ let ( exterior, interiors) = std:: mem:: replace (
159
+ & mut self . inner ,
160
+ geo:: Polygon :: new ( LineString ( vec ! [ ] ) , vec ! [ ] ) ,
161
+ )
162
+ . into_inner ( ) ;
163
+ self . inner = geo:: Polygon :: new (
149
164
exterior,
150
165
interiors
151
166
. into_iter ( )
@@ -207,7 +222,7 @@ impl Triangulation {
207
222
}
208
223
209
224
let exterior = self . inner . exterior ( ) . clone ( ) ;
210
- let mut inner = std:: mem:: replace ( & mut self . inner , GeoPolygon :: new ( exterior, vec ! [ ] ) ) ;
225
+ let mut inner = std:: mem:: replace ( & mut self . inner , geo :: Polygon :: new ( exterior, vec ! [ ] ) ) ;
211
226
match self . agent_radius {
212
227
AgentRadius :: Obstacles ( radius, segments, simplification) if radius > 1.0e-5 => {
213
228
inner = inner. inflate_obstacles ( radius, segments as u32 , simplification) ;
@@ -349,7 +364,7 @@ impl Triangulation {
349
364
} )
350
365
. unwrap_or ( true )
351
366
&& !inner. interiors ( ) . iter ( ) . any ( |obstacle| {
352
- GeoPolygon :: new ( obstacle. clone ( ) , vec ! [ ] ) . contains ( & center)
367
+ geo :: Polygon :: new ( obstacle. clone ( ) , vec ! [ ] ) . contains ( & center)
353
368
} ) ) )
354
369
. then ( || {
355
370
#[ cfg( feature = "tracing" ) ]
0 commit comments