@@ -545,24 +545,33 @@ async fn inscribe_circles(
545545 let point_ids_count = vector. point_domain . ids ( ) . len ( ) ;
546546 for point_index in 0 ..point_ids_count {
547547 let point_id = vector. point_domain . ids ( ) [ point_index] ;
548+
549+ // Get points with two connected segments
548550 let [ Some ( ( first_index, first) ) , Some ( ( second_index, second) ) , None ] = ( {
549551 let mut connected_segments = vector. segment_bezier_iter ( ) . enumerate ( ) . filter ( |& ( _, ( _, _, start, end) ) | ( start == point_id) != ( end == point_id) ) ;
550552 [ connected_segments. next ( ) , connected_segments. next ( ) , connected_segments. next ( ) ]
551553 } ) else {
552554 continue ;
553555 } ;
556+
557+ // Convert data types
554558 let flipped = [ first. 3 , second. 3 ] . map ( |end| end == point_id) ;
555559 let [ first, second] = [ first. 1 , second. 1 ]
556560 . map ( |t| t. apply_transformation ( |x| transform. transform_point2 ( x) ) )
557561 . map ( bezpath_algorithms:: inscribe_circles_algorithms:: bezier_to_path_seg) ;
558562 let first = if flipped[ 0 ] { first. reverse ( ) } else { first } ;
559563 let second = if flipped[ 1 ] { second. reverse ( ) } else { second } ;
560564
565+ // Find positions to inscribe
561566 let Some ( pos) = bezpath_algorithms:: inscribe_circles_algorithms:: inscribe ( first, second, radius) else {
562567 continue ;
563568 } ;
569+
570+ // Split path based on inscription
564571 let [ first, second] = [ first. subsegment ( pos. time_1 ..1.0 ) , second. subsegment ( pos. time_2 ..1.0 ) ] ;
565572 let start_positions = [ first, second] . map ( |segment| DVec2 :: new ( segment. start ( ) . x , segment. start ( ) . y ) ) ;
573+
574+ // Make round handles into circle shape
566575 let start_tangents = [ first, second] . map ( bezpath_algorithms:: inscribe_circles_algorithms:: tangent_at_start) . map ( |v| DVec2 :: new ( v. x , v. y ) ) ;
567576 let k = ( 4. / 3. ) * ( pos. theta / 4. ) . tan ( ) ;
568577 if !k. is_finite ( ) {
@@ -574,9 +583,18 @@ async fn inscribe_circles(
574583 handle_start : handle_positions[ 0 ] ,
575584 handle_end : handle_positions[ 1 ] ,
576585 } ;
586+
587+ // Convert data types back
577588 let first = if flipped[ 0 ] { first. reverse ( ) } else { first } ;
578589 let second = if flipped[ 1 ] { second. reverse ( ) } else { second } ;
579590 let handles = [ first, second] . map ( bezpath_algorithms:: inscribe_circles_algorithms:: path_seg_to_handles) ;
591+
592+ // Apply inverse transforms
593+ let inverse = transform. inverse ( ) ;
594+ let handles = handles. map ( |handle| handle. apply_transformation ( |p| inverse. transform_point2 ( p) ) ) ;
595+ let start_positions = start_positions. map ( |p| inverse. transform_point2 ( p) ) ;
596+ let rounded_handles = rounded_handles. apply_transformation ( |p| inverse. transform_point2 ( p) ) ;
597+
580598 vector. segment_domain . set_handles ( first_index, handles[ 0 ] ) ;
581599 vector. segment_domain . set_handles ( second_index, handles[ 1 ] ) ;
582600 let end_point_index = vector. point_domain . len ( ) ;
0 commit comments