1- use std:: f64:: consts:: PI ;
2-
31use super :: graph_modification_utils:: merge_layers;
42use super :: snapping:: { SnapCache , SnapCandidatePoint , SnapData , SnapManager , SnappedPoint } ;
53use super :: utility_functions:: { adjust_handle_colinearity, calculate_bezier_bbox, calculate_segment_angle, restore_g1_continuity, restore_previous_handle_position} ;
@@ -17,6 +15,7 @@ use bezier_rs::{Bezier, BezierHandles, Subpath, TValue};
1715use glam:: { DAffine2 , DVec2 } ;
1816use graphene_std:: vector:: { HandleExt , HandleId , SegmentId } ;
1917use graphene_std:: vector:: { ManipulatorPointId , PointId , VectorData , VectorModificationType } ;
18+ use std:: f64:: consts:: TAU ;
2019
2120#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
2221pub enum SelectionChange {
@@ -1034,8 +1033,8 @@ impl ShapeState {
10341033 /// If both or neither handles are selected, the angle of both handles will be averaged from their current angles, weighted by their lengths.
10351034 /// Assumes all selected manipulators have handles that are already not colinear.
10361035 ///
1037- /// For vector meshes, non colinear handle which is nearest in the direction of 180° angle separation, becomes colinear with current handle,
1038- /// if there is no such handle, nothing happens
1036+ /// For vector meshes, the non- colinear handle which is nearest in the direction of 180° angle separation becomes colinear with current handle.
1037+ /// If there is no such handle, nothing happens.
10391038 pub fn convert_selected_manipulators_to_colinear_handles ( & self , responses : & mut VecDeque < Message > , document : & DocumentMessageHandler ) {
10401039 let mut skip_set = HashSet :: new ( ) ;
10411040
@@ -1055,43 +1054,42 @@ impl ShapeState {
10551054
10561055 // Here we take handles as the current handle and the most opposite non-colinear-handle
10571056
1058- let is_handle_non_colinear = |handle : HandleId | -> bool { ! ( vector_data. colinear_manipulators . iter ( ) . any ( |& handles| handles[ 0 ] == handle || handles[ 1 ] == handle) ) } ;
1057+ let is_handle_colinear = |handle : HandleId | -> bool { vector_data. colinear_manipulators . iter ( ) . any ( |& handles| handles[ 0 ] == handle || handles[ 1 ] == handle) } ;
10591058
1060- let other_handles = match point {
1061- ManipulatorPointId :: Anchor ( _ ) => point. get_handle_pair ( & vector_data) ,
1062- _ => {
1063- point. get_all_connected_handles ( & vector_data) . and_then ( |handles| {
1064- let mut non_colinear_handles = handles. iter ( ) . filter ( |& handle| is_handle_non_colinear ( * handle) ) . clone ( ) . collect :: < Vec < _ > > ( ) ;
1059+ let other_handles = if matches ! ( point, ManipulatorPointId :: Anchor ( _ ) ) {
1060+ point. get_handle_pair ( & vector_data)
1061+ } else {
1062+ point. get_all_connected_handles ( & vector_data) . and_then ( |handles| {
1063+ let mut non_colinear_handles = handles. iter ( ) . filter ( |& handle| ! is_handle_colinear ( * handle) ) . clone ( ) . collect :: < Vec < _ > > ( ) ;
10651064
1066- // Sort these by angle from the current handle
1067- non_colinear_handles. sort_by ( |& handle_a, & handle_b| {
1068- let anchor = point. get_anchor_position ( & vector_data) . expect ( "No anchor position for handle" ) ;
1069- let orig_handle_pos = point. get_position ( & vector_data) . expect ( "No handle position" ) ;
1065+ // Sort these by angle from the current handle
1066+ non_colinear_handles. sort_by ( |& handle_a, & handle_b| {
1067+ let anchor = point. get_anchor_position ( & vector_data) . expect ( "No anchor position for handle" ) ;
1068+ let orig_handle_pos = point. get_position ( & vector_data) . expect ( "No handle position" ) ;
10701069
1071- let a_pos = handle_a. to_manipulator_point ( ) . get_position ( & vector_data) . expect ( "No handle position" ) ;
1072- let b_pos = handle_b. to_manipulator_point ( ) . get_position ( & vector_data) . expect ( "No handle position" ) ;
1070+ let a_pos = handle_a. to_manipulator_point ( ) . get_position ( & vector_data) . expect ( "No handle position" ) ;
1071+ let b_pos = handle_b. to_manipulator_point ( ) . get_position ( & vector_data) . expect ( "No handle position" ) ;
10731072
1074- let v_orig = ( orig_handle_pos - anchor) . normalize_or_zero ( ) ;
1073+ let v_orig = ( orig_handle_pos - anchor) . normalize_or_zero ( ) ;
10751074
1076- let v_a = ( a_pos - anchor) . normalize_or_zero ( ) ;
1077- let v_b = ( b_pos - anchor) . normalize_or_zero ( ) ;
1075+ let v_a = ( a_pos - anchor) . normalize_or_zero ( ) ;
1076+ let v_b = ( b_pos - anchor) . normalize_or_zero ( ) ;
10781077
1079- let angle_a = v_orig. angle_to ( v_a) . abs ( ) ;
1080- let angle_b = v_orig. angle_to ( v_b) . abs ( ) ;
1078+ let angle_a = v_orig. angle_to ( v_a) . abs ( ) ;
1079+ let angle_b = v_orig. angle_to ( v_b) . abs ( ) ;
10811080
1082- // Sort by descending angle (180° is farthest )
1083- angle_b. partial_cmp ( & angle_a) . unwrap_or ( std:: cmp:: Ordering :: Equal )
1084- } ) ;
1081+ // Sort by descending angle (180° is furthest )
1082+ angle_b. partial_cmp ( & angle_a) . unwrap_or ( std:: cmp:: Ordering :: Equal )
1083+ } ) ;
10851084
1086- let current = match point {
1087- ManipulatorPointId :: EndHandle ( segment) => HandleId :: end ( segment) ,
1088- ManipulatorPointId :: PrimaryHandle ( segment) => HandleId :: primary ( segment) ,
1089- ManipulatorPointId :: Anchor ( _) => unreachable ! ( ) ,
1090- } ;
1085+ let current = match point {
1086+ ManipulatorPointId :: EndHandle ( segment) => HandleId :: end ( segment) ,
1087+ ManipulatorPointId :: PrimaryHandle ( segment) => HandleId :: primary ( segment) ,
1088+ ManipulatorPointId :: Anchor ( _) => unreachable ! ( ) ,
1089+ } ;
10911090
1092- if let Some ( other) = non_colinear_handles. iter ( ) . next ( ) { Some ( [ current, * * other] ) } else { None }
1093- } )
1094- }
1091+ non_colinear_handles. first ( ) . map ( |other| [ current, * * other] )
1092+ } )
10951093 } ;
10961094
10971095 let Some ( handles) = other_handles else { continue } ;
@@ -1554,14 +1552,12 @@ impl ShapeState {
15541552 /// Disable colinear handles colinear.
15551553 pub fn disable_colinear_handles_state_on_selected ( & self , network_interface : & NodeNetworkInterface , responses : & mut VecDeque < Message > ) {
15561554 for ( & layer, state) in & self . selected_shape_state {
1557- let Some ( vector_data) = network_interface. compute_modified_vector ( layer) else {
1558- continue ;
1559- } ;
1555+ let Some ( vector_data) = network_interface. compute_modified_vector ( layer) else { continue } ;
15601556
15611557 for & point in & state. selected_points {
15621558 if let ManipulatorPointId :: Anchor ( point) = point {
15631559 for connected in vector_data. all_connected ( point) {
1564- if let Some ( & handles) = vector_data. colinear_manipulators . iter ( ) . find ( |target| target. iter ( ) . any ( | & target| target == connected) ) {
1560+ if let Some ( & handles) = vector_data. colinear_manipulators . iter ( ) . find ( |target| target. contains ( & connected) ) {
15651561 let modification_type = VectorModificationType :: SetG1Continuous { handles, enabled : false } ;
15661562 responses. add ( GraphOperationMessage :: Vector { layer, modification_type } ) ;
15671563 }
@@ -1800,7 +1796,7 @@ impl ShapeState {
18001796 let angle = base. angle_to ( to) ;
18011797 let cross = base. perp_dot ( to) ;
18021798
1803- if cross < 0.0 { 2.0 * PI - angle } else { angle }
1799+ if cross < 0. { TAU - angle } else { angle }
18041800 } ;
18051801
18061802 let angle_a = signed_angle ( v_orig, v_a) ;
0 commit comments