UNPKG

@game-vir/entity

Version:

Entity system for game development.

29 lines (28 loc) 1.01 kB
import { round } from '@augment-vir/common'; /** * An angle definition defined in either radians or degrees, with accessors for both radians and * degrees. Values are rounded according to the given `digits` option. An instance of this class is * readonly: to get updated values, construct a new instance. * * @category Math */ export class Angle { options; /** The angle's value expressed in radians. */ radians; /** The angle's value expressed in degrees. */ degrees; constructor( /** Original angle value, either in radians or degrees. */ originalValue, /** Angle options. Set to `undefined` to disable all options. */ options) { this.options = options; this.radians = round(originalValue.radians ?? (Math.PI * originalValue.degrees) / 180, { digits: options?.digits, }); this.degrees = round(originalValue.degrees ?? (originalValue.radians * 180) / Math.PI, { digits: options?.digits, }); } }