@daign/2d-graphics
Version:
Two dimensional graphics library that implements the daign-2d-pipeline.
46 lines (45 loc) • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FollowAlongModifier = void 0;
/**
* Follow along modifier.
* The movement of the specified point is applied to all following points also.
*/
var FollowAlongModifier = /** @class */ (function () {
/**
* Constructor.
*/
function FollowAlongModifier() {
// Variable to temporarily disable the control modifier.
this.enabled = true;
}
/**
* Modify the position change that has been requested for a control object.
* @param updatedPoints - The array of updated points.
* @param pointIndex - The index of the point that initiated the change.
* @param controlObject - The corresponding control object.
* @returns The modified array of points.
*/
FollowAlongModifier.prototype.modifyPoints = function (updatedPoints, pointIndex, controlObject) {
if (!this.enabled) {
return updatedPoints;
}
var pointBefore = controlObject.points.getElement(pointIndex);
var pointAfter = updatedPoints[pointIndex];
if (pointBefore) {
// Difference between old and new position.
var diff_1 = pointAfter.clone().sub(pointBefore);
// Apply the same difference to all following points.
var modifiedPoints = updatedPoints.map(function (point, index) {
if (index > pointIndex) {
point.add(diff_1);
}
return point;
});
return modifiedPoints;
}
return updatedPoints;
};
return FollowAlongModifier;
}());
exports.FollowAlongModifier = FollowAlongModifier;