@daign/2d-graphics
Version:
Two dimensional graphics library that implements the daign-2d-pipeline.
45 lines (44 loc) • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RoundFollowingModifier = void 0;
/**
* Round following modifier.
* Round the points that follow the point of the original change request.
*/
var RoundFollowingModifier = /** @class */ (function () {
/**
* Constructor.
* @param precision - The number of decimal places to round to. Optional.
*/
function RoundFollowingModifier(precision) {
// Variable to temporarily disable the control modifier.
this.enabled = true;
this.precision = undefined;
if (precision) {
this.precision = precision;
}
}
/**
* 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.
*/
RoundFollowingModifier.prototype.modifyPoints = function (updatedPoints, pointIndex, _controlObject) {
var _this = this;
if (!this.enabled) {
return updatedPoints;
}
// Apply the same difference to all following points.
var modifiedPoints = updatedPoints.map(function (point, index) {
if (index > pointIndex) {
point.round(_this.precision);
}
return point;
});
return modifiedPoints;
};
return RoundFollowingModifier;
}());
exports.RoundFollowingModifier = RoundFollowingModifier;