@@ -126,6 +126,14 @@ impl ClosestSegment {
126126 self . layer
127127 }
128128
129+ pub fn segment ( & self ) -> SegmentId {
130+ self . segment
131+ }
132+
133+ pub fn points ( & self ) -> [ PointId ; 2 ] {
134+ self . points
135+ }
136+
129137 pub fn closest_point_to_viewport ( & self ) -> DVec2 {
130138 self . bezier_point_to_viewport
131139 }
@@ -150,9 +158,7 @@ impl ClosestSegment {
150158 pub fn too_far ( & self , mouse_position : DVec2 , tolerance : f64 , document_metadata : & DocumentMetadata ) -> bool {
151159 let dist_sq = self . distance_squared ( mouse_position) ;
152160 let stroke_width = document_metadata. document_to_viewport . decompose_scale ( ) . x . max ( 1. ) * self . stroke_width ;
153- let stroke_width_sq = stroke_width * stroke_width;
154- let tolerance_sq = tolerance * tolerance;
155- ( stroke_width_sq + tolerance_sq) < dist_sq
161+ ( stroke_width + tolerance) . powi ( 2 ) < dist_sq
156162 }
157163
158164 pub fn handle_positions ( & self , document_metadata : & DocumentMetadata ) -> ( Option < DVec2 > , Option < DVec2 > ) {
@@ -221,6 +227,28 @@ impl ClosestSegment {
221227 let id = self . adjusted_insert ( responses) ;
222228 shape_editor. select_anchor_point_by_id ( self . layer , id, extend_selection)
223229 }
230+
231+ pub fn calculate_perp ( & self , document : & DocumentMessageHandler ) -> DVec2 {
232+ let tangent = if let ( Some ( handle1) , Some ( handle2) ) = self . handle_positions ( document. metadata ( ) ) {
233+ ( handle1 - handle2) . try_normalize ( )
234+ } else {
235+ let [ first_point, last_point] = self . points ( ) ;
236+ if let Some ( vector_data) = document. network_interface . compute_modified_vector ( self . layer ( ) ) {
237+ if let ( Some ( pos1) , Some ( pos2) ) = (
238+ ManipulatorPointId :: Anchor ( first_point) . get_position ( & vector_data) ,
239+ ManipulatorPointId :: Anchor ( last_point) . get_position ( & vector_data) ,
240+ ) {
241+ ( pos1 - pos2) . try_normalize ( )
242+ } else {
243+ None
244+ }
245+ } else {
246+ None
247+ }
248+ }
249+ . unwrap_or ( DVec2 :: ZERO ) ;
250+ tangent. perp ( )
251+ }
224252}
225253
226254// TODO Consider keeping a list of selected manipulators to minimize traversals of the layers
@@ -978,6 +1006,29 @@ impl ShapeState {
9781006 . collect :: < HashMap < _ , _ > > ( )
9791007 }
9801008
1009+ pub fn dissolve_segment ( & self , responses : & mut VecDeque < Message > , layer : LayerNodeIdentifier , vector_data : & VectorData , segment : SegmentId , points : [ PointId ; 2 ] ) {
1010+ // Checking which point is terminal point
1011+ let is_point1_terminal = vector_data. connected_count ( points[ 0 ] ) == 1 ;
1012+ let is_point2_terminal = vector_data. connected_count ( points[ 1 ] ) == 1 ;
1013+
1014+ // Delete the segment and terminal points
1015+ let modification_type = VectorModificationType :: RemoveSegment { id : segment } ;
1016+ responses. add ( GraphOperationMessage :: Vector { layer, modification_type } ) ;
1017+ for & handles in vector_data. colinear_manipulators . iter ( ) . filter ( |handles| handles. iter ( ) . any ( |handle| handle. segment == segment) ) {
1018+ let modification_type = VectorModificationType :: SetG1Continuous { handles, enabled : false } ;
1019+ responses. add ( GraphOperationMessage :: Vector { layer, modification_type } ) ;
1020+ }
1021+
1022+ if is_point1_terminal {
1023+ let modification_type = VectorModificationType :: RemovePoint { id : points[ 0 ] } ;
1024+ responses. add ( GraphOperationMessage :: Vector { layer, modification_type } ) ;
1025+ }
1026+ if is_point2_terminal {
1027+ let modification_type = VectorModificationType :: RemovePoint { id : points[ 1 ] } ;
1028+ responses. add ( GraphOperationMessage :: Vector { layer, modification_type } ) ;
1029+ }
1030+ }
1031+
9811032 fn dissolve_anchor ( anchor : PointId , responses : & mut VecDeque < Message > , layer : LayerNodeIdentifier , vector_data : & VectorData ) -> Option < [ ( HandleId , PointId ) ; 2 ] > {
9821033 // Delete point
9831034 let modification_type = VectorModificationType :: RemovePoint { id : anchor } ;
0 commit comments