@@ -138,6 +138,11 @@ class Graphics extends Visual {
138138 */
139139 var pathSegments : Array <Array <Float >> = [];
140140
141+ /**
142+ * Tracks which path segments have been closed via closePath()
143+ */
144+ var pathSegmentsClosed : Array <Bool > = [];
145+
141146 /**
142147 * Current depth value for ordering visuals.
143148 * Incremented for each visual added to ensure proper render order.
@@ -274,6 +279,7 @@ class Graphics extends Visual {
274279 // Clear path data
275280 currentPath = null ;
276281 pathSegments .resize (0 );
282+ pathSegmentsClosed .resize (0 );
277283 currentX = 0 ;
278284 currentY = 0 ;
279285
@@ -604,10 +610,12 @@ class Graphics extends Visual {
604610 // Start a new path segment
605611 if (pathSegments .length > 0 && pathSegments [pathSegments .length - 1 ].length >= 2 ) {
606612 pathSegments .push ([]);
613+ pathSegmentsClosed .push (false );
607614 }
608615
609616 if (pathSegments .length == 0 ) {
610617 pathSegments .push ([]);
618+ pathSegmentsClosed .push (false );
611619 }
612620
613621 var segment = pathSegments [pathSegments .length - 1 ];
@@ -767,7 +775,8 @@ class Graphics extends Visual {
767775 * Draw all accumulated path segments
768776 */
769777 public function drawPath (): Void {
770- for (segment in pathSegments ) {
778+ for (i in 0 ... pathSegments .length ) {
779+ var segment = pathSegments [i ];
771780 if (segment .length >= 4 ) {
772781 var line = getLine ();
773782 // Copy segment points to the line's points array
@@ -777,25 +786,33 @@ class Graphics extends Visual {
777786 line .thickness = lineThickness ;
778787 line .color = lineColor ;
779788 line .alpha = lineAlpha ;
789+ // Set loop if this segment was closed via closePath()
790+ if (pathSegmentsClosed [i ]) {
791+ line .loop = true ;
792+ }
780793
781794 // Update current position to end of this segment
782795 currentX = segment [segment .length - 2 ];
783796 currentY = segment [segment .length - 1 ];
784797 }
785798 }
786799 pathSegments .resize (0 );
800+ pathSegmentsClosed .resize (0 );
787801 }
788802
789803 /**
790804 * Close the current path
791805 */
792806 public function closePath (): Void {
793807 if (pathSegments .length > 0 ) {
794- var segment = pathSegments [pathSegments .length - 1 ];
808+ var segmentIndex = pathSegments .length - 1 ;
809+ var segment = pathSegments [segmentIndex ];
795810 if (segment .length >= 4 ) {
796811 // Add line back to the start
797812 segment .push (segment [0 ]);
798813 segment .push (segment [1 ]);
814+ // Mark this segment as closed for loop rendering
815+ pathSegmentsClosed [segmentIndex ] = true ;
799816 }
800817 }
801818
0 commit comments