1- use super :: graph_modification_utils:: { self , merge_layers} ;
1+ use super :: graph_modification_utils:: merge_layers;
22use super :: snapping:: { SnapCache , SnapCandidatePoint , SnapData , SnapManager , SnappedPoint } ;
33use super :: utility_functions:: calculate_segment_angle;
44use crate :: consts:: HANDLE_LENGTH_FACTOR ;
@@ -12,7 +12,6 @@ use crate::messages::tool::common_functionality::utility_functions::is_visible_p
1212use crate :: messages:: tool:: tool_messages:: path_tool:: { PathOverlayMode , PointSelectState } ;
1313use bezier_rs:: { Bezier , BezierHandles , Subpath , TValue } ;
1414use glam:: { DAffine2 , DVec2 } ;
15- use graphene_core:: transform:: Transform ;
1615use graphene_core:: vector:: { ManipulatorPointId , PointId , VectorData , VectorModificationType } ;
1716use graphene_std:: vector:: { HandleId , SegmentId } ;
1817
@@ -149,7 +148,6 @@ pub struct ClosestSegment {
149148 colinear : [ Option < HandleId > ; 2 ] ,
150149 t : f64 ,
151150 bezier_point_to_viewport : DVec2 ,
152- stroke_width : f64 ,
153151}
154152
155153impl ClosestSegment {
@@ -169,6 +167,12 @@ impl ClosestSegment {
169167 self . bezier_point_to_viewport
170168 }
171169
170+ pub fn closest_point ( & self , document_metadata : & DocumentMetadata ) -> DVec2 {
171+ let transform = document_metadata. transform_to_viewport ( self . layer ) ;
172+ let bezier_point = self . bezier . evaluate ( TValue :: Parametric ( self . t ) ) ;
173+ transform. transform_point2 ( bezier_point)
174+ }
175+
172176 /// Updates this [`ClosestSegment`] with the viewport-space location of the closest point on the segment to the given mouse position.
173177 pub fn update_closest_point ( & mut self , document_metadata : & DocumentMetadata , mouse_position : DVec2 ) {
174178 let transform = document_metadata. transform_to_viewport ( self . layer ) ;
@@ -186,10 +190,8 @@ impl ClosestSegment {
186190 self . bezier_point_to_viewport . distance_squared ( mouse_position)
187191 }
188192
189- pub fn too_far ( & self , mouse_position : DVec2 , tolerance : f64 , document_metadata : & DocumentMetadata ) -> bool {
190- let dist_sq = self . distance_squared ( mouse_position) ;
191- let stroke_width = document_metadata. document_to_viewport . decompose_scale ( ) . x . max ( 1. ) * self . stroke_width ;
192- ( stroke_width + tolerance) . powi ( 2 ) < dist_sq
193+ pub fn too_far ( & self , mouse_position : DVec2 , tolerance : f64 ) -> bool {
194+ tolerance. powi ( 2 ) < self . distance_squared ( mouse_position)
193195 }
194196
195197 pub fn handle_positions ( & self , document_metadata : & DocumentMetadata ) -> ( Option < DVec2 > , Option < DVec2 > ) {
@@ -1449,11 +1451,6 @@ impl ShapeState {
14491451 if distance_squared < closest_distance_squared {
14501452 closest_distance_squared = distance_squared;
14511453
1452- // 0.5 is half the line (center to side) but it's convenient to allow targeting slightly more than half the line width
1453- const STROKE_WIDTH_PERCENT : f64 = 0.7 ;
1454-
1455- let stroke_width = graph_modification_utils:: get_stroke_width ( layer, network_interface) . unwrap_or ( 1. ) as f64 * STROKE_WIDTH_PERCENT ;
1456-
14571454 // Convert to linear if handes are on top of control points
14581455 if let bezier_rs:: BezierHandles :: Cubic { handle_start, handle_end } = bezier. handles {
14591456 if handle_start. abs_diff_eq ( bezier. start ( ) , f64:: EPSILON * 100. ) && handle_end. abs_diff_eq ( bezier. end ( ) , f64:: EPSILON * 100. ) {
@@ -1474,7 +1471,6 @@ impl ShapeState {
14741471 t,
14751472 bezier_point_to_viewport : screenspace,
14761473 layer,
1477- stroke_width,
14781474 } ) ;
14791475 }
14801476 }
0 commit comments