|
2 | 2 | * @fileOverview
|
3 | 3 | * @author David Gossow - [email protected]
|
4 | 4 | */
|
| 5 | +import Vector3, { type IVector3 } from './Vector3.js'; |
| 6 | +import Quaternion, { type IQuaternion } from './Quaternion.js'; |
| 7 | +import { type ITransform } from './Transform.js'; |
| 8 | +import { PartialNullable } from '../types/interface-types.js'; |
5 | 9 |
|
6 |
| -import Vector3 from './Vector3.js'; |
7 |
| -import Quaternion from './Quaternion.js'; |
8 |
| -import Transform from './Transform.js'; |
| 10 | +export interface IPose { |
| 11 | + /** |
| 12 | + * The ROSLIB.Vector3 describing the position. |
| 13 | + */ |
| 14 | + position: IVector3; |
| 15 | + /** |
| 16 | + * The ROSLIB.Quaternion describing the orientation. |
| 17 | + */ |
| 18 | + orientation: IQuaternion; |
| 19 | +} |
9 | 20 |
|
10 | 21 | /**
|
11 | 22 | * A Pose in 3D space. Values are copied into this object.
|
12 | 23 | */
|
13 |
| -export default class Pose { |
14 |
| - /** |
15 |
| - * @param {Object} [options] |
16 |
| - * @param {Vector3} [options.position] - The ROSLIB.Vector3 describing the position. |
17 |
| - * @param {Quaternion} [options.orientation] - The ROSLIB.Quaternion describing the orientation. |
18 |
| - */ |
19 |
| - constructor(options) { |
20 |
| - options = options || {}; |
21 |
| - // copy the values into this object if they exist |
22 |
| - options = options || {}; |
23 |
| - this.position = new Vector3(options.position); |
24 |
| - this.orientation = new Quaternion(options.orientation); |
| 24 | +export default class Pose implements IPose { |
| 25 | + |
| 26 | + position: Vector3; |
| 27 | + orientation: Quaternion; |
| 28 | + |
| 29 | + constructor(options?: PartialNullable<IPose>) { |
| 30 | + this.position = new Vector3(options?.position); |
| 31 | + this.orientation = new Quaternion(options?.orientation); |
25 | 32 | }
|
| 33 | + |
26 | 34 | /**
|
27 | 35 | * Apply a transform against this pose.
|
28 | 36 | *
|
29 |
| - * @param {Transform} tf - The transform to be applied. |
| 37 | + * @param {ITransform} tf - The transform to be applied. |
30 | 38 | */
|
31 |
| - applyTransform(tf) { |
| 39 | + applyTransform(tf: ITransform) { |
32 | 40 | this.position.multiplyQuaternion(tf.rotation);
|
33 | 41 | this.position.add(tf.translation);
|
34 |
| - var tmp = tf.rotation.clone(); |
| 42 | + const tmp = new Quaternion(tf.rotation); |
35 | 43 | tmp.multiply(this.orientation);
|
36 | 44 | this.orientation = tmp;
|
37 | 45 | }
|
| 46 | + |
38 | 47 | /**
|
39 | 48 | * Clone a copy of this pose.
|
40 | 49 | *
|
41 | 50 | * @returns {Pose} The cloned pose.
|
42 | 51 | */
|
43 |
| - clone() { |
| 52 | + clone(): Pose { |
44 | 53 | return new Pose(this);
|
45 | 54 | }
|
| 55 | + |
46 | 56 | /**
|
47 | 57 | * Multiply this pose with another pose without altering this pose.
|
48 | 58 | *
|
49 | 59 | * @returns {Pose} The result of the multiplication.
|
50 | 60 | */
|
51 |
| - multiply(pose) { |
52 |
| - var p = pose.clone(); |
| 61 | + multiply(pose: Pose): Pose { |
| 62 | + const p = pose.clone(); |
53 | 63 | p.applyTransform({
|
54 | 64 | rotation: this.orientation,
|
55 | 65 | translation: this.position
|
56 | 66 | });
|
57 | 67 | return p;
|
58 | 68 | }
|
| 69 | + |
59 | 70 | /**
|
60 | 71 | * Compute the inverse of this pose.
|
61 | 72 | *
|
62 | 73 | * @returns {Pose} The inverse of the pose.
|
63 | 74 | */
|
64 |
| - getInverse() { |
65 |
| - var inverse = this.clone(); |
| 75 | + getInverse(): Pose { |
| 76 | + const inverse = this.clone(); |
66 | 77 | inverse.orientation.invert();
|
67 | 78 | inverse.position.multiplyQuaternion(inverse.orientation);
|
68 | 79 | inverse.position.x *= -1;
|
|
0 commit comments