@@ -596,22 +596,24 @@ fn snap_pivot_to_bounds(document: &DocumentMessageHandler, mouse_position: DVec2
596596 let tolerance = snapping:: snap_tolerance ( document) ;
597597 let mut best_snap: Option < ( DVec2 , Quad , BoundingBoxSnapTarget , f64 ) > = None ;
598598
599- let mut check_snap = |snap_doc : DVec2 , quad : Quad , point_type : BoundingBoxSnapTarget | {
600- let snap_viewport = document. metadata ( ) . document_to_viewport . transform_point2 ( snap_doc) ;
601- let distance = mouse_position. distance ( snap_viewport) ;
602- if distance < tolerance && best_snap. map_or ( true , |( _, _, _, best_distance) | distance < best_distance) {
603- best_snap = Some ( ( snap_doc, quad, point_type, distance) ) ;
599+ let mut check_quad = |quad : Quad | {
600+ let check = |snap_doc : DVec2 , point_type : BoundingBoxSnapTarget , best : & mut Option < ( DVec2 , Quad , BoundingBoxSnapTarget , f64 ) > | {
601+ let snap_viewport = document. metadata ( ) . document_to_viewport . transform_point2 ( snap_doc) ;
602+ let distance = mouse_position. distance ( snap_viewport) ;
603+ if distance < tolerance && best. map_or ( true , |( _, _, _, d) | distance < d) {
604+ * best = Some ( ( snap_doc, quad, point_type, distance) ) ;
605+ }
606+ } ;
607+ for i in 0 ..4 {
608+ check ( quad. 0 [ i] , BoundingBoxSnapTarget :: CornerPoint , & mut best_snap) ;
609+ check ( ( quad. 0 [ i] + quad. 0 [ ( i + 1 ) % 4 ] ) / 2.0 , BoundingBoxSnapTarget :: EdgeMidpoint , & mut best_snap) ;
604610 }
611+ check ( quad. center ( ) , BoundingBoxSnapTarget :: CenterPoint , & mut best_snap) ;
605612 } ;
606613
607614 // Snap to selection's combined bounding box
608615 if let Some ( bounds) = selection_bounds {
609- let quad = document. metadata ( ) . document_to_viewport . inverse ( ) * bounds. transform * Quad :: from_box ( bounds. bounds ) ;
610- for i in 0 ..4 {
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 ) ;
613- }
614- check_snap ( quad. center ( ) , quad, BoundingBoxSnapTarget :: CenterPoint ) ;
616+ check_quad ( document. metadata ( ) . document_to_viewport . inverse ( ) * bounds. transform * Quad :: from_box ( bounds. bounds ) ) ;
615617 }
616618
617619 let selected: Vec < _ > = document. network_interface . selected_nodes ( ) . selected_visible_and_unlocked_layers ( & document. network_interface ) . collect ( ) ;
@@ -622,12 +624,7 @@ fn snap_pivot_to_bounds(document: &DocumentMessageHandler, mouse_position: DVec2
622624 let Some ( bounds) = document. metadata ( ) . bounding_box_with_transform ( layer, document. metadata ( ) . transform_to_document ( layer) ) else {
623625 continue ;
624626 } ;
625- let quad = Quad :: from_box ( bounds) ;
626- for i in 0 ..4 {
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 ) ;
629- }
630- check_snap ( quad. center ( ) , quad, BoundingBoxSnapTarget :: CenterPoint ) ;
627+ check_quad ( Quad :: from_box ( bounds) ) ;
631628 }
632629
633630 best_snap. map ( |( snap_point, quad, point_type, distance) | snapping:: SnappedPoint {
0 commit comments