Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: transpose3D * refactor: remove redundant code * chore: 1. remove pnpm lock file; 2. upgrade package version to 0.4.7
- Loading branch information
Showing
6 changed files
with
54 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Coordinate3D, Vector3 } from '../../../src'; | ||
|
||
describe('Transpose3D', () => { | ||
test('transpose() exchanges dimensions', () => { | ||
const coord = new Coordinate3D(); | ||
coord.transform('transpose3D'); | ||
const constZ = 0.3; | ||
expect(coord.map([0, 1, constZ])).toEqual([1, 0, constZ]); | ||
expect(coord.map([0.2, 0.8, constZ])).toEqual([0.8, 0.2, constZ]); | ||
expect(coord.invert([1, 0, constZ])).toEqual([0, 1, constZ]); | ||
expect(coord.map([0.8, 0.2, constZ])).toEqual([0.2, 0.8, constZ]); | ||
}); | ||
|
||
test('cartesian3D transpose', () => { | ||
const coord = new Coordinate3D({ | ||
transformations: [['cartesian3D'], ['transpose3D']], | ||
width: 300, | ||
height: 150, | ||
depth: 100, | ||
}); | ||
|
||
const v1: Vector3 = [0, 0, 0]; | ||
const v2: Vector3 = [0, 0, 0]; | ||
|
||
expect(coord.map(v1)).toEqual(v2); | ||
expect(coord.map([1, 1, 1])).toEqual([150, 300, 100]); | ||
expect(coord.invert([0, 0, 0])).toEqual([0, 0, 0]); | ||
expect(coord.invert([150, 300, 100])).toEqual([1, 1, 1]); | ||
}); | ||
}); |
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,18 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { CreateTransformer3D, Vector3 } from '../type'; | ||
|
||
/** | ||
* Exchange dimensions of the vector. | ||
* @param params [tx, ty] | ||
* @param x x of the the bounding box of coordinate | ||
* @param y y of the the bounding box of coordinate | ||
* @param width width of the the bounding box of coordinate | ||
* @param height height of the the bounding box of coordinate | ||
* @returns transformer | ||
*/ | ||
export const transpose3D: CreateTransformer3D = (params, x, y, z, width, height, depth) => { | ||
return { | ||
transform: ([x, y, z]: Vector3) => [y, x, z], | ||
untransform: ([x, y, z]: Vector3) => [y, x, z], | ||
}; | ||
}; |
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