@@ -480,6 +480,7 @@ class FreeDrawOutline extends Outline {
480480 this . #scaleFactor = scaleFactor ;
481481 this . #innerMargin = innerMargin ;
482482 this . #isLTR = isLTR ;
483+ this . firstPoint = [ NaN , NaN ] ;
483484 this . lastPoint = [ NaN , NaN ] ;
484485 this . #computeMinMax( isLTR ) ;
485486
@@ -560,9 +561,12 @@ class FreeDrawOutline extends Outline {
560561 let lastX = outline [ 4 ] ;
561562 let lastY = outline [ 5 ] ;
562563 const minMax = [ lastX , lastY , lastX , lastY ] ;
564+ let firstPointX = lastX ;
565+ let firstPointY = lastY ;
563566 let lastPointX = lastX ;
564567 let lastPointY = lastY ;
565568 const ltrCallback = isLTR ? Math . max : Math . min ;
569+ const bezierBbox = new Float32Array ( 4 ) ;
566570
567571 for ( let i = 6 , ii = outline . length ; i < ii ; i += 6 ) {
568572 const x = outline [ i + 4 ] ,
@@ -571,23 +575,47 @@ class FreeDrawOutline extends Outline {
571575 if ( isNaN ( outline [ i ] ) ) {
572576 Util . pointBoundingBox ( x , y , minMax ) ;
573577
578+ if ( firstPointY > y ) {
579+ firstPointX = x ;
580+ firstPointY = y ;
581+ } else if ( firstPointY === y ) {
582+ firstPointX = ltrCallback ( firstPointX , x ) ;
583+ }
574584 if ( lastPointY < y ) {
575585 lastPointX = x ;
576586 lastPointY = y ;
577587 } else if ( lastPointY === y ) {
578588 lastPointX = ltrCallback ( lastPointX , x ) ;
579589 }
580590 } else {
581- const bbox = [ Infinity , Infinity , - Infinity , - Infinity ] ;
582- Util . bezierBoundingBox ( lastX , lastY , ...outline . slice ( i , i + 6 ) , bbox ) ;
591+ bezierBbox [ 0 ] = bezierBbox [ 1 ] = Infinity ;
592+ bezierBbox [ 2 ] = bezierBbox [ 3 ] = - Infinity ;
593+ Util . bezierBoundingBox (
594+ lastX ,
595+ lastY ,
596+ ...outline . slice ( i , i + 6 ) ,
597+ bezierBbox
598+ ) ;
583599
584- Util . rectBoundingBox ( ...bbox , minMax ) ;
600+ Util . rectBoundingBox (
601+ bezierBbox [ 0 ] ,
602+ bezierBbox [ 1 ] ,
603+ bezierBbox [ 2 ] ,
604+ bezierBbox [ 3 ] ,
605+ minMax
606+ ) ;
585607
586- if ( lastPointY < bbox [ 3 ] ) {
587- lastPointX = bbox [ 2 ] ;
588- lastPointY = bbox [ 3 ] ;
589- } else if ( lastPointY === bbox [ 3 ] ) {
590- lastPointX = ltrCallback ( lastPointX , bbox [ 2 ] ) ;
608+ if ( firstPointY > bezierBbox [ 1 ] ) {
609+ firstPointX = bezierBbox [ 0 ] ;
610+ firstPointY = bezierBbox [ 1 ] ;
611+ } else if ( firstPointY === bezierBbox [ 1 ] ) {
612+ firstPointX = ltrCallback ( firstPointX , bezierBbox [ 0 ] ) ;
613+ }
614+ if ( lastPointY < bezierBbox [ 3 ] ) {
615+ lastPointX = bezierBbox [ 2 ] ;
616+ lastPointY = bezierBbox [ 3 ] ;
617+ } else if ( lastPointY === bezierBbox [ 3 ] ) {
618+ lastPointX = ltrCallback ( lastPointX , bezierBbox [ 2 ] ) ;
591619 }
592620 }
593621 lastX = x ;
@@ -599,6 +627,7 @@ class FreeDrawOutline extends Outline {
599627 bbox [ 1 ] = minMax [ 1 ] - this . #innerMargin;
600628 bbox [ 2 ] = minMax [ 2 ] - minMax [ 0 ] + 2 * this . #innerMargin;
601629 bbox [ 3 ] = minMax [ 3 ] - minMax [ 1 ] + 2 * this . #innerMargin;
630+ this . firstPoint = [ firstPointX , firstPointY ] ;
602631 this . lastPoint = [ lastPointX , lastPointY ] ;
603632 }
604633
0 commit comments