1- use glam:: DVec2 ;
21use slotmap:: { new_key_type, SlotMap } ;
32
43new_key_type ! {
@@ -19,12 +18,12 @@ use crate::intersection_path_segment::{path_segment_intersection, segments_equal
1918use crate :: path:: Path ;
2019use crate :: path_cubic_segment_self_intersection:: path_cubic_segment_self_intersection;
2120use crate :: path_segment:: { get_end_point, get_start_point, path_segment_bounding_box, reverse_path_segment, sample_path_segment_at, split_segment_at, PathSegment } ;
21+ #[ cfg( feature = "logging" ) ]
2222use crate :: path_to_path_data;
2323use crate :: quad_tree:: QuadTree ;
2424use crate :: vector:: { vectors_equal, Vector } ;
2525use std:: cmp:: Ordering ;
2626use std:: collections:: { HashMap , HashSet , VecDeque } ;
27- use std:: f64:: consts:: TAU ;
2827
2928#[ derive( Debug , Clone , Copy ) ]
3029pub enum PathBooleanOperation {
@@ -65,6 +64,7 @@ pub struct MajorGraphEdge {
6564
6665#[ derive( Debug , Clone , Default ) ]
6766pub struct MajorGraphVertex {
67+ #[ cfg_attr( not( feature = "logging" ) , expect( dead_code) ) ]
6868 pub point : Vector ,
6969 outgoing_edges : Vec < MajorEdgeKey > ,
7070}
@@ -85,25 +85,6 @@ struct MinorGraphEdge {
8585}
8686
8787impl MinorGraphEdge {
88- #[ cfg( feature = "logging" ) ]
89- fn format_path ( & self ) -> String {
90- use std:: fmt:: Write ;
91- let mut output = String :: new ( ) ;
92- let segments = self . segments . clone ( ) ;
93- for segment in segments. into_iter ( ) {
94- let _ = match segment {
95- PathSegment :: Line ( mut start, mut end) | PathSegment :: Cubic ( mut start, _, _, mut end) => {
96- if self . direction_flag . backwards ( ) {
97- ( end, start) = ( start, end) ;
98- }
99- write ! ( & mut output, "{:.1},{:.1}-{:.1},{:.1} " , start. x, start. y, end. x, end. y)
100- }
101- x => write ! ( & mut output, "{:?}" , x) ,
102- } ;
103- }
104- output
105- }
106-
10788 fn start_segment ( & self ) -> PathSegment {
10889 let segment = self . segments [ 0 ] ;
10990 match self . direction_flag {
@@ -199,7 +180,7 @@ fn major_graph_to_dot(graph: &MajorGraph) -> String {
199180 for ( vertex_key, vertex) in & graph. vertices {
200181 dot. push_str ( & format ! ( " {:?} [label=\" {:.1},{:.1}\" ]\n " , ( vertex_key. 0 . as_ffi( ) & 0xFF ) , vertex. point. x, vertex. point. y) ) ;
201182 }
202- for ( edge_key , edge) in & graph. edges {
183+ for ( _ , edge) in & graph. edges {
203184 dot. push_str ( & format ! (
204185 " {:?} -> {:?}: {:0b}\n " ,
205186 ( edge. incident_vertices[ 0 ] . 0 . as_ffi( ) & 0xFF ) ,
@@ -393,9 +374,6 @@ impl Direction {
393374 pub fn forward ( self ) -> bool {
394375 self == Self :: Forward
395376 }
396- pub fn backwards ( self ) -> bool {
397- self == Self :: Backwards
398- }
399377}
400378
401379// TODO:(@TrueDoctor) Optimize this by rounding each vertex up and down and then inserting them in a hashmap. This should remove the need for bbox calculations and the quad tree
@@ -667,7 +645,7 @@ fn get_incidence_angle(edge: &MinorGraphEdge) -> f64 {
667645}
668646
669647fn sort_outgoing_edges_by_angle ( graph : & mut MinorGraph ) {
670- for vertex in graph. vertices . values_mut ( ) {
648+ for ( vertex_key , vertex) in graph. vertices . iter_mut ( ) {
671649 if vertex. outgoing_edges . len ( ) > 2 {
672650 vertex. outgoing_edges . sort_by ( |& a, & b| {
673651 // TODO(@TrueDoctor): Make more robust. The js version seems to sort the data slightly differently when the angles are reallly close. In that case put the edge wich was discovered later first.
@@ -680,14 +658,14 @@ fn sort_outgoing_edges_by_angle(graph: &mut MinorGraph) {
680658 }
681659 new
682660 } ) ;
683- let edges : Vec < _ > = vertex
684- . outgoing_edges
685- . iter ( )
686- . map ( |key| ( * key , & graph. edges [ * key ] ) )
687- . map ( | ( key , edge ) | ( ( key . 0 . as_ffi ( ) & 0xFF ) , ( edge. start_segment ( ) ) . start_angle ( ) ) )
688- . collect ( ) ;
689- # [ cfg ( feature = "logging" ) ]
690- dbg ! ( edges ) ;
661+ if cfg ! ( feature = "logging" ) {
662+ eprintln ! ( "Outgoing edges for {:?}:" , vertex_key ) ;
663+ for & edge_key in & vertex . outgoing_edges {
664+ let edge = & graph. edges [ edge_key ] ;
665+ let angle = edge. start_segment ( ) . start_angle ( ) ;
666+ eprintln ! ( "{:?}: {}°" , edge_key . 0 , angle . to_degrees ( ) )
667+ }
668+ }
691669 }
692670 }
693671}
@@ -926,9 +904,6 @@ fn compute_dual(minor_graph: &MinorGraph) -> Result<DualGraph, BooleanError> {
926904 }
927905 #[ cfg( feature = "logging" ) ]
928906 eprintln ! ( "component_vertices: {}" , component_vertices. len( ) ) ;
929- for edge in & dual_edges {
930- // eprintln!("{:?}", edge.incident_vertex);
931- }
932907
933908 let windings: Option < Vec < _ > > = component_vertices
934909 . iter ( )
@@ -971,21 +946,13 @@ fn compute_dual(minor_graph: &MinorGraph) -> Result<DualGraph, BooleanError> {
971946 // return Err(BooleanError::MultipleOuterFaces);
972947 #[ cfg( feature = "logging" ) ]
973948 eprintln ! ( "Found multiple outer faces: {areas:?}, falling back to area calculation" ) ;
974- let ( key, area) = * areas. iter ( ) . max_by_key ( |( _, area) | ( ( area. abs ( ) * 1000. ) as u64 ) ) . unwrap ( ) ;
975- if area < 0. {
976- reverse_winding = true ;
977- }
949+ let ( key, _) = * areas. iter ( ) . max_by_key ( |( _, area) | ( ( area. abs ( ) * 1000. ) as u64 ) ) . unwrap ( ) ;
978950 * key
979951 } else {
980952 * windings. iter ( ) . find ( |( & _, winding) | ( winding < & 0 ) ^ reverse_winding) . expect ( "No outer face of a component found." ) . 0
981953 } ;
982954 #[ cfg( feature = "logging" ) ]
983955 dbg ! ( outer_face_key) ;
984- if reverse_winding {
985- for & edge in component_edges. iter ( ) {
986- // dual_edges[edge].direction_flag = !dual_edges[edge].direction_flag;
987- }
988- }
989956
990957 components. push ( DualGraphComponent {
991958 vertices : component_vertices,
0 commit comments