@daign/2d-graphics
Version:
Two dimensional graphics library that implements the daign-2d-pipeline.
46 lines (45 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OrthogonalModifier = void 0;
/**
* Orthogonal modifier.
* The point has to be orthogonal to the previous point.
*/
var OrthogonalModifier = /** @class */ (function () {
/**
* Constructor.
*/
function OrthogonalModifier() {
// 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.
*/
OrthogonalModifier.prototype.modifyPoints = function (updatedPoints, pointIndex, _controlObject) {
if (!this.enabled) {
return updatedPoints;
}
// The first point can move freely. No change necessary.
if (pointIndex === 0) {
return updatedPoints;
}
var targetPoint = updatedPoints[pointIndex];
var previousPoint = updatedPoints[pointIndex - 1];
var diffHorizontal = Math.abs(targetPoint.x - previousPoint.x);
var diffVertical = Math.abs(targetPoint.y - previousPoint.y);
if (diffHorizontal > diffVertical) {
targetPoint.set(targetPoint.x, previousPoint.y);
}
else {
targetPoint.set(previousPoint.x, targetPoint.y);
}
return updatedPoints;
};
return OrthogonalModifier;
}());
exports.OrthogonalModifier = OrthogonalModifier;