Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Angles.js is a collection of functions to work with angles. The aim is to have a fast and correct library, which can effortlessly convert between different units and can seamlessly work within different units. The result is a static library, which works on a configurable scale.
var angles = require('angles');
angles.SCALE = 360;
console.log(angles.normalize(365)); // 5
console.log(angles.normalize(-365)); // 355
Simply calculate the linear interpolation of the smaller angle.
var a = -30; // 330°
var b = 30;
var pct = 0.5; // Percentage between a and b
angles.SCALE = 360;
var dir = angles.shortestDirection(a, b); // -1 => Rotate CCW
console.log(angles.lerp(a, b, pct, dir)); // => 0
Having the scale configurable opens a lot of possibilities, like calculating clock-angles:
angles.SCALE = 60;
var time = new Date;
var s = time.getSeconds();
var m = time.getMinutes();
var h = time.getHours() / 23 * 59;
console.log(angles.between(s, m, h)); // true or false, if seconds clockhand is between the minutes and hours clockhand
Normalizes an angle to be in the interval [-180, 180), if SCALE
is 360 or [-π, π) if SCALE
is 2π.
Normalizes an angle to be in the interval [0, 360), if SCALE
is 360 or [0, 2π) if SCALE
is 2π.
Determines what the shortest rotation direction is to go from one angle to another. The result is positive if it's clock-wise.
Determines if an angle n
is between two other angles a, b
. The angles don't have to be normalized.
Calculates the angular difference between two angles
Calculates the linear interpolation of two angles
Calculate the minimal distance between two angles
Calculate radians from current angle (Unit 2PI)
Calculate degrees from current angle (Unit 360)
Calculate gons from current angle (Unit 400)
Calculates the angle given by two points (2 element arrays)
Calculates the original angle (in full resolution) based on the sine and co-sine of the angle.
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.
Translates the angle to a point of the compass ("N", "NE", "E", "SE", "S", "SW", "W", "NW"). If you want to want to have the major directions only, remove every second element from the array DIRECTIONS
.
Installing Angles.js is as easy as cloning this repo or use one of the following commands:
bower install angle
or
npm install --save angles
<script src="angles.js"></script>
<script>
console.log(Angles.normalize(128));
</script>
<script src="require.js"></script>
<script>
requirejs(['angles.js'],
function(Angles) {
console.log(Angles.normalize(128));
});
</script>
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.
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
npm test
Copyright (c) 2016, Robert Eisele (robert@xarg.org) Dual licensed under the MIT or GPL Version 2 licenses.
FAQs
A function collection for working with angles
We found that angles demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.