@@ -196,8 +196,8 @@ impl DistributionSnapper {
196
196
let mut snap_x: Option < SnappedPoint > = None ;
197
197
let mut snap_y: Option < SnappedPoint > = None ;
198
198
199
- self . x ( consider_x, bounds, tolerance, & mut snap_x, point) ;
200
- self . y ( consider_y, bounds, tolerance, & mut snap_y, point) ;
199
+ self . horizontal_snap ( consider_x, bounds, tolerance / 2. , & mut snap_x, point) ;
200
+ self . vertical_snap ( consider_y, bounds, tolerance / 2. , & mut snap_y, point) ;
201
201
202
202
match ( snap_x, snap_y) {
203
203
( Some ( x) , Some ( y) ) => {
@@ -220,7 +220,7 @@ impl DistributionSnapper {
220
220
}
221
221
}
222
222
223
- fn x ( & self , consider_x : bool , bounds : Rect , tolerance : f64 , snap_x : & mut Option < SnappedPoint > , point : & SnapCandidatePoint ) {
223
+ fn horizontal_snap ( & self , consider_x : bool , bounds : Rect , tolerance : f64 , snap_x : & mut Option < SnappedPoint > , point : & SnapCandidatePoint ) {
224
224
// Right
225
225
if consider_x && !self . right . is_empty ( ) {
226
226
let ( equal_dist, mut vec_right) = Self :: top_level_matches ( bounds, & self . right , tolerance, dist_right) ;
@@ -269,7 +269,7 @@ impl DistributionSnapper {
269
269
}
270
270
}
271
271
272
- fn y ( & self , consider_y : bool , bounds : Rect , tolerance : f64 , snap_y : & mut Option < SnappedPoint > , point : & SnapCandidatePoint ) {
272
+ fn vertical_snap ( & self , consider_y : bool , bounds : Rect , tolerance : f64 , snap_y : & mut Option < SnappedPoint > , point : & SnapCandidatePoint ) {
273
273
// Down
274
274
if consider_y && !self . down . is_empty ( ) {
275
275
let ( equal_dist, mut vec_down) = Self :: top_level_matches ( bounds, & self . down , tolerance, dist_down) ;
@@ -322,7 +322,24 @@ impl DistributionSnapper {
322
322
}
323
323
324
324
pub fn free_snap ( & mut self , snap_data : & mut SnapData , point : & SnapCandidatePoint , snap_results : & mut SnapResults , config : SnapTypeConfiguration ) {
325
- let Some ( bounds) = config. bbox else { return } ;
325
+ let Some ( config_bbox) = config. bbox else { return } ;
326
+ let Some ( layer_bbox) = snap_data
327
+ . document
328
+ . metadata ( )
329
+ . bounding_box_document (
330
+ snap_data
331
+ . document
332
+ . network_interface
333
+ . selected_nodes ( )
334
+ . selected_unlocked_layers ( & snap_data. document . network_interface )
335
+ . next ( )
336
+ . expect ( "No selected layers" ) ,
337
+ )
338
+ . map ( |bbox| Rect :: from_box ( bbox) )
339
+ else {
340
+ return ;
341
+ } ;
342
+ let bounds = config_bbox. intersection ( layer_bbox) . expect ( "No Intersection" ) ;
326
343
if point. source != SnapSource :: BoundingBox ( BoundingBoxSnapSource :: CenterPoint ) || !snap_data. document . snapping_state . bounding_box . distribute_evenly {
327
344
return ;
328
345
}
0 commit comments