11use nfp:: prelude:: * ;
2- use std:: time:: Instant ;
32
43/// Number of iterations to run the NFP calculation
54const ITERATIONS : usize = 1000 ;
65
76fn main ( ) {
87
98 // Generate two different 100-edge polygons with fixed seeds
10- let poly_a = generate_100_edge_polygon ( 42 ) ;
11- let poly_b = generate_100_edge_polygon ( 43 ) ;
9+ let poly_a = generate_convex_100_edge_polygon ( 42 ) ;
10+ let poly_b = generate_convex_100_edge_polygon ( 43 ) ;
1211
1312 for _ in 0 ..ITERATIONS {
14- let _ = NFP :: nfp ( & poly_a, & poly_b) ;
13+ let _ = NFPConvex :: nfp ( & poly_a, & poly_b) ;
1514 }
1615}
1716
1817/// Generate a 100-edge polygon using a fixed seed via bit manipulation
19- fn generate_100_edge_polygon ( seed : u64 ) -> Vec < Point > {
18+ fn generate_convex_100_edge_polygon ( seed : u64 ) -> Vec < Point > {
2019 use std:: f64:: consts:: PI ;
20+ use togo:: algo:: pointline_convex_hull;
2121
2222 let mut points = Vec :: new ( ) ;
2323 let mut rng_state = seed;
@@ -35,15 +35,16 @@ fn generate_100_edge_polygon(seed: u64) -> Vec<Point> {
3535 points. push ( point ( radius * angle. cos ( ) , radius * angle. sin ( ) ) ) ;
3636 }
3737
38- // Sort by angle from centroid to ensure CCW ordering
38+ // Sort by angle from centroid to ensure CCW ordering (required by convex_hull)
3939 let centroid = compute_centroid ( & points) ;
4040 points. sort_by ( |a, b| {
4141 let angle_a = ( a. y - centroid. y ) . atan2 ( a. x - centroid. x ) ;
4242 let angle_b = ( b. y - centroid. y ) . atan2 ( b. x - centroid. x ) ;
4343 angle_a. partial_cmp ( & angle_b) . unwrap_or ( std:: cmp:: Ordering :: Equal )
4444 } ) ;
4545
46- points
46+ // Apply convex hull to ensure convex polygon (expects CCW input)
47+ pointline_convex_hull ( & points)
4748}
4849
4950fn compute_centroid ( points : & [ Point ] ) -> Point {
0 commit comments