UNPKG

@pilotlab/lux-types

Version:

A luxurious user experience framework, developed by your friends at Pilot.

56 lines (38 loc) 2.06 kB
import is from '@pilotlab/lux-is'; import { DataType, IAttribute, Attribute, AttributeCollection, AttributeChangeOptions } from '@pilotlab/lux-attributes'; import IPoint3D from './interfaces/IPoint3D'; export abstract class PointBase<TNode extends IAttribute> extends Attribute<AttributeCollection> implements IPoint3D { constructor(type:string, x?:number, y?:number, z?:number) { super(type, null, DataType.COLLECTION, null, false); this.p_x = this.children.set('x', is.notEmpty(x) ? x : 0, DataType.NUMBER_DOUBLE, AttributeChangeOptions.zero).node; this.p_y = this.children.set('y', is.notEmpty(y) ? y : 0, DataType.NUMBER_DOUBLE, AttributeChangeOptions.zero).node; this.p_z = this.children.set('z', is.notEmpty(z) ? z : 0, DataType.NUMBER_DOUBLE, AttributeChangeOptions.zero).node; } get x():number { return this.p_x.value; } set x(value:number) { this.p_x.set(value, AttributeChangeOptions.saveAndSignal.durationZero); } protected p_x:IAttribute; get y():number { return this.p_y.value; } set y(value:number) { this.p_y.set(value, AttributeChangeOptions.saveAndSignal.durationZero); } protected p_y:IAttribute; get z():number { return this.p_z.value; } set z(value:number) { this.p_z.set(value, AttributeChangeOptions.saveAndSignal.durationZero); } protected p_z:IAttribute; get isEmpty():boolean { return is.empty(this.x) || is.empty(this.y) || is.empty(this.z); } /*====================================================================* START: Public Methods *====================================================================*/ /** * Get the distance between two coordinates */ distance(point:PointBase<any>):number { let e:number = 0.0; let d:number = 0.0; for (let i:number = 0; i < 3; i++) { d = (this.children.list.item(i).value - point.children.list.item(i).value); e += d * d; } return Math.sqrt(e); } } // End of class export default PointBase;