Comparing version 0.2.4 to 0.3.0
{ | ||
"name": "angles", | ||
"title": "angles.js", | ||
"version": "0.2.4", | ||
"homepage": "https://github.com/infusion/Angles.js", | ||
"bugs": "https://github.com/infusion/Angles.js/issues", | ||
"title": "Angles.js", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/rawify/Angles.js", | ||
"bugs": "https://github.com/rawify/Angles.js/issues", | ||
"description": "A function collection for working with angles", | ||
@@ -22,25 +22,48 @@ "keywords": [ | ||
"angular", | ||
"average", | ||
"mean", | ||
"between" | ||
], | ||
"author": "Robert Eisele <robert@xarg.org> (http://www.xarg.org/)", | ||
"main": "angles", | ||
"private": false, | ||
"main": "./dist/angles.js", | ||
"module": "./dist/angles.mjs", | ||
"types": "./angles.d.ts", | ||
"browser": "./dist/angles.min.js", | ||
"unpkg": "./dist/angles.min.js", | ||
"readmeFilename": "README.md", | ||
"license": "MIT OR GPL-2.0", | ||
"exports": { | ||
".": { | ||
"types": "./angles.d.ts", | ||
"require": "./dist/angles.js", | ||
"import": "./dist/angles.mjs" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/infusion/Angles.js.git" | ||
"url": "git@github.com:rawify/Angles.js.git" | ||
}, | ||
"funding": { | ||
"type": "github", | ||
"url": "https://github.com/sponsors/rawify" | ||
}, | ||
"author": { | ||
"name": "Robert Eisele", | ||
"email": "robert@raw.org", | ||
"url": "https://raw.org/" | ||
}, | ||
"license": "MIT", | ||
"engines": { | ||
"node": "*" | ||
}, | ||
"directories": { | ||
"test": "tests" | ||
}, | ||
"scripts": { | ||
"build": "crude-build Angles", | ||
"test": "mocha tests/*.js" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*", | ||
"gulp": "*", | ||
"google-closure-compiler": "*" | ||
"crude-build": "^0.1.0", | ||
"mocha": "*" | ||
} | ||
} | ||
} |
123
README.md
# Angles.js | ||
[![NPM Package](https://img.shields.io/npm/v/angles.svg?style=flat)](https://npmjs.org/package/angles "View this project on npm") | ||
[![Build Status](https://travis-ci.org/infusion/Angles.js.svg)](https://travis-ci.org/infusion/Angles.js) | ||
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT) | ||
@@ -10,4 +9,3 @@ | ||
Examples | ||
=== | ||
## Examples | ||
@@ -33,4 +31,2 @@ ```javascript | ||
console.log(angles.lerp(a, b, pct, dir)); // => 0 | ||
``` | ||
@@ -50,69 +46,63 @@ | ||
Functions | ||
=== | ||
## Functions | ||
normalizeHalf(n) | ||
--- | ||
### normalizeHalf(n) | ||
Normalizes an angle to be in the interval [-180, 180), if `SCALE` is 360 or [-π, π) if `SCALE` is 2π. | ||
normalize(n) | ||
--- | ||
### normalize(n) | ||
Normalizes an angle to be in the interval [0, 360), if `SCALE` is 360 or [0, 2π) if `SCALE` is 2π. | ||
shortestDirection(from, to) | ||
--- | ||
### shortestDirection(from, to) | ||
Determines what the shortest rotation direction is to go from one angle to another. The result is positive if it's clock-wise. | ||
between(n, a, b) | ||
--- | ||
### between(n, a, b) | ||
Determines if an angle `n` is between two other angles `a, b`. The angles don't have to be normalized. | ||
diff(a, b) | ||
--- | ||
### diff(a, b) | ||
Calculates the angular difference between two angles | ||
lerp(a, b, p[, dir=-1]) | ||
--- | ||
### lerp(a, b, p[, dir=-1]) | ||
Calculates the linear interpolation of two angles | ||
distance(a, b) | ||
--- | ||
### distance(a, b) | ||
Calculate the minimal distance between two angles | ||
toRad(n) | ||
--- | ||
### toRad(n) | ||
Calculate radians from current angle (Unit 2PI) | ||
toDeg(n) | ||
--- | ||
### toDeg(n) | ||
Calculate degrees from current angle (Unit 360) | ||
toGon(n) | ||
--- | ||
### toGon(n) | ||
Calculate gons from current angle (Unit 400) | ||
fromSlope(p1, p2) | ||
--- | ||
### fromSlope(p1, p2) | ||
Calculates the angle between the x-axis and the line formed by two points. | ||
fromSinCos(sin, cos) | ||
--- | ||
### fromSinCos(sin, cos) | ||
Calculates the original angle (in full resolution) based on the sine and co-sine of the angle. | ||
quadrant(x, y[k=4[, shift=0]]) | ||
--- | ||
### quadrant(x, y[k=4[, shift=0]]) | ||
Calculates the quadrant (with `k=4`, or octant with `k=8`) in which a point with coordinates `x,y` falls. Optionally, the coordinate system can be rotated with the `shift` parameter, which follows the `SCALE`-attribute. A positive value rotates counter-clockwise. | ||
compass(angle) | ||
--- | ||
### compass(angle) | ||
Translates the angle to a point of the compass ("N", "NE", "E", "SE", "S", "SW", "W", "NW") in the normal windrose way (N=0, E=90, S=180, W=270). If you want to want to have the major directions only, remove every second element from the array `DIRECTIONS`. | ||
Installation | ||
=== | ||
Installing Angles.js is as easy as cloning this repo or use one of the following commands: | ||
## Installation | ||
``` | ||
bower install angle | ||
``` | ||
or | ||
Installing Angles.js is as easy as cloning this repo or use one of the following command: | ||
@@ -124,38 +114,37 @@ ``` | ||
Using Angles.js with the browser | ||
=== | ||
```html | ||
<script src="angles.js"></script> | ||
<script> | ||
console.log(Angles.normalize(128)); | ||
</script> | ||
``` | ||
## Using Angles.js with the browser | ||
Using Angles.js with require.js | ||
=== | ||
```html | ||
<script src="require.js"></script> | ||
<script src="angles.min.js"></script> | ||
<script> | ||
requirejs(['angles.js'], | ||
function(Angles) { | ||
console.log(Angles.normalize(128)); | ||
}); | ||
console.log(Angles.normalize(128)); | ||
</script> | ||
``` | ||
Coding Style | ||
=== | ||
## Coding Style | ||
As every library I publish, Angles.js is also built to be as small as possible after compressing it with Google Closure Compiler in advanced mode. Thus the coding style orientates a little on maxing-out the compression rate. Please make sure you keep this style if you plan to extend the library. | ||
Testing | ||
=== | ||
If you plan to enhance the library, make sure you add test cases and all the previous tests are passing. You can test the library with | ||
## Building the library | ||
After cloning the Git repository run: | ||
``` | ||
npm test | ||
npm install | ||
npm run build | ||
``` | ||
Copyright and licensing | ||
=== | ||
Copyright (c) 2016, [Robert Eisele](http://www.xarg.org/) | ||
Dual licensed under the MIT or GPL Version 2 licenses. | ||
## Run a test | ||
Testing the source against the shipped test suite is as easy as | ||
``` | ||
npm run test | ||
``` | ||
## Copyright and Licensing | ||
Copyright (c) 2024, [Robert Eisele](https://raw.org/) | ||
Licensed under the MIT license. |
var should = require('should'); | ||
var angles = require('../angles.js'); | ||
var assert = require("assert"); | ||
var angles = require('angles'); | ||
var tests = [ | ||
{m: 'between', p: [38, 13, 45], r: true, s: 360}, | ||
{m: 'between', p: [38, 40, 45], r: false, s: 360}, | ||
{m: 'between', p: [12, 5, 18], r: true, s: 60}, | ||
{m: 'between', p: [15, 2, 18], r: true, s: 12}, | ||
{m: 'between', p: [38 + 360 * 3, 13 - 360 * 2, 45 + 360], r: true, s: 360}, | ||
{m: 'toRad', p: [90], r: Math.PI / 2, s: 360}, | ||
{m: 'toDeg', p: [Math.PI], r: 180, s: Math.PI * 2}, | ||
{m: 'toRad', p: [180], r: Math.PI, s: 360}, | ||
{m: 'toDeg', p: [Math.PI], r: 180, s: Math.PI * 2}, | ||
{m: 'distance', p: [1, 359], r: 2, s: 360}, | ||
{m: 'distance', p: [358, 1], r: 3, s: 360}, | ||
{m: 'distance', p: [18, 25], r: 7, s: 360}, | ||
{m: 'distance', p: [1, 359], r: 2, s: 360}, | ||
{m: 'normalize', p: [55], r: 55, s: 360}, | ||
{m: 'normalize', p: [55 + 360], r: 55, s: 360}, | ||
{m: 'normalize', p: [-55], r: 305, s: 360}, | ||
{m: 'normalize', p: [-190], r: 170, s: 360}, | ||
{m: 'normalizeHalf', p: [55], r: 55, s: 360}, | ||
{m: 'normalizeHalf', p: [55 + 360], r: 55, s: 360}, | ||
{m: 'normalizeHalf', p: [-55], r: -55, s: 360}, | ||
{m: 'normalizeHalf', p: [-190], r: 170, s: 360}, | ||
{m: 'fromSlope', p: [[1, 1], [5, 10]], r: 66.03751102542182, s: 360}, | ||
{m: 'fromSlope', p: [[124, 8984], [234, 10322]], r: 85.30015415271286, s: 360}, | ||
{m: 'fromSlope', p: [[424, 8984], [234, 10322]], r: 98.08213603676147, s: 360}, | ||
{m: 'fromSlope', p: [[345, -78445], [3475890, 8495]], r: 1.4329425927144732, s: 360}, | ||
{m: 'shortestDirection', p: [50, 60], r: -1, s: 360}, | ||
{m: 'shortestDirection', p: [60, 50], r: 1, s: 360}, | ||
{m: 'shortestDirection', p: [50, 50], r: 0, s: 360}, | ||
{m: 'shortestDirection', p: [60 + 360 * 3, 50 + 360 * 7], r: 1, s: 360}, | ||
{m: 'shortestDirection', p: [60 - 360 * 3, 50 - 360 * 7], r: 1, s: 360}, | ||
{m: 'fromSinCos', p: [Math.sin(0.3), Math.cos(0.3)], r: 0.3, s: Math.PI * 2}, | ||
{m: 'fromSinCos', p: [Math.sin(-0.3), Math.cos(-0.3)], r: Math.PI * 2 - 0.3, s: Math.PI * 2}, | ||
{m: 'fromSinCos', p: [Math.sin(0.7), Math.cos(0.7)], r: 0.7, s: Math.PI * 2}, | ||
{m: 'fromSinCos', p: [Math.sin(-0.7), Math.cos(-0.7)], r: Math.PI * 2 - 0.7, s: Math.PI * 2}, | ||
{m: 'lerp', p: [45, 135, 0.4, -1], r: 81, s: 360}, | ||
{m: 'lerp', p: [0, Math.PI * 2, 0.5], r: 0, s: Math.PI * 2}, | ||
{m: 'lerp', p: [0, Math.PI, 0.5, -1], r: Math.PI * 0.5, s: Math.PI * 2}, | ||
{m: 'lerp', p: [45, 360 + 315, 0.5, -1], r: 180, s: 360}, | ||
{m: 'lerp', p: [45, 360 + 315, 0.5, 1], r: 0, s: 360}, | ||
{m: 'lerp', p: [45, 360 + 315, 0, -1], r: 45, s: 360}, | ||
{m: 'lerp', p: [45, 360 + 315, 1, -1], r: 315, s: 360}, | ||
{m: 'lerp', p: [30, 90, 0.25, -1], r: 45, s: 360}, | ||
{m: 'lerp', p: [30, 90, 0.25, 1], r: 315, s: 360}, | ||
{m: 'lerp', p: [300, 60, 0.25, -1], r: 330, s: 360}, | ||
{m: 'lerp', p: [300, 60, 0.25, 1], r: 240, s: 360}, | ||
{m: 'lerp', p: [-30, 30, 0.5, -1], r: 0, s: 360}, | ||
{m: 'lerp', p: [-30, 30, 0.5, 1], r: 180, s: 360}, | ||
{m: 'lerp', p: [-30, 30, 0.25, -1], r: 345, s: 360}, | ||
{m: 'lerp', p: [-30, 30, 0.25, 1], r: 255, s: 360}, | ||
{m: 'lerp', p: [10, 10, 0.5, -1], r: 10, s: 360}, | ||
{m: 'lerp', p: [10, 10, 0.5, 1], r: 10, s: 360}, | ||
{ m: 'between', p: [38, 13, 45], r: true, s: 360 }, | ||
{ m: 'between', p: [38, 40, 45], r: false, s: 360 }, | ||
{ m: 'between', p: [12, 5, 18], r: true, s: 60 }, | ||
{ m: 'between', p: [15, 2, 18], r: true, s: 12 }, | ||
{ m: 'between', p: [38 + 360 * 3, 13 - 360 * 2, 45 + 360], r: true, s: 360 }, | ||
{ m: 'toRad', p: [90], r: Math.PI / 2, s: 360 }, | ||
{ m: 'toDeg', p: [Math.PI], r: 180, s: Math.PI * 2 }, | ||
{ m: 'toRad', p: [180], r: Math.PI, s: 360 }, | ||
{ m: 'toDeg', p: [Math.PI], r: 180, s: Math.PI * 2 }, | ||
{ m: 'distance', p: [1, 359], r: 2, s: 360 }, | ||
{ m: 'distance', p: [358, 1], r: 3, s: 360 }, | ||
{ m: 'distance', p: [18, 25], r: 7, s: 360 }, | ||
{ m: 'distance', p: [1, 359], r: 2, s: 360 }, | ||
{ m: 'normalize', p: [55], r: 55, s: 360 }, | ||
{ m: 'normalize', p: [55 + 360], r: 55, s: 360 }, | ||
{ m: 'normalize', p: [-55], r: 305, s: 360 }, | ||
{ m: 'normalize', p: [-190], r: 170, s: 360 }, | ||
{ m: 'normalizeHalf', p: [55], r: 55, s: 360 }, | ||
{ m: 'normalizeHalf', p: [55 + 360], r: 55, s: 360 }, | ||
{ m: 'normalizeHalf', p: [-55], r: -55, s: 360 }, | ||
{ m: 'normalizeHalf', p: [-190], r: 170, s: 360 }, | ||
{ m: 'fromSlope', p: [[1, 1], [5, 10]], r: 66.03751102542182, s: 360 }, | ||
{ m: 'fromSlope', p: [[124, 8984], [234, 10322]], r: 85.30015415271286, s: 360 }, | ||
{ m: 'fromSlope', p: [[424, 8984], [234, 10322]], r: 98.08213603676147, s: 360 }, | ||
{ m: 'fromSlope', p: [[345, -78445], [3475890, 8495]], r: 1.4329425927144732, s: 360 }, | ||
{ m: 'shortestDirection', p: [50, 60], r: -1, s: 360 }, | ||
{ m: 'shortestDirection', p: [60, 50], r: 1, s: 360 }, | ||
{ m: 'shortestDirection', p: [50, 50], r: 0, s: 360 }, | ||
{ m: 'shortestDirection', p: [60 + 360 * 3, 50 + 360 * 7], r: 1, s: 360 }, | ||
{ m: 'shortestDirection', p: [60 - 360 * 3, 50 - 360 * 7], r: 1, s: 360 }, | ||
{ m: 'fromSinCos', p: [Math.sin(0.3), Math.cos(0.3)], r: 0.3, s: Math.PI * 2 }, | ||
{ m: 'fromSinCos', p: [Math.sin(-0.3), Math.cos(-0.3)], r: Math.PI * 2 - 0.3, s: Math.PI * 2 }, | ||
{ m: 'fromSinCos', p: [Math.sin(0.7), Math.cos(0.7)], r: 0.7, s: Math.PI * 2 }, | ||
{ m: 'fromSinCos', p: [Math.sin(-0.7), Math.cos(-0.7)], r: Math.PI * 2 - 0.7, s: Math.PI * 2 }, | ||
{ m: 'lerp', p: [45, 135, 0.4, -1], r: 81, s: 360 }, | ||
{ m: 'lerp', p: [0, Math.PI * 2, 0.5], r: 0, s: Math.PI * 2 }, | ||
{ m: 'lerp', p: [0, Math.PI, 0.5, -1], r: Math.PI * 0.5, s: Math.PI * 2 }, | ||
{ m: 'lerp', p: [45, 360 + 315, 0.5, -1], r: 180, s: 360 }, | ||
{ m: 'lerp', p: [45, 360 + 315, 0.5, 1], r: 0, s: 360 }, | ||
{ m: 'lerp', p: [45, 360 + 315, 0, -1], r: 45, s: 360 }, | ||
{ m: 'lerp', p: [45, 360 + 315, 1, -1], r: 315, s: 360 }, | ||
{ m: 'lerp', p: [30, 90, 0.25, -1], r: 45, s: 360 }, | ||
{ m: 'lerp', p: [30, 90, 0.25, 1], r: 315, s: 360 }, | ||
{ m: 'lerp', p: [300, 60, 0.25, -1], r: 330, s: 360 }, | ||
{ m: 'lerp', p: [300, 60, 0.25, 1], r: 240, s: 360 }, | ||
{ m: 'lerp', p: [-30, 30, 0.5, -1], r: 0, s: 360 }, | ||
{ m: 'lerp', p: [-30, 30, 0.5, 1], r: 180, s: 360 }, | ||
{ m: 'lerp', p: [-30, 30, 0.25, -1], r: 345, s: 360 }, | ||
{ m: 'lerp', p: [-30, 30, 0.25, 1], r: 255, s: 360 }, | ||
{ m: 'lerp', p: [10, 10, 0.5, -1], r: 10, s: 360 }, | ||
{ m: 'lerp', p: [10, 10, 0.5, 1], r: 10, s: 360 }, | ||
]; | ||
@@ -92,17 +92,19 @@ | ||
tests.push({m: 'quadrant', p: [ | ||
tests.push({ | ||
m: 'quadrant', p: [ | ||
Math.cos(i / 180 * Math.PI), | ||
Math.sin(i / 180 * Math.PI) | ||
], r: kl, s: 360, label: 'Quadrant of angle ' + i}); | ||
], r: kl, s: 360, label: 'Quadrant of angle ' + i | ||
}); | ||
tests.push({m: 'compass', p: [i], r: dir, s: 360, label: 'Direction of angle ' + i}); | ||
tests.push({ m: 'compass', p: [i], r: dir, s: 360, label: 'Direction of angle ' + i }); | ||
} | ||
describe('Angles', function() { | ||
describe('Angles', function () { | ||
for (var i = 0; i < tests.length; i++) { | ||
(function(i) { | ||
(function (i) { | ||
it('Should work with ' + (tests[i].label || "->" + tests[i].m + "(" + tests[i].p.join(", ") + ")"), function() { | ||
it('Should work with ' + (tests[i].label || "->" + tests[i].m + "(" + tests[i].p.join(", ") + ")"), function () { | ||
@@ -112,5 +114,5 @@ var c = tests[i]; | ||
if (typeof c.r !== 'number') | ||
angles[c.m].apply(angles, c.p).should.be.equal(c.r); | ||
assert.equal(angles[c.m].apply(angles, c.p), c.r) | ||
else | ||
angles[c.m].apply(angles, c.p).should.be.approximately(c.r, 1e-15); | ||
assert(Math.abs(angles[c.m].apply(angles, c.p) - c.r) < 1e-14) | ||
}); | ||
@@ -121,1 +123,2 @@ | ||
}); | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
37543
2
0
100
1013
9
147
1