Simple JavaScript library for working with angles.
npm install @fczbkk/angleSimple JavaScript library for working with angles.
Class representing an angle.
#### constructor
Create an angle.
Parameters
- config Object
- config.directions_start number Value with which first direction keyword will be associated.
- config.directions Array<string> List of direction keywords.
- $0 Object (optional, default {})
- $0.directions_start (optional, default default_directions_start)
- $0.directions (optional, default default_directions)
#### directions_start
#### directions
#### toDirection
Converts angle in degrees to direction keyword.
Parameters
- angle number
Examples
``javascript`
(new Angle()).toDirection(90); // --> 'top'
Returns string
#### fromDirection
Converts direction keyword to angle in degrees. Returns null if direction keyword is not defined.
Parameters
- direction string
Examples
`javascript`
(new Angle()).fromDirection('top'); // --> 90
Returns (number | null)
#### radToDeg
Convert angle from radians to degrees.
Parameters
- angle number
Examples
`javascript`
Array.radToDeg(Math.PI); // --> 180
Returns number
#### degToRad
Convert angle from degrees to radians.
Parameters
- angle number
Examples
`javascript`
Array.radToDeg(180); // --> Math.PI
Returns number
#### normalize
Converts angle in degrees into equal angle in range between 0 and 360.
Parameters
- angle number
Examples
`javascript``
Array.normalize(450); // --> 90
Returns number
If you found any bugs, if you have feature requests or any questions, please, either file an issue at GitHub or send me an e-mail at riki@fczbkk.com.
Angle is published under the MIT license.