Skip to content

Commit

Permalink
add appropriate pointType for unidirectional drag ( see #276)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Veillette <[email protected]>
  • Loading branch information
veillette committed Mar 17, 2023
1 parent 7813dda commit b4d3c08
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions js/common/model/TransformedCurve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,14 +587,6 @@ export default class TransformedCurve extends Curve {
// We want to create a straight line between this point and the last drag event point
const closestVector = closestPoint.getVector();
this.interpolate( closestVector.x, closestVector.y, lastPoint.x, penultimatePosition.y );

closestPoint.pointType = 'discontinuous';
if ( lastPoint.x > closestPoint.x ) {
this.getClosestPointAt( position.x - this.deltaX ).pointType = 'discontinuous';
}
else {
this.getClosestPointAt( position.x + this.deltaX ).pointType = 'discontinuous';
}
}
else {

Expand Down Expand Up @@ -667,11 +659,48 @@ export default class TransformedCurve extends Curve {
functionWeight += mollifierFunction( dx ) * piecewiseFunction.evaluate( x + dx );
}
this.getClosestPointAt( x ).y = functionWeight / weight;
this.getClosestPointAt( x ).pointType = 'smooth';
}
}
}
}

// assign type to points
if ( penultimatePosition ) {

const lastPoint = this.getClosestPointAt( penultimatePosition.x );

const lastPointIndex = this.getIndex( lastPoint );
const closestPointIndex = this.getIndex( closestPoint );

let min = Math.min( closestPointIndex, lastPointIndex );
let max = Math.max( closestPointIndex, lastPointIndex );
for ( let i = min; i <= max; i++ ) {
this.points[ i ].pointType = 'smooth';
}

if ( antepenultimatePosition ) {

// Point associated with the last drag event
const nextToLastPoint = this.getClosestPointAt( antepenultimatePosition.x );

const nextToLastPointIndex = this.getIndex( nextToLastPoint );

min = Math.min( closestPointIndex, nextToLastPointIndex );
max = Math.max( closestPointIndex, nextToLastPointIndex );

for ( let i = min; i <= max; i++ ) {
this.points[ i ].pointType = 'smooth';
}
}

closestPoint.pointType = 'discontinuous';
if ( lastPointIndex > closestPointIndex ) {
this.getClosestPointAt( closestPoint.x - this.deltaX ).pointType = 'discontinuous';
}
else if ( lastPointIndex < closestPointIndex ) {
this.getClosestPointAt( closestPoint.x + this.deltaX ).pointType = 'discontinuous';
}
}
}

/**
Expand Down

0 comments on commit b4d3c08

Please sign in to comment.