@@ -104,6 +104,14 @@ impl ClosestSegment {
104
104
self . layer
105
105
}
106
106
107
+ pub fn segment ( & self ) -> SegmentId {
108
+ self . segment
109
+ }
110
+
111
+ pub fn points ( & self ) -> [ PointId ; 2 ] {
112
+ self . points
113
+ }
114
+
107
115
pub fn closest_point_to_viewport ( & self ) -> DVec2 {
108
116
self . bezier_point_to_viewport
109
117
}
@@ -128,9 +136,7 @@ impl ClosestSegment {
128
136
pub fn too_far ( & self , mouse_position : DVec2 , tolerance : f64 , document_metadata : & DocumentMetadata ) -> bool {
129
137
let dist_sq = self . distance_squared ( mouse_position) ;
130
138
let stroke_width = document_metadata. document_to_viewport . decompose_scale ( ) . x . max ( 1. ) * self . stroke_width ;
131
- let stroke_width_sq = stroke_width * stroke_width;
132
- let tolerance_sq = tolerance * tolerance;
133
- ( stroke_width_sq + tolerance_sq) < dist_sq
139
+ ( stroke_width + tolerance) . powi ( 2 ) < dist_sq
134
140
}
135
141
136
142
pub fn handle_positions ( & self , document_metadata : & DocumentMetadata ) -> ( Option < DVec2 > , Option < DVec2 > ) {
@@ -199,6 +205,28 @@ impl ClosestSegment {
199
205
let id = self . adjusted_insert ( responses) ;
200
206
shape_editor. select_anchor_point_by_id ( self . layer , id, extend_selection)
201
207
}
208
+
209
+ pub fn calculate_perp ( & self , document : & DocumentMessageHandler ) -> DVec2 {
210
+ let tangent = if let ( Some ( handle1) , Some ( handle2) ) = self . handle_positions ( document. metadata ( ) ) {
211
+ ( handle1 - handle2) . try_normalize ( )
212
+ } else {
213
+ let [ first_point, last_point] = self . points ( ) ;
214
+ if let Some ( vector_data) = document. network_interface . compute_modified_vector ( self . layer ( ) ) {
215
+ if let ( Some ( pos1) , Some ( pos2) ) = (
216
+ ManipulatorPointId :: Anchor ( first_point) . get_position ( & vector_data) ,
217
+ ManipulatorPointId :: Anchor ( last_point) . get_position ( & vector_data) ,
218
+ ) {
219
+ ( pos1 - pos2) . try_normalize ( )
220
+ } else {
221
+ None
222
+ }
223
+ } else {
224
+ None
225
+ }
226
+ }
227
+ . unwrap_or ( DVec2 :: ZERO ) ;
228
+ tangent. perp ( )
229
+ }
202
230
}
203
231
204
232
// TODO Consider keeping a list of selected manipulators to minimize traversals of the layers
@@ -900,6 +928,29 @@ impl ShapeState {
900
928
. collect :: < HashMap < _ , _ > > ( )
901
929
}
902
930
931
+ pub fn dissolve_segment ( & self , responses : & mut VecDeque < Message > , layer : LayerNodeIdentifier , vector_data : & VectorData , segment : SegmentId , points : [ PointId ; 2 ] ) {
932
+ // Checking which point is terminal point
933
+ let is_point1_terminal = vector_data. connected_count ( points[ 0 ] ) == 1 ;
934
+ let is_point2_terminal = vector_data. connected_count ( points[ 1 ] ) == 1 ;
935
+
936
+ // Delete the segment and terminal points
937
+ let modification_type = VectorModificationType :: RemoveSegment { id : segment } ;
938
+ responses. add ( GraphOperationMessage :: Vector { layer, modification_type } ) ;
939
+ for & handles in vector_data. colinear_manipulators . iter ( ) . filter ( |handles| handles. iter ( ) . any ( |handle| handle. segment == segment) ) {
940
+ let modification_type = VectorModificationType :: SetG1Continuous { handles, enabled : false } ;
941
+ responses. add ( GraphOperationMessage :: Vector { layer, modification_type } ) ;
942
+ }
943
+
944
+ if is_point1_terminal {
945
+ let modification_type = VectorModificationType :: RemovePoint { id : points[ 0 ] } ;
946
+ responses. add ( GraphOperationMessage :: Vector { layer, modification_type } ) ;
947
+ }
948
+ if is_point2_terminal {
949
+ let modification_type = VectorModificationType :: RemovePoint { id : points[ 1 ] } ;
950
+ responses. add ( GraphOperationMessage :: Vector { layer, modification_type } ) ;
951
+ }
952
+ }
953
+
903
954
fn dissolve_anchor ( anchor : PointId , responses : & mut VecDeque < Message > , layer : LayerNodeIdentifier , vector_data : & VectorData ) -> Option < [ ( HandleId , PointId ) ; 2 ] > {
904
955
// Delete point
905
956
let modification_type = VectorModificationType :: RemovePoint { id : anchor } ;
0 commit comments