@@ -547,24 +547,33 @@ async fn inscribe_circles(
547547 let point_ids_count = vector. point_domain . ids ( ) . len ( ) ;
548548 for point_index in 0 ..point_ids_count {
549549 let point_id = vector. point_domain . ids ( ) [ point_index] ;
550+
551+ // Get points with two connected segments
550552 let [ Some ( ( first_index, first) ) , Some ( ( second_index, second) ) , None ] = ( {
551553 let mut connected_segments = vector. segment_bezier_iter ( ) . enumerate ( ) . filter ( |& ( _, ( _, _, start, end) ) | ( start == point_id) != ( end == point_id) ) ;
552554 [ connected_segments. next ( ) , connected_segments. next ( ) , connected_segments. next ( ) ]
553555 } ) else {
554556 continue ;
555557 } ;
558+
559+ // Convert data types
556560 let flipped = [ first. 3 , second. 3 ] . map ( |end| end == point_id) ;
557561 let [ first, second] = [ first. 1 , second. 1 ]
558562 . map ( |t| t. apply_transformation ( |x| transform. transform_point2 ( x) ) )
559563 . map ( bezpath_algorithms:: inscribe_circles_algorithms:: bezier_to_path_seg) ;
560564 let first = if flipped[ 0 ] { first. reverse ( ) } else { first } ;
561565 let second = if flipped[ 1 ] { second. reverse ( ) } else { second } ;
562566
567+ // Find positions to inscribe
563568 let Some ( pos) = bezpath_algorithms:: inscribe_circles_algorithms:: inscribe ( first, second, radius) else {
564569 continue ;
565570 } ;
571+
572+ // Split path based on inscription
566573 let [ first, second] = [ first. subsegment ( pos. time_1 ..1.0 ) , second. subsegment ( pos. time_2 ..1.0 ) ] ;
567574 let start_positions = [ first, second] . map ( |segment| DVec2 :: new ( segment. start ( ) . x , segment. start ( ) . y ) ) ;
575+
576+ // Make round handles into circle shape
568577 let start_tangents = [ first, second] . map ( bezpath_algorithms:: inscribe_circles_algorithms:: tangent_at_start) . map ( |v| DVec2 :: new ( v. x , v. y ) ) ;
569578 let k = ( 4. / 3. ) * ( pos. theta / 4. ) . tan ( ) ;
570579 if !k. is_finite ( ) {
@@ -576,9 +585,18 @@ async fn inscribe_circles(
576585 handle_start : handle_positions[ 0 ] ,
577586 handle_end : handle_positions[ 1 ] ,
578587 } ;
588+
589+ // Convert data types back
579590 let first = if flipped[ 0 ] { first. reverse ( ) } else { first } ;
580591 let second = if flipped[ 1 ] { second. reverse ( ) } else { second } ;
581592 let handles = [ first, second] . map ( bezpath_algorithms:: inscribe_circles_algorithms:: path_seg_to_handles) ;
593+
594+ // Apply inverse transforms
595+ let inverse = transform. inverse ( ) ;
596+ let handles = handles. map ( |handle| handle. apply_transformation ( |p| inverse. transform_point2 ( p) ) ) ;
597+ let start_positions = start_positions. map ( |p| inverse. transform_point2 ( p) ) ;
598+ let rounded_handles = rounded_handles. apply_transformation ( |p| inverse. transform_point2 ( p) ) ;
599+
582600 vector. segment_domain . set_handles ( first_index, handles[ 0 ] ) ;
583601 vector. segment_domain . set_handles ( second_index, handles[ 1 ] ) ;
584602 let end_point_index = vector. point_domain . len ( ) ;
0 commit comments