@@ -93,6 +93,10 @@ export class BaseSketcher2d {
9393 }
9494
9595 lineTo ( point : Point2D ) : this {
96+ if ( samePoint ( point , this . firstPoint ) ) {
97+ point = this . firstPoint
98+ }
99+
96100 const curve = make2dSegmentCurve (
97101 this . _convertToUV ( this . pointer ) ,
98102 this . _convertToUV ( point )
@@ -149,6 +153,10 @@ export class BaseSketcher2d {
149153 }
150154
151155 threePointsArcTo ( end : Point2D , midPoint : Point2D ) : this {
156+ if ( samePoint ( end , this . firstPoint ) ) {
157+ end = this . firstPoint
158+ }
159+
152160 this . saveCurve (
153161 make2dThreePointArc (
154162 this . _convertToUV ( this . pointer ) ,
@@ -174,6 +182,10 @@ export class BaseSketcher2d {
174182 }
175183
176184 sagittaArcTo ( end : Point2D , sagitta : number ) : this {
185+ if ( samePoint ( end , this . firstPoint ) ) {
186+ end = this . firstPoint
187+ }
188+
177189 const [ x0 , y0 ] = this . pointer ;
178190 const [ x1 , y1 ] = end ;
179191
@@ -216,6 +228,10 @@ export class BaseSketcher2d {
216228 }
217229
218230 bulgeArcTo ( end : Point2D , bulge : number ) : this {
231+ if ( samePoint ( end , this . firstPoint ) ) {
232+ end = this . firstPoint
233+ }
234+
219235 if ( ! bulge ) return this . lineTo ( end ) ;
220236 const halfChord = distance2d ( this . pointer , end ) / 2 ;
221237 const bulgeAsSagitta = - bulge * halfChord ;
@@ -239,6 +255,10 @@ export class BaseSketcher2d {
239255 }
240256
241257 tangentArcTo ( end : Point2D ) : this {
258+ if ( samePoint ( end , this . firstPoint ) ) {
259+ end = this . firstPoint
260+ }
261+
242262 const previousCurve = this . pendingCurves . length
243263 ? this . pendingCurves [ this . pendingCurves . length - 1 ]
244264 : null ;
@@ -271,6 +291,10 @@ export class BaseSketcher2d {
271291 longAxis = false ,
272292 sweep = false
273293 ) : this {
294+ if ( samePoint ( end , this . firstPoint ) ) {
295+ end = this . firstPoint
296+ }
297+
274298 let rotationAngle = rotation ;
275299 let majorRadius = horizontalRadius ;
276300 let minorRadius = verticalRadius ;
@@ -376,6 +400,10 @@ export class BaseSketcher2d {
376400 }
377401
378402 bezierCurveTo ( end : Point2D , controlPoints : Point2D | Point2D [ ] ) : this {
403+ if ( samePoint ( end , this . firstPoint ) ) {
404+ end = this . firstPoint
405+ }
406+
379407 let cp : Point2D [ ] ;
380408 if ( controlPoints . length === 2 && ! Array . isArray ( controlPoints [ 0 ] ) ) {
381409 cp = [ controlPoints as Point2D ] ;
@@ -408,6 +436,10 @@ export class BaseSketcher2d {
408436 }
409437
410438 smoothSplineTo ( end : Point2D , config ?: SplineConfig ) : this {
439+ if ( samePoint ( end , this . firstPoint ) ) {
440+ end = this . firstPoint
441+ }
442+
411443 const { endTangent, startTangent, startFactor, endFactor } =
412444 defaultsSplineConfig ( config ) ;
413445
0 commit comments