UNPKG

@technobuddha/library

Version:
38 lines (37 loc) 1.39 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.angleDifference = void 0; var normalizeAngle_1 = __importDefault(require("../normalizeAngle")); /** * Computes the difference between startAngle and endAngle (angles in radians). * * @param startAngle Start angle in radians. * @param endAngle End angle in radians. * @returns The number of radians that when added to *startAngle* will result in *endAngle*. * * @remarks * Positive numbers mean that the * direction is clockwise. Negative numbers indicate a counter-clockwise direction. * The shortest route (clockwise vs counter-clockwise) between the angles is used. * When the difference is PI radians, the function returns PI (not -PI) * * @example * angleDifference(PI * 1/6, PI * 2/6) is PI * 1/6 * * angleDifference(PI * 2/6, PI * 1/6) is -PI * 1/6. * * angleDifference(PI * 11/6, PI * 1/6) is PI * 2/6 * * angleDifference(PI * 1/6, PI * 11/6) is -PI * 1/6. */ function angleDifference(startAngle, endAngle) { var d = normalizeAngle_1.default(endAngle) - normalizeAngle_1.default(startAngle); if (d > Math.PI) d -= Math.PI * 2; return d; } exports.angleDifference = angleDifference; exports.default = angleDifference;