@@ -562,45 +562,67 @@ impl Fsm for PenToolFsmState {
562562 self
563563 }
564564 ( _, PenToolMessage :: Overlays ( mut overlay_context) ) => {
565+ let valid = |point : DVec2 , handle : DVec2 | point. distance_squared ( handle) >= HIDE_HANDLE_DISTANCE * HIDE_HANDLE_DISTANCE ;
566+
565567 let transform = document. metadata ( ) . document_to_viewport * transform;
568+
569+ // The currently-being-placed anchor
570+ let next_anchor = transform. transform_point2 ( tool_data. next_point ) ;
571+ // The currently-being-placed anchor's outgoing handle (the one currently being dragged out)
572+ let next_handle_start = transform. transform_point2 ( tool_data. next_handle_start ) ;
573+
574+ // The most recently placed anchor
575+ let anchor_start = tool_data. latest_point ( ) . map ( |point| transform. transform_point2 ( point. pos ) ) ;
576+ // The most recently placed anchor's incoming handle (opposite the one currently being dragged out)
577+ let handle_end = tool_data. handle_end . map ( |point| transform. transform_point2 ( point) ) ;
578+ // The most recently placed anchor's outgoing handle (which is currently influencing the currently-being-placed segment)
579+ let handle_start = tool_data. latest_point ( ) . map ( |point| transform. transform_point2 ( point. handle_start ) ) ;
580+
566581 if let ( Some ( ( start, handle_start) ) , Some ( handle_end) ) = ( tool_data. latest_point ( ) . map ( |point| ( point. pos , point. handle_start ) ) , tool_data. handle_end ) {
567582 let handles = BezierHandles :: Cubic { handle_start, handle_end } ;
568- let bezier = Bezier {
569- start,
570- handles,
571- end : tool_data. next_point ,
572- } ;
583+ let end = tool_data. next_point ;
584+ let bezier = Bezier { start, handles, end } ;
585+ // Draw the curve for the currently-being-placed segment
573586 overlay_context. outline_bezier ( bezier, transform) ;
574587 }
575588
576- let valid = |point : DVec2 , handle : DVec2 | point. distance_squared ( handle) >= HIDE_HANDLE_DISTANCE * HIDE_HANDLE_DISTANCE ;
577- let next_point = transform. transform_point2 ( tool_data. next_point ) ;
578- let next_handle_start = transform. transform_point2 ( tool_data. next_handle_start ) ;
579- overlay_context. line ( next_point, next_handle_start, None ) ;
580- let start = tool_data. latest_point ( ) . map ( |point| transform. transform_point2 ( point. pos ) ) ;
589+ // Draw the line between the currently-being-placed anchor and its currently-being-dragged-out outgoing handle (opposite the one currently being dragged out)
590+ overlay_context. line ( next_anchor, next_handle_start, None ) ;
581591
582- let handle_start = tool_data. latest_point ( ) . map ( |point| transform. transform_point2 ( point. handle_start ) ) ;
583- let handle_end = tool_data. handle_end . map ( |point| transform. transform_point2 ( point) ) ;
592+ if let ( Some ( anchor_start) , Some ( handle_start) , Some ( handle_end) ) = ( anchor_start, handle_start, handle_end) {
593+ // Draw the line between the most recently placed anchor and its outgoing handle (which is currently influencing the currently-being-placed segment)
594+ overlay_context. line ( anchor_start, handle_start, None ) ;
584595
585- if let ( Some ( start) , Some ( handle_start) , Some ( handle_end) ) = ( start, handle_start, handle_end) {
586- overlay_context. line ( start, handle_start, None ) ;
587- overlay_context. line ( next_point, handle_end, None ) ;
596+ // Draw the line between the currently-being-placed anchor and its incoming handle (opposite the one currently being dragged out)
597+ overlay_context. line ( next_anchor, handle_end, None ) ;
588598
589599 path_overlays ( document, shape_editor, & mut overlay_context) ;
590600
591- if self == PenToolFsmState :: DraggingHandle && valid ( next_point, handle_end) {
601+ if self == PenToolFsmState :: DraggingHandle && valid ( next_anchor, handle_end) {
602+ // Draw the handle circle for the currently-being-dragged-out incoming handle (opposite the one currently being dragged out)
592603 overlay_context. manipulator_handle ( handle_end, false ) ;
593604 }
594- if valid ( start, handle_start) {
605+
606+ if valid ( anchor_start, handle_start) {
607+ // Draw the handle circle for the most recently placed anchor's outgoing handle (which is currently influencing the currently-being-placed segment)
595608 overlay_context. manipulator_handle ( handle_start, false ) ;
596609 }
597610 } else {
611+ // Draw the whole path and its manipulators when the user is clicking-and-dragging out from the most recently placed anchor to set its outgoing handle, during which it would otherwise not have its overlays drawn
598612 path_overlays ( document, shape_editor, & mut overlay_context) ;
599613 }
600- if self == PenToolFsmState :: DraggingHandle && valid ( next_point, next_handle_start) {
614+
615+ if self == PenToolFsmState :: DraggingHandle && valid ( next_anchor, next_handle_start) {
616+ // Draw the handle circle for the currently-being-dragged-out outgoing handle (the one currently being dragged out, under the user's cursor)
601617 overlay_context. manipulator_handle ( next_handle_start, false ) ;
602618 }
603- overlay_context. manipulator_anchor ( next_point, false , None ) ;
619+
620+ if self == PenToolFsmState :: DraggingHandle {
621+ // Draw the anchor square for the most recently placed anchor
622+ overlay_context. manipulator_anchor ( next_anchor, false , None ) ;
623+ }
624+
625+ // Draw the overlays that visualize current snapping
604626 tool_data. snap_manager . draw_overlays ( SnapData :: new ( document, input) , & mut overlay_context) ;
605627
606628 self
0 commit comments