-
Notifications
You must be signed in to change notification settings - Fork 3
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
7 changed files
with
276 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
49 changes: 49 additions & 0 deletions
49
modules/culling/test/lib/algorithms/plane-ray-intersection.spec.ts
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,49 @@ | ||
// math.gl | ||
// SPDX-License-Identifier: MIT and Apache-2.0 | ||
// Copyright (c) vis.gl contributors | ||
|
||
// This file is derived from the Cesium math library under Apache 2 license | ||
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md | ||
|
||
import test from 'tape-promise/tape'; | ||
import {tapeEquals} from 'test/utils/tape-assertions'; | ||
import {intersectPlaneWithRay, Plane, Ray} from '@math.gl/culling'; | ||
import {Vector3} from '@math.gl/core'; | ||
|
||
const VECTOR3_UNIT_X = new Vector3(1.0, 0.0, 0.0); | ||
|
||
test('rayPlane intersects', (t) => { | ||
const ray = new Ray( | ||
new Vector3(2.0, 0.0, 0.0), | ||
new Vector3(-1.0, 0.0, 0.0), | ||
); | ||
const plane = new Plane(VECTOR3_UNIT_X, -1.0); | ||
|
||
const intersectionPoint = intersectPlaneWithRay(plane, ray); | ||
tapeEquals(t, intersectionPoint, new Vector3(1.0, 0.0, 0.0)); | ||
t.end(); | ||
}); | ||
|
||
test('rayPlane misses', (t) => { | ||
const ray = new Ray( | ||
new Vector3(2.0, 0.0, 0.0), | ||
new Vector3(1.0, 0.0, 0.0), | ||
); | ||
const plane = new Plane(VECTOR3_UNIT_X, -1.0); | ||
|
||
const intersectionPoint = intersectPlaneWithRay(plane, ray); | ||
t.equals(intersectionPoint, undefined); | ||
t.end(); | ||
}); | ||
|
||
test('rayPlane misses (parallel)', (t) => { | ||
const ray = new Ray( | ||
new Vector3(2.0, 0.0, 0.0), | ||
new Vector3(0.0, 1.0, 0.0), | ||
); | ||
const plane = new Plane(VECTOR3_UNIT_X, -1.0); | ||
|
||
const intersectionPoint = intersectPlaneWithRay(plane, ray); | ||
t.equals(intersectionPoint, undefined); | ||
t.end(); | ||
}); |
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,38 @@ | ||
// math.gl | ||
// SPDX-License-Identifier: MIT and Apache-2.0 | ||
// Copyright (c) vis.gl contributors | ||
|
||
// This file is derived from the Cesium math library under Apache 2 license | ||
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md | ||
|
||
import test from 'tape-promise/tape'; | ||
import {tapeEquals} from 'test/utils/tape-assertions'; | ||
import {EllipsoidTangentPlane} from '@math.gl/culling'; | ||
import {Vector2, Vector3} from '@math.gl/core'; | ||
|
||
const VECTOR3_UNIT_X = new Vector3(1.0, 0.0, 0.0); | ||
|
||
test('EllipsoidTangentPlane#constructor sets expected values', (t) => { | ||
const tangentPlane = new EllipsoidTangentPlane(VECTOR3_UNIT_X); | ||
tapeEquals(t, tangentPlane.origin, new Vector3(6378137.0, 0.0, 0.0)); | ||
t.end(); | ||
}); | ||
|
||
test('EllipsoidTangentPlane#projectPointToNearestOnPlane works', (t) => { | ||
const tangentPlane = new EllipsoidTangentPlane(VECTOR3_UNIT_X); | ||
|
||
const inputAndResults = [ | ||
{input: new Vector3(1.0, 0.0, 0.0), result: new Vector2(0.0, 0.0)}, | ||
{input: new Vector3(0.0, 0.0, 0.0), result: new Vector2(0.0, 0.0)}, | ||
{input: new Vector3(-1.0, 0.0, 0.0), result: new Vector2(0.0, 0.0)}, | ||
{input: new Vector3(1.0, 0.0, 1.0), result: new Vector2(0.0, 1.0)}, | ||
{input: new Vector3(0.0, 1.0, 0.0), result: new Vector2(1.0, 0.0)}, | ||
{input: new Vector3(0.0, 1.0, 1.0), result: new Vector2(1.0, 1.0)}, | ||
]; | ||
|
||
for (const {input, result} of inputAndResults) { | ||
const output = tangentPlane.projectPointToNearestOnPlane(input); | ||
tapeEquals(t, output, result); | ||
} | ||
t.end(); | ||
}); |
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,40 @@ | ||
// math.gl | ||
// SPDX-License-Identifier: MIT and Apache-2.0 | ||
// Copyright (c) vis.gl contributors | ||
|
||
// This file is derived from the Cesium math library under Apache 2 license | ||
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md | ||
|
||
import test from 'tape-promise/tape'; | ||
import {tapeEquals} from 'test/utils/tape-assertions'; | ||
import {Ray} from "@math.gl/culling"; | ||
import {Vector3} from "@math.gl/core"; | ||
|
||
const VECTOR3_ZERO = new Vector3(0.0, 0.0, 0.0); | ||
const VECTOR3_UNIT_X = new Vector3(1.0, 0.0, 0.0); | ||
const VECTOR3_UNIT_Y = new Vector3(0.0, 1.0, 0.0); | ||
|
||
test("Ray#default constructor create zero valued Ray", (t) => { | ||
const ray = new Ray(); | ||
tapeEquals(t, ray.origin, VECTOR3_ZERO); | ||
tapeEquals(t, ray.direction, VECTOR3_ZERO); | ||
t.end(); | ||
}); | ||
|
||
test("Ray#constructor sets expected properties", (t) => { | ||
const origin = VECTOR3_UNIT_Y; | ||
const direction = VECTOR3_UNIT_X; | ||
const ray = new Ray(origin, direction); | ||
tapeEquals(t, ray.origin, VECTOR3_UNIT_Y); | ||
tapeEquals(t, ray.direction, VECTOR3_UNIT_X); | ||
t.end(); | ||
}); | ||
|
||
test("Ray#constructor normalizes direction", (t) => { | ||
const origin = VECTOR3_UNIT_Y; | ||
const direction = new Vector3(18., 0, 0); | ||
const ray = new Ray(origin, direction); | ||
tapeEquals(t, ray.origin, VECTOR3_UNIT_Y); | ||
tapeEquals(t, ray.direction, VECTOR3_UNIT_X); | ||
t.end(); | ||
}); |
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,68 @@ | ||
// math.gl | ||
// SPDX-License-Identifier: MIT and Apache-2.0 | ||
// Copyright (c) vis.gl contributors | ||
|
||
// This file is derived from the Cesium math library under Apache 2 license | ||
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md | ||
|
||
import test from 'tape-promise/tape'; | ||
import {tapeEquals} from 'test/utils/tape-assertions'; | ||
import {Vector3, radians, _MathUtils} from '@math.gl/core'; | ||
import {GeoRectangle} from '@math.gl/geospatial'; | ||
|
||
const west = -0.9; | ||
const south = 0.5; | ||
const east = 1.4; | ||
const north = 1.0; | ||
const center = new Vector3((west + east) / 2.0, (south + north) / 2.0, 0.0); | ||
|
||
test('GeoRectangle#default constructor sets expected values.', (t) => { | ||
const rectangle = new GeoRectangle(); | ||
t.equals(rectangle.west, 0.0); | ||
t.equals(rectangle.south, 0.0); | ||
t.equals(rectangle.north, 0.0); | ||
t.equals(rectangle.east, 0.0); | ||
t.end(); | ||
}); | ||
|
||
test('GeoRectangle#constructor sets expected parameter values.', (t) => { | ||
const rectangle = new GeoRectangle(west, south, east, north); | ||
t.equals(rectangle.west, west); | ||
t.equals(rectangle.south, south); | ||
t.equals(rectangle.north, north); | ||
t.equals(rectangle.east, east); | ||
t.end(); | ||
}); | ||
|
||
test('GeoRectangle#width works', (t) => { | ||
let rectangle = new GeoRectangle(west, south, east, north); | ||
t.equals(rectangle.width, east - west); | ||
|
||
rectangle = new GeoRectangle(2.0, -1.0, -2.0, 1.0); | ||
t.equals(rectangle.width, rectangle.east - rectangle.west + _MathUtils.TWO_PI); | ||
t.end(); | ||
}); | ||
|
||
test('GeoRectangle#center works', (t) => { | ||
const rectangle = new GeoRectangle(west, south, east, north); | ||
const returnedResult = GeoRectangle.center(rectangle); | ||
tapeEquals(t, returnedResult, center); | ||
t.end(); | ||
}); | ||
|
||
test('GeoRectangle#center works across IDL', (t) => { | ||
const inputAndResults = [ | ||
{input: [170, 0, -170, 0], result: [180, 0]}, | ||
{input: [160, 0, -170, 0], result: [175, 0]}, | ||
{input: [170, 0, -160, 0], result: [-175, 0]}, | ||
{input: [160, 0, 140, 0], result: [-30, 0]}, | ||
] | ||
|
||
for (const {input, result} of inputAndResults) { | ||
const rectangle = new GeoRectangle(...radians(input)); | ||
const returnedResult = GeoRectangle.center(rectangle); | ||
tapeEquals(t, returnedResult, new Vector3(...radians(result), 0)); | ||
} | ||
|
||
t.end(); | ||
}); |
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