Skip to content

Commit e05e356

Browse files
committed
refactor(Transform): Refactor Transform to typescript module, add interface to represent structure and type methods.
Signed-off-by: Drew Hoener <[email protected]>
1 parent 9f4a996 commit e05e356

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/math/Transform.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,40 @@
33
* @author David Gossow - [email protected]
44
*/
55

6-
import Vector3 from './Vector3.js';
7-
import Quaternion from './Quaternion.js';
6+
import Vector3, { type IVector3 } from './Vector3.js';
7+
import Quaternion, { type IQuaternion } from './Quaternion.js';
8+
9+
export interface ITransform {
10+
/**
11+
* The ROSLIB.Vector3 describing the translation.
12+
*/
13+
translation: IVector3;
14+
/**
15+
* The ROSLIB.Quaternion describing the rotation.
16+
*/
17+
rotation: IQuaternion;
18+
}
819

920
/**
1021
* A Transform in 3-space. Values are copied into this object.
1122
*/
12-
export default class Transform {
13-
/**
14-
* @param {Object} options
15-
* @param {Vector3} options.translation - The ROSLIB.Vector3 describing the translation.
16-
* @param {Quaternion} options.rotation - The ROSLIB.Quaternion describing the rotation.
17-
*/
18-
constructor(options) {
23+
export default class Transform implements ITransform {
24+
25+
translation: Vector3;
26+
rotation: Quaternion;
27+
28+
constructor(options: ITransform) {
1929
// Copy the values into this object if they exist
2030
this.translation = new Vector3(options.translation);
2131
this.rotation = new Quaternion(options.rotation);
2232
}
33+
2334
/**
2435
* Clone a copy of this transform.
2536
*
2637
* @returns {Transform} The cloned transform.
2738
*/
28-
clone() {
39+
clone(): Transform {
2940
return new Transform(this);
3041
}
3142
}

src/math/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { default as Pose } from './Pose.js';
22
export { default as Quaternion, type IQuaternion } from './Quaternion.js';
3-
export { default as Transform } from './Transform.js';
3+
export { default as Transform, type ITransform } from './Transform.js';
44
export { default as Vector3, type IVector3 } from './Vector3.js';

0 commit comments

Comments
 (0)