1
1
use geo:: { Coord , GeoFloat , LineString , Polygon } ;
2
2
use hashbrown:: HashSet ;
3
3
use spade:: handles:: { DirectedEdgeHandle , VertexHandle } ;
4
- use spade:: { DelaunayTriangulation , Point2 , SpadeNum , Triangulation } ;
4
+ use spade:: { CdtEdge , ConstrainedDelaunayTriangulation , Point2 , SpadeNum , Triangulation } ;
5
5
use std:: cmp:: Ordering ;
6
6
use std:: collections:: BinaryHeap ;
7
7
use std:: hash:: Hash ;
12
12
T : SpadeNum ,
13
13
{
14
14
score : T ,
15
- edge : DirectedEdgeHandle < ' a , Point2 < T > , ( ) , ( ) , ( ) > ,
15
+ edge : DirectedEdgeHandle < ' a , Point2 < T > , ( ) , CdtEdge < ( ) > , ( ) > ,
16
16
}
17
17
18
18
// These impls give us a max-heap
@@ -37,7 +37,7 @@ impl<T: SpadeNum> PartialEq for CharScore<'_, T> {
37
37
}
38
38
39
39
#[ derive( Debug ) ]
40
- struct BoundaryNode < ' a , T > ( VertexHandle < ' a , Point2 < T > > ) ;
40
+ struct BoundaryNode < ' a , T > ( VertexHandle < ' a , Point2 < T > , ( ) , CdtEdge < ( ) > > ) ;
41
41
42
42
impl < T > PartialEq for BoundaryNode < ' _ , T > {
43
43
fn eq ( & self , other : & BoundaryNode < T > ) -> bool {
@@ -72,13 +72,29 @@ fn characteristic_shape<T>(orig: &Polygon<T>, eps: T, max_len: usize) -> Polygon
72
72
where
73
73
T : GeoFloat + SpadeNum ,
74
74
{
75
+ // Number of unique vertices
76
+ let orig_len = orig. exterior ( ) . 0 . len ( ) - 1 ;
77
+
75
78
// Construct Delaunay triangulation
76
79
let vertices = orig
77
80
. exterior ( )
78
81
. coords ( )
82
+ . take ( orig_len) // duplicate points are removed
79
83
. map ( |c| Point2 :: new ( c. x , c. y ) )
80
84
. collect :: < Vec < _ > > ( ) ;
81
- let tri = DelaunayTriangulation :: < Point2 < T > > :: bulk_load_stable ( vertices) . unwrap ( ) ;
85
+
86
+ let edges = ( 0 ..orig_len - 1 )
87
+ . map ( |i| {
88
+ if i == 0 {
89
+ [ vertices. len ( ) - 1 , i]
90
+ } else {
91
+ [ i, i + 1 ]
92
+ }
93
+ } )
94
+ . collect :: < Vec < _ > > ( ) ;
95
+
96
+ let tri =
97
+ ConstrainedDelaunayTriangulation :: < Point2 < T > > :: bulk_load_cdt ( vertices, edges) . unwrap ( ) ;
82
98
83
99
let boundary_edges = tri. convex_hull ( ) . map ( |edge| edge. rev ( ) ) . collect :: < Vec < _ > > ( ) ;
84
100
let mut boundary_nodes: HashSet < _ > =
@@ -125,7 +141,7 @@ where
125
141
}
126
142
127
143
fn recompute_boundary < ' a , T > (
128
- edge : DirectedEdgeHandle < ' a , Point2 < T > , ( ) , ( ) , ( ) > ,
144
+ edge : DirectedEdgeHandle < ' a , Point2 < T > , ( ) , CdtEdge < ( ) > , ( ) > ,
129
145
pq : & mut BinaryHeap < CharScore < ' a , T > > ,
130
146
) where
131
147
T : GeoFloat + SpadeNum ,
0 commit comments