From c08230b4d17d7fa79ec5441300b9f9e722abd268 Mon Sep 17 00:00:00 2001 From: Martin Veillette Date: Fri, 17 Mar 2023 17:50:01 -0400 Subject: [PATCH] tagged last point when turning around ( see #276) Signed-off-by: Martin Veillette --- js/common/model/TransformedCurve.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/js/common/model/TransformedCurve.ts b/js/common/model/TransformedCurve.ts index 0a27c5cc..55583f35 100644 --- a/js/common/model/TransformedCurve.ts +++ b/js/common/model/TransformedCurve.ts @@ -667,7 +667,7 @@ export default class TransformedCurve extends Curve { // Main idea: assign the smooth type to ALL points between penultimatePosition to position ( // and possibly antepenultimatePosition if it exists), then come back to it by reassigning the - // closestPoint (and the its point partner ahead of the drag) to be discontinuous. + // closestPoint (and its point partner ahead of the drag) to be discontinuous. // if ( penultimatePosition ) { @@ -693,7 +693,10 @@ export default class TransformedCurve extends Curve { max = Math.max( lastPointIndex, nextToLastPointIndex ); for ( let i = min; i <= max; i++ ) { - this.points[ i ].pointType = 'smooth'; + const point = this.points[ i ]; + if ( point !== nextToLastPoint ) { + this.points[ i ].pointType = 'smooth'; + } } } @@ -707,6 +710,22 @@ export default class TransformedCurve extends Curve { else if ( lastPointIndex < closestPointIndex ) { this.getClosestPointAt( closestPoint.x + this.deltaX ).pointType = 'discontinuous'; } + + // We need to consider the case where the drag has turned + if ( antepenultimatePosition ) { + // Point associated with the last drag event + const nextToLastPoint = this.getClosestPointAt( antepenultimatePosition.x ); + if ( ( closestPoint.x - lastPoint.x ) * ( nextToLastPoint.x - lastPoint.x ) > 0 ) { + lastPoint.pointType = 'discontinuous'; + if ( lastPointIndex > closestPointIndex ) { + + this.getClosestPointAt( lastPoint.x - this.deltaX ).pointType = 'discontinuous'; + } + else if ( lastPointIndex < closestPointIndex ) { + this.getClosestPointAt( lastPoint.x + this.deltaX ).pointType = 'discontinuous'; + } + } + } } }