path-generator
Version:
A easy motion profile path generator
52 lines (51 loc) • 1.35 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.deepCopy = exports.copy = exports.distance2Angle = exports.angle2Distance = exports.r2d = exports.d2r = exports.boundRadians = void 0;
function fmod(num1, num2) {
return num1 - Math.floor(num1 / num2) * num2;
}
function boundRadians(angle) {
var newAngle = fmod(angle, Math.PI * 2);
if (newAngle < 0)
newAngle = Math.PI * 2 + newAngle;
return newAngle;
}
exports.boundRadians = boundRadians;
/**
* @param angle in degrees
* @returns angle in radians
*/
function d2r(angle) {
return (angle * Math.PI) / 180;
}
exports.d2r = d2r;
/**
* @param angle in radians
* @returns angle in degrees
*/
function r2d(angle) {
return (angle * 180) / Math.PI;
}
exports.r2d = r2d;
/**
* @param angle In degrees
*/
function angle2Distance(angle, width) {
return (width / 2) * d2r(angle);
}
exports.angle2Distance = angle2Distance;
/**
* @returns Angle in degrees
*/
function distance2Angle(distance, width) {
return r2d((distance / width) * 2);
}
exports.distance2Angle = distance2Angle;
function copy(type, objects) {
return objects.map(function (object) { return Object.assign(new type(), object); });
}
exports.copy = copy;
function deepCopy(value) {
return JSON.parse(JSON.stringify(value));
}
exports.deepCopy = deepCopy;
;