@@ -594,30 +594,24 @@ pub fn create_bounding_box_transform(document: &DocumentMessageHandler) -> DAffi
594594
595595fn snap_pivot_to_bounds ( document : & DocumentMessageHandler , mouse_position : DVec2 , selection_bounds : & Option < BoundingBoxManager > ) -> Option < snapping:: SnappedPoint > {
596596 let tolerance = snapping:: snap_tolerance ( document) ;
597- let mut best_distance = f64:: INFINITY ;
598- let mut best_snap_point: Option < DVec2 > = None ;
599- let mut best_quad: Option < Quad > = None ;
600- let mut best_point_type: u8 = 0 ; // 0=corner, 1=midpoint, 2=center
597+ let mut best_snap: Option < ( DVec2 , Quad , BoundingBoxSnapTarget , f64 ) > = None ;
601598
602- let mut check_snap = |snap_doc : DVec2 , quad : Quad , point_type : u8 | {
599+ let mut check_snap = |snap_doc : DVec2 , quad : Quad , point_type : BoundingBoxSnapTarget | {
603600 let snap_viewport = document. metadata ( ) . document_to_viewport . transform_point2 ( snap_doc) ;
604601 let distance = mouse_position. distance ( snap_viewport) ;
605- if distance < tolerance && distance < best_distance {
606- best_distance = distance;
607- best_snap_point = Some ( snap_doc) ;
608- best_quad = Some ( quad) ;
609- best_point_type = point_type;
602+ if distance < tolerance && best_snap. map_or ( true , |( _, _, _, best_distance) | distance < best_distance) {
603+ best_snap = Some ( ( snap_doc, quad, point_type, distance) ) ;
610604 }
611605 } ;
612606
613607 // Snap to selection's combined bounding box
614608 if let Some ( bounds) = selection_bounds {
615609 let quad = document. metadata ( ) . document_to_viewport . inverse ( ) * bounds. transform * Quad :: from_box ( bounds. bounds ) ;
616610 for i in 0 ..4 {
617- check_snap ( quad. 0 [ i] , quad, 0 ) ;
618- check_snap ( ( quad. 0 [ i] + quad. 0 [ ( i + 1 ) % 4 ] ) / 2.0 , quad, 1 ) ;
611+ check_snap ( quad. 0 [ i] , quad, BoundingBoxSnapTarget :: CornerPoint ) ;
612+ check_snap ( ( quad. 0 [ i] + quad. 0 [ ( i + 1 ) % 4 ] ) / 2.0 , quad, BoundingBoxSnapTarget :: EdgeMidpoint ) ;
619613 }
620- check_snap ( quad. center ( ) , quad, 2 ) ;
614+ check_snap ( quad. center ( ) , quad, BoundingBoxSnapTarget :: CenterPoint ) ;
621615 }
622616
623617 let selected: Vec < _ > = document. network_interface . selected_nodes ( ) . selected_visible_and_unlocked_layers ( & document. network_interface ) . collect ( ) ;
@@ -630,27 +624,20 @@ fn snap_pivot_to_bounds(document: &DocumentMessageHandler, mouse_position: DVec2
630624 } ;
631625 let quad = Quad :: from_box ( bounds) ;
632626 for i in 0 ..4 {
633- check_snap ( quad. 0 [ i] , quad, 0 ) ;
634- check_snap ( ( quad. 0 [ i] + quad. 0 [ ( i + 1 ) % 4 ] ) / 2.0 , quad, 1 ) ;
627+ check_snap ( quad. 0 [ i] , quad, BoundingBoxSnapTarget :: CornerPoint ) ;
628+ check_snap ( ( quad. 0 [ i] + quad. 0 [ ( i + 1 ) % 4 ] ) / 2.0 , quad, BoundingBoxSnapTarget :: EdgeMidpoint ) ;
635629 }
636- check_snap ( quad. center ( ) , quad, 2 ) ;
630+ check_snap ( quad. center ( ) , quad, BoundingBoxSnapTarget :: CenterPoint ) ;
637631 }
638632
639- best_snap_point. zip ( best_quad) . map ( |( snap_point, quad) | {
640- let target = match best_point_type {
641- 0 => SnapTarget :: BoundingBox ( BoundingBoxSnapTarget :: CornerPoint ) ,
642- 1 => SnapTarget :: BoundingBox ( BoundingBoxSnapTarget :: EdgeMidpoint ) ,
643- _ => SnapTarget :: BoundingBox ( BoundingBoxSnapTarget :: CenterPoint ) ,
644- } ;
645- snapping:: SnappedPoint {
646- snapped_point_document : snap_point,
647- source : SnapSource :: Path ( PathSnapSource :: HandlePoint ) ,
648- target,
649- distance : best_distance,
650- tolerance,
651- target_bounds : Some ( quad) ,
652- ..Default :: default ( )
653- }
633+ best_snap. map ( |( snap_point, quad, point_type, distance) | snapping:: SnappedPoint {
634+ snapped_point_document : snap_point,
635+ source : SnapSource :: Path ( PathSnapSource :: HandlePoint ) ,
636+ target : SnapTarget :: BoundingBox ( point_type) ,
637+ distance,
638+ tolerance,
639+ target_bounds : Some ( quad) ,
640+ ..Default :: default ( )
654641 } )
655642}
656643
0 commit comments