@tempots/std

nearEqualAngles() function

number numbers can sometime introduce tiny errors even for simple operations. nearEqualAngles compares two angles (default is 360deg) using a tiny tollerance (last optional argument). By default the tollerance is defined as EPSILON.

Signature:

nearEqualAngles: (a: number, b: number, turn?: number, tollerance?: number) => boolean

Parameters

Parameter

Type

Description

a

number

The first angle in degrees.

b

number

The second angle in degrees.

turn

number

(Optional) The total number of degrees in a full turn. Default is 360.0.

tollerance

number

(Optional) The tollerance value. Default is EPSILON.

Returns: boolean

true if the angles are very close, false otherwise.

Example

nearEqualAngles(0, 360) // returns true
nearEqualAngles(0, 361) // returns false
nearEqualAngles(0, 360.000000000001) // returns true
nearEqualAngles(0, 361, 360, 1) // returns true