npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

degree-circle

v1.0.0

Published

A small library for comparing and performing operations on 0-360 degree values

Downloads

3

Readme

degree-circle

A small library for comparing and performing operations on 0-360 degree values

Description

This library can be used for comparing angles in degrees to see which comes before/after which, whether they are equal or whether they are opposite. Addition, subtraction, multiplication, division and modulus division (remainder) are also possible, with results in the 0-360 range no matter how large the inputs nor whether they are positive or negative. Division by zero may cause unexpected results.

Angle comparison works even when the shortest distance around the circle between each angle crosses the zero line. IE 350º still comes before 5º. The transition point is where the two angles are opposite, thus: 180 degrees apart. Technically, opposite angles are neither before nor after each other, but there are methods which will include opposite angles, as well as equal angles, similar to the '>=' and '<=' operators.

Usage

npm i degree-circle

const angle = require('degree-circle')

console.log(angle(5).isBefore(7)) // => true
console.log(angle(359).isBefore(0)) // => true (Crosses 360/0 boundary)

console.log(angle(0).isEqualTo(360)) // => true
console.log(angle(355).isEqualTo(-5)) // => true

console.log(angle(0).isBefore(360)) // => false (Same)
console.log(angle(0).isBeforeOrEqualTo(360)) // => true

console.log(angle(-90).isBeforeOppositeOrEqualTo(270)) // => true (Equal)
console.log(angle(-90).isBeforeOppositeOrEqualTo(90)) // => true (Opposite)
console.log(angle(-90).isBeforeOppositeOrEqualTo(30)) // => true (Before)

API

The API is rather simple. First:

const angle = require('degree-circle')

Then call angle(a) with your first angle in degrees. Next call one of the following:

Operations

add(b: number): number

add b to a and return the result on the degree-circle (0 <= n < 360)

  • @param {number} b a value in degrees (any number)
  • @returns {number} a + b: (0 <= n < 360)

subtract(b: number): number

subtract b from a and return the result on the degree-circle (0 <= n < 360)

  • @param {number} b a value in degrees
  • @returns {number} a - b: (0 <= n < 360)

multiply(b: number): number

multiply b with a and return the result on the degree-circle (0 <= n < 360)

  • @param {number} b a value in degrees
  • @returns {number} a * b: (0 <= n < 360)

divide(b: number): number

divide a by b and return the result on the degree-circle (0 <= n < 360)

  • @param {number} b a value in degrees
  • @returns {number} a / b: (0 <= n < 360)

modulo(b: number): number

divide a by b and return the remainder on the degree-circle (0 <= n < 360)

  • @param {number} b a value in degrees
  • @returns {number} a % b: (0 <= n < 360)

Comparisons

isEqualTo(b: number): boolean

compare b to a and return whether the two angles are equal

  • @param {number} b a value in degrees
  • @returns {boolean} a === b where a and b have been normalized to (0 <= n < 360)

isOpposite(b: number): boolean

compare b to a and return whether the two angles are opposite (180º out of phase)

  • @param {number} b a value in degrees
  • @returns {boolean} a === b ± 180 where a and b have been normalized to (0 <= n < 360)

isBefore(b: number): boolean

compare b to a and return whether a comes before b on the circle

  • @param {number} b a value in degrees
  • @returns {boolean} a < b where a and b have been normalized to (0 <= n < 360)
  • @description
  • an angle is before another angle if:
    • the angle has a lesser degree-value (Normalized for zero-crossing)
    • the difference between the two angles is not zero
    • the difference between the two angles is not 180 exactly

isAfter(b: number): boolean

compare b to a and return whether a comes after b on the circle

  • @param {number} b a value in degrees
  • @returns {boolean} a > b where a and b have been normalized to (0 <= n < 360)
  • @description
  • an angle is after another angle if:
    • the angle has a greater degree-value (Normalized for zero-crossing)
    • the difference between the two angles is not zero
    • the difference between the two angles is not 180 exactly

isBeforeOrEqualTo(b: number): boolean

compare b to a and return whether a comes on or before b on the circle

  • @param {number} b a value in degrees
  • @returns {boolean} a <= b where a and b have been normalized to (0 <= n < 360)

isAfterOrEqualTo(b: number): boolean

compare b to a and return whether a comes on or after b on the circle

  • @param {number} b a value in degrees
  • @returns {boolean} a >= b where a and b have been normalized to (0 <= n < 360)

isBeforeOrOpposite(b: number): boolean

compare b to a and return whether a comes before b on the circle, including exactly opposite

  • @param {number} b a value in degrees
  • @returns {boolean} a < b or abs(a - b) === 180 where a and b have been normalized to (0 <= n < 360)

isAfterOrOpposite(b: number): boolean

compare b to a and return whether a comes after b on the circle, including exactly opposite

  • @param {number} b a value in degrees
  • @returns {boolean} a > b or abs(a - b) === 180 where a and b have been normalized to (0 <= n < 360)

isBeforeOppositeOrEqual(b: number): boolean

compare b to a and return whether a comes on or before b, or exactly opposite to b, on the circle

  • @param {number} b a value in degrees
  • @returns {boolean} a <= b or abs(a - b) === 180 where a and b have been normalized to (0 <= n < 360)

isAfterOppositeOrEqual(b: number): boolean

compare b to a and return whether a comes on or after b, or exactly opposite to b, on the circle

  • @param {number} b a value in degrees
  • @returns {boolean} a >= b or abs(a - b) === 180 where a and b have been normalized to (0 <= n < 360)