Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate oriented bounding box from bounding region for 3D tiles of Cesium's OSM buildings #40

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1e0b40a
ported methods:
sraimund Dec 26, 2024
37ea8d8
partly ported class 'EllipsoidTangentPlane' from Cesium
sraimund Dec 26, 2024
798782e
ported constant from Cesium:
sraimund Dec 26, 2024
ad9d391
ported methods from Cesium:
sraimund Dec 26, 2024
2e836a7
ported methods from Cesium:
sraimund Dec 26, 2024
fc7bbcc
partly ported class 'Rectangle' from Cesium
sraimund Dec 26, 2024
dc5e8dc
partly ported class 'Ray' from Cesium
sraimund Dec 26, 2024
fc2d667
ported method from Cesium:
sraimund Dec 26, 2024
361f7c5
export ported classes
sraimund Dec 26, 2024
a4c6bfb
added geospatial module for Rectangle calculations
sraimund Dec 26, 2024
bd15973
fix: reuse OBBs properties
sraimund Dec 30, 2024
1f6013c
Merge branch 'master' into master
ibgreen Jan 4, 2025
2222cc5
remove types from TSdoc
sraimund Jan 6, 2025
801904f
reuse parent method
sraimund Jan 6, 2025
5c2bd42
global functions makeOrientedBoundingBoxFromRegion() and intersectPla…
sraimund Jan 6, 2025
ae5cef2
rename Rectangle to GeoRectangle
sraimund Jan 6, 2025
0f89190
tests ported
sraimund Jan 6, 2025
d283930
minimal tests added
sraimund Jan 6, 2025
c8f8f7a
Merge remote-tracking branch 'origin/master'
sraimund Jan 6, 2025
2cb1e6b
replace multiplyByVector() by transform()
sraimund Jan 6, 2025
e851a2a
chore: Bump lerna to 4.2.0-alpha.0. Fix CI. Modernize dependencies. (…
ibgreen Jan 4, 2025
f07f502
feat(geospatial): Add makeOBBFromRegion() (#43)
ibgreen Jan 4, 2025
409d06f
v4.2.0-alpha.1
ibgreen Jan 4, 2025
8614fbd
build(deps): bump nanoid from 3.3.7 to 3.3.8 (#39)
dependabot[bot] Jan 4, 2025
c36934c
chore: Fix CI workflows (#46)
ibgreen Jan 4, 2025
e261b33
v4.2.0-alpha.2
ibgreen Jan 4, 2025
8ac014d
chore: Fix CI release action (#47)
ibgreen Jan 4, 2025
b76d955
v4.2.0-alpha.3
ibgreen Jan 4, 2025
26bc24b
moved from culling to geospatial
sraimund Jan 14, 2025
3a838e7
use normalizeAngle() instead of negativePiToPi()
sraimund Jan 14, 2025
cf81329
use normalizeAngle() instead of negativePiToPi() and zeroToTwoPi(), s…
sraimund Jan 14, 2025
2759906
moved from culling to geospatial
sraimund Jan 14, 2025
d709cc9
remove duplicate methods
sraimund Jan 14, 2025
c6a3cfe
adjust exports and imports
sraimund Jan 14, 2025
5e08ff2
removed in favor of geo-rectangle
sraimund Jan 14, 2025
744c5ef
removed in favor of keeping method in culling module
sraimund Jan 14, 2025
28d4faa
tests for EllipsoidTangentPlane
sraimund Jan 14, 2025
ae64150
amend tsdoc
sraimund Jan 14, 2025
717ae2e
adjust version
sraimund Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions modules/core/src/classes/matrix3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import {NumericArray, NumericArray9} from '@math.gl/types';
import {Matrix} from './base/matrix';
import {Vector3} from './vector3';
import {checkVector} from '../lib/validators';

import {vec4_transformMat3} from '../lib/gl-matrix-extras';
Expand Down Expand Up @@ -202,6 +203,56 @@ export class Matrix3 extends Matrix {
return this.check();
}

/**
* Computes the product of this matrix and a column vector.
*
* @param {Vector3} cartesian The column.
* @param {Vector3} result The object onto which to store the result.
* @returns {Vector3} The modified result parameter.
*/
multiplyByVector(cartesian: Vector3, result?: Vector3): Vector3 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as m3.transform(v3) below? The name comes from viewing the matrix as a transform on vectors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's indeed the same. I removed the method 2cb1e6b

if (!result)
result = new Vector3()

const vX = cartesian.x;
const vY = cartesian.y;
const vZ = cartesian.z;

const x = this[0] * vX + this[3] * vY + this[6] * vZ;
const y = this[1] * vX + this[4] * vY + this[7] * vZ;
const z = this[2] * vX + this[5] * vY + this[8] * vZ;

result.x = x;
result.y = y;
result.z = z;

return result;
}

/**
* Computes the product of this matrix times a (non-uniform) scale, as if the scale were a scale matrix.
*
* @param {Vector3} scale The non-uniform scale on the right-hand side.
* @param {Matrix3} result The object onto which to store the result.
* @returns {Matrix3} The modified result parameter.
*/
multiplyByScale(scale: Vector3, result?: Matrix3): Matrix3 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is inherited from Matrix3 < Matrix < MathArray. Called m3.scale(v3)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now reused the parent scale method, see 801904f The overridden scale method in Matrix3 multiplies it with a Vector2. There I'm not sure if adding another check whether the array length is 2 or 3 impacts the performance in case the method is called many times.

if (!result)
result = new Matrix3()

result[0] = this[0] * scale.x;
result[1] = this[1] * scale.x;
result[2] = this[2] * scale.x;
result[3] = this[3] * scale.y;
result[4] = this[4] * scale.y;
result[5] = this[5] * scale.y;
result[6] = this[6] * scale.z;
result[7] = this[7] * scale.z;
result[8] = this[8] * scale.z;

return result;
}

rotate(radians: number): this {
mat3_rotate(this, this, radians);
return this.check();
Expand Down
3 changes: 3 additions & 0 deletions modules/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export {
// math.gl "GLSL"-style functions
radians,
degrees,
mod,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least a trivial, minimal test case for every global export is normally expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. See 0f89190

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In bounding-box-from-region.spec.ts, however, I added only two tests since there are too many to port from Cesium. Moreover, these tests are based on a unit sphere and math.gl supports only a WGS84 ellipsoid currently.

zeroToTwoPi,
negativePiToPi,
sin,
cos,
tan,
Expand Down
50 changes: 50 additions & 0 deletions modules/core/src/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import type {NumericArray} from '@math.gl/types';

import type {MathArray} from '../classes/base/math-array';
import {EPSILON14, TWO_PI, PI} from './math-utils';

const RADIANS_TO_DEGREES = (1 / Math.PI) * 180;
const DEGREES_TO_RADIANS = (1 / 180) * Math.PI;
Expand Down Expand Up @@ -122,6 +123,55 @@ export function degrees(
return map(radians, (radians) => radians * RADIANS_TO_DEGREES, result);
}


/**
* The modulo operation that also works for negative dividends.
*
* @param {number} m The dividend.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Avoid adding types in the TSDoc, they are inferred from the typescript types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. See 2222cc5

* @param {number} n The divisor.
* @returns {number} The remainder.
*/
export function mod(m: number, n: number): number {
if (Math.sign(m) === Math.sign(n) && Math.abs(m) < Math.abs(n)) {
return m;
}

return ((m % n) + n) % n;
}

/**
* Produces an angle in the range 0 <= angle <= 2Pi which is equivalent to the provided angle.
*
* @param {number} angle in radians
* @returns {number} The angle in the range [0, <code>TWO_PI</code>].
*/
export function zeroToTwoPi(angle: number): number {
if (angle >= 0 && angle <= TWO_PI) {
return angle;
}
const remainder = mod(angle, TWO_PI);
if (
Math.abs(remainder) < EPSILON14 &&
Math.abs(angle) > EPSILON14
) {
return TWO_PI;
}
return remainder;
}

/**
* Produces an angle in the range -Pi <= angle <= Pi which is equivalent to the provided angle.
*
* @param {number} angle in radians
* @returns {number} The angle in the range [<code>-PI</code>, <code>PI</code>].
*/
export function negativePiToPi(angle: number): number {
if (angle >= -PI && angle <= PI) {
return angle;
}
return zeroToTwoPi(angle + PI) - PI;
}

/**
* "GLSL equivalent" of `Math.sin`: Works on single values and vectors
* @deprecated
Expand Down
1 change: 1 addition & 0 deletions modules/core/src/lib/math-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export const PI_OVER_TWO = Math.PI / 2;
export const PI_OVER_FOUR = Math.PI / 4;
export const PI_OVER_SIX = Math.PI / 6;

export const PI = Math.PI;
export const TWO_PI = Math.PI * 2;
3 changes: 2 additions & 1 deletion modules/culling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
],
"dependencies": {
"@math.gl/core": "4.1.0-alpha.9",
"@math.gl/types": "4.1.0-alpha.9"
"@math.gl/types": "4.1.0-alpha.9",
"@math.gl/geospatial": "4.1.0-alpha.9"
},
"gitHead": "e1a95300cb225a90da6e90333d4adf290f7ba501"
}
2 changes: 2 additions & 0 deletions modules/culling/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export {BoundingSphere} from './lib/bounding-volumes/bounding-sphere';
export {OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';
export {CullingVolume} from './lib/culling-volume';
export {Plane} from './lib/plane';
export {Ray} from './lib/ray';
export {EllipsoidTangentPlane} from './lib/ellipsoid-tangent-plane';

export {PerspectiveOffCenterFrustum as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';
export {PerspectiveFrustum as _PerspectiveFrustum} from './lib/perspective-frustum';
Expand Down
Loading
Loading