@@ -691,32 +691,28 @@ impl Fsm for SelectToolFsmState {
691
691
// Measure with Alt held down
692
692
// TODO: Don't use `Key::Alt` directly, instead take it as a variable from the input mappings list like in all other places
693
693
if overlay_context. visibility_settings . quick_measurement ( ) && !matches ! ( self , Self :: ResizingBounds { .. } ) && input. keyboard . get ( Key :: Alt as usize ) {
694
- // Get all selected layers and compute their viewport-aligned AABB
695
- let selected_bounds_viewport = document
694
+ // Compute document-space bounding box (AABB) of all selected visible & unlocked layers
695
+ let selected_bounds_doc_space = document
696
696
. network_interface
697
697
. selected_nodes ( )
698
698
. selected_visible_and_unlocked_layers ( & document. network_interface )
699
+ // Exclude layers that are artboards
699
700
. filter ( |layer| !document. network_interface . is_artboard ( & layer. to_node ( ) , & [ ] ) )
700
- . filter_map ( |layer| {
701
- // Get the layer's bounding box in its local space
702
- let local_bounds = document. metadata ( ) . bounding_box_with_transform ( layer, DAffine2 :: IDENTITY ) ?;
703
- // Transform the bounds directly to viewport space
704
- let viewport_quad = document. metadata ( ) . transform_to_viewport ( layer) * Quad :: from_box ( local_bounds) ;
705
- // Convert the quad to an AABB in viewport space
706
- Some ( Rect :: from_box ( viewport_quad. bounding_box ( ) ) )
707
- } )
701
+ // For each remaining layer, try to get its document-space bounding box and convert it to a Rect
702
+ . filter_map ( |layer| document. metadata ( ) . bounding_box_document ( layer) . map ( Rect :: from_box) )
703
+ // Combine all individual bounding boxes into one overall bounding box that contains all selected layers
708
704
. reduce ( Rect :: combine_bounds) ;
709
705
710
- // Get the hovered layer's viewport-aligned AABB
711
- let hovered_bounds_viewport = document. metadata ( ) . bounding_box_with_transform ( layer, DAffine2 :: IDENTITY ) . map ( |bounds| {
712
- let viewport_quad = document. metadata ( ) . transform_to_viewport ( layer) * Quad :: from_box ( bounds) ;
713
- Rect :: from_box ( viewport_quad. bounding_box ( ) )
714
- } ) ;
706
+ // Compute document-space bounding box (AABB) of the currently hovered layer
707
+ let hovered_bounds_doc_space = document. metadata ( ) . bounding_box_document ( layer) ;
715
708
716
- // Use the viewport-aligned AABBs for measurement
717
- if let ( Some ( selected_bounds) , Some ( hovered_bounds) ) = ( selected_bounds_viewport, hovered_bounds_viewport) {
718
- // Since we're already in viewport space, use identity transform
719
- measure:: overlay ( selected_bounds, hovered_bounds, DAffine2 :: IDENTITY , DAffine2 :: IDENTITY , & mut overlay_context) ;
709
+ // If both selected and hovered bounds exist, overlay measurement lines
710
+ if let ( Some ( selected_bounds) , Some ( hovered_bounds) ) = ( selected_bounds_doc_space, hovered_bounds_doc_space. map ( Rect :: from_box) ) {
711
+ // Both `selected_bounds` and `hovered_bounds` are in document space.
712
+ // To correctly render overlay lines in the UI (which is in viewport space), we need to transform both rectangles from document to viewport space.
713
+ // Therefore, we pass `document_to_viewport` as both the `transform` and `document_to_viewport` parameters.
714
+ let document_to_viewport = document. metadata ( ) . document_to_viewport ;
715
+ measure:: overlay ( selected_bounds, hovered_bounds, document_to_viewport, document_to_viewport, & mut overlay_context) ;
720
716
}
721
717
}
722
718
}
0 commit comments