-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
Changes from 12 commits
1e0b40a
37ea8d8
798782e
ad9d391
2e836a7
fc7bbcc
dc5e8dc
fc2d667
361f7c5
a4c6bfb
bd15973
1f6013c
2222cc5
801904f
5c2bd42
ae5cef2
0f89190
d283930
c8f8f7a
2cb1e6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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 { | ||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is inherited from There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,9 @@ export { | |
// math.gl "GLSL"-style functions | ||
radians, | ||
degrees, | ||
mod, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. See 0f89190 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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