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