-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
183 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { LengthUnit } from '../../utils'; | ||
import { Vector2, Vector3 } from '../../utils/math'; | ||
import { NumberType, SerializableMember, SerializableObject } from '../decorators'; | ||
import { RelativePosition } from './RelativePosition'; | ||
|
||
/** | ||
* Relative 2D Position relative to another object. This indicates the translation and rotation | ||
* relative to another reference object. | ||
*/ | ||
@SerializableObject() | ||
export class Relative2DPosition extends RelativePosition<Vector3, LengthUnit> { | ||
constructor(referenceObject?: any, x?: number, y?: number, unit: LengthUnit = LengthUnit.METER) { | ||
super(referenceObject, new Vector3()); | ||
this.referenceValue.x = unit.convert(x ? x : 0, LengthUnit.METER); | ||
this.referenceValue.y = unit.convert(y ? y : 0, LengthUnit.METER); | ||
} | ||
|
||
@SerializableMember({ | ||
numberType: NumberType.DECIMAL, | ||
}) | ||
get x(): number { | ||
if (!this.referenceValue) { | ||
return undefined; | ||
} | ||
return this.referenceValue.x; | ||
} | ||
|
||
set x(value: number) { | ||
if (!this.referenceValue) { | ||
return; | ||
} | ||
this.referenceValue.x = value; | ||
} | ||
|
||
@SerializableMember({ | ||
numberType: NumberType.DECIMAL, | ||
}) | ||
get y(): number { | ||
if (!this.referenceValue) { | ||
return undefined; | ||
} | ||
return this.referenceValue.y; | ||
} | ||
|
||
set y(value: number) { | ||
if (!this.referenceValue) { | ||
return; | ||
} | ||
this.referenceValue.y = value; | ||
} | ||
|
||
fromVector(vector: Vector2 | Vector3, unit?: LengthUnit): this { | ||
if (unit) { | ||
this.x = unit.convert(vector.x, this.unit); | ||
this.y = unit.convert(vector.y, this.unit); | ||
} else { | ||
this.x = vector.x; | ||
this.y = vector.y; | ||
} | ||
return this; | ||
} | ||
|
||
toVector3(unit?: LengthUnit): Vector3 { | ||
if (unit) { | ||
return new Vector3(this.unit.convert(this.x, unit), this.unit.convert(this.y, unit)); | ||
} else { | ||
return new Vector3(this.x, this.y); | ||
} | ||
} | ||
|
||
/** | ||
* Clone the position | ||
* @returns {Absolute2DPosition} Cloned position | ||
*/ | ||
clone(): this { | ||
const position = super.clone(); | ||
position.x = this.x; | ||
position.y = this.y; | ||
return position as this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { LengthUnit, Vector3 } from '../../utils'; | ||
import { NumberType, SerializableMember, SerializableObject } from '../decorators'; | ||
import { Relative2DPosition } from './Relative2DPosition'; | ||
|
||
/** | ||
* Relative 3D Position relative to another object. This indicates the translation and rotation | ||
* relative to another reference object. | ||
*/ | ||
@SerializableObject() | ||
export class Relative3DPosition extends Relative2DPosition { | ||
constructor(referenceObject?: any, x?: number, y?: number, z?: number, unit: LengthUnit = LengthUnit.METER) { | ||
super(referenceObject, x, y, unit); | ||
this.referenceValue.z = unit.convert(z ? z : 0, LengthUnit.METER); | ||
} | ||
|
||
@SerializableMember({ | ||
numberType: NumberType.DECIMAL, | ||
}) | ||
get z(): number { | ||
if (!this.referenceValue) { | ||
return undefined; | ||
} | ||
return this.referenceValue.z; | ||
} | ||
|
||
set z(value: number) { | ||
if (!this.referenceValue) { | ||
return; | ||
} | ||
this.referenceValue.z = value; | ||
} | ||
|
||
fromVector(vector: Vector3, unit?: LengthUnit): this { | ||
if (unit) { | ||
this.x = unit.convert(vector.x, this.unit); | ||
this.y = unit.convert(vector.y, this.unit); | ||
this.z = unit.convert(vector.z ?? 0, this.unit); | ||
} else { | ||
this.x = vector.x; | ||
this.y = vector.y; | ||
this.z = vector.z ?? 0; | ||
} | ||
return this; | ||
} | ||
|
||
toVector3(unit?: LengthUnit): Vector3 { | ||
if (unit) { | ||
return new Vector3( | ||
this.unit.convert(this.x, unit), | ||
this.unit.convert(this.y, unit), | ||
this.unit.convert(this.z, unit), | ||
); | ||
} else { | ||
return new Vector3(this.x, this.y, this.z); | ||
} | ||
} | ||
|
||
/** | ||
* Clone the position | ||
* @returns {Absolute3DPosition} Cloned position | ||
*/ | ||
clone(): this { | ||
const position = super.clone(); | ||
position.x = this.x; | ||
position.y = this.y; | ||
position.z = this.z; | ||
return position as this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters