@@ -567,24 +567,33 @@ async fn inscribe_circles(
567567 let point_ids_count = vector. point_domain . ids ( ) . len ( ) ;
568568 for point_index in 0 ..point_ids_count {
569569 let point_id = vector. point_domain . ids ( ) [ point_index] ;
570+
571+ // Get points with two connected segments
570572 let [ Some ( ( first_index, first) ) , Some ( ( second_index, second) ) , None ] = ( {
571573 let mut connected_segments = vector. segment_bezier_iter ( ) . enumerate ( ) . filter ( |& ( _, ( _, _, start, end) ) | ( start == point_id) != ( end == point_id) ) ;
572574 [ connected_segments. next ( ) , connected_segments. next ( ) , connected_segments. next ( ) ]
573575 } ) else {
574576 continue ;
575577 } ;
578+
579+ // Convert data types
576580 let flipped = [ first. 3 , second. 3 ] . map ( |end| end == point_id) ;
577581 let [ first, second] = [ first. 1 , second. 1 ]
578582 . map ( |t| t. apply_transformation ( |x| transform. transform_point2 ( x) ) )
579583 . map ( bezpath_algorithms:: inscribe_circles_algorithms:: bezier_to_path_seg) ;
580584 let first = if flipped[ 0 ] { first. reverse ( ) } else { first } ;
581585 let second = if flipped[ 1 ] { second. reverse ( ) } else { second } ;
582586
587+ // Find positions to inscribe
583588 let Some ( pos) = bezpath_algorithms:: inscribe_circles_algorithms:: inscribe ( first, second, radius) else {
584589 continue ;
585590 } ;
591+
592+ // Split path based on inscription
586593 let [ first, second] = [ first. subsegment ( pos. time_1 ..1.0 ) , second. subsegment ( pos. time_2 ..1.0 ) ] ;
587594 let start_positions = [ first, second] . map ( |segment| DVec2 :: new ( segment. start ( ) . x , segment. start ( ) . y ) ) ;
595+
596+ // Make round handles into circle shape
588597 let start_tangents = [ first, second] . map ( bezpath_algorithms:: inscribe_circles_algorithms:: tangent_at_start) . map ( |v| DVec2 :: new ( v. x , v. y ) ) ;
589598 let k = ( 4. / 3. ) * ( pos. theta / 4. ) . tan ( ) ;
590599 if !k. is_finite ( ) {
@@ -596,9 +605,18 @@ async fn inscribe_circles(
596605 handle_start : handle_positions[ 0 ] ,
597606 handle_end : handle_positions[ 1 ] ,
598607 } ;
608+
609+ // Convert data types back
599610 let first = if flipped[ 0 ] { first. reverse ( ) } else { first } ;
600611 let second = if flipped[ 1 ] { second. reverse ( ) } else { second } ;
601612 let handles = [ first, second] . map ( bezpath_algorithms:: inscribe_circles_algorithms:: path_seg_to_handles) ;
613+
614+ // Apply inverse transforms
615+ let inverse = transform. inverse ( ) ;
616+ let handles = handles. map ( |handle| handle. apply_transformation ( |p| inverse. transform_point2 ( p) ) ) ;
617+ let start_positions = start_positions. map ( |p| inverse. transform_point2 ( p) ) ;
618+ let rounded_handles = rounded_handles. apply_transformation ( |p| inverse. transform_point2 ( p) ) ;
619+
602620 vector. segment_domain . set_handles ( first_index, handles[ 0 ] ) ;
603621 vector. segment_domain . set_handles ( second_index, handles[ 1 ] ) ;
604622 let end_point_index = vector. point_domain . len ( ) ;
0 commit comments