Skip to content
Snippets Groups Projects
Commit bcae5861 authored by Alexander Rose's avatar Alexander Rose
Browse files

math geo helpers

parent 8fda9beb
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,11 @@ export function getBoundary(data: PositionData): Boundary { ...@@ -28,6 +28,11 @@ export function getBoundary(data: PositionData): Boundary {
const { x, y, z, radius, indices } = data; const { x, y, z, radius, indices } = data;
const n = OrderedSet.size(indices); const n = OrderedSet.size(indices);
if (n > 250_000) {
const box = Box3D.computeBounding(data);
return { box, sphere: Sphere3D.fromBox3D(Sphere3D(), box) };
}
const boundaryHelper = getBoundaryHelper(n); const boundaryHelper = getBoundaryHelper(n);
boundaryHelper.reset(); boundaryHelper.reset();
for (let t = 0; t < n; t++) { for (let t = 0; t < n; t++) {
......
/** /**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
* *
* @author David Sehnal <david.sehnal@gmail.com> * @author David Sehnal <david.sehnal@gmail.com>
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
...@@ -120,6 +120,14 @@ namespace Box3D { ...@@ -120,6 +120,14 @@ namespace Box3D {
add(out, Vec3.transformMat4(tmpTransformV, Vec3.set(tmpTransformV, maxX, maxY, maxZ), m)); add(out, Vec3.transformMat4(tmpTransformV, Vec3.set(tmpTransformV, maxX, maxY, maxZ), m));
return out; return out;
} }
export function containsVec3(box: Box3D, v: Vec3) {
return (
v[0] < box.min[0] || v[0] > box.max[0] ||
v[1] < box.min[1] || v[1] > box.max[1] ||
v[2] < box.min[2] || v[2] > box.max[2]
) ? false : true;
}
} }
export { Box3D }; export { Box3D };
\ No newline at end of file
...@@ -122,6 +122,18 @@ namespace Sphere3D { ...@@ -122,6 +122,18 @@ namespace Sphere3D {
export function fromBox3D(out: Sphere3D, box: Box3D) { export function fromBox3D(out: Sphere3D, box: Box3D) {
Vec3.scale(out.center, Vec3.add(out.center, box.max, box.min), 0.5); Vec3.scale(out.center, Vec3.add(out.center, box.max, box.min), 0.5);
out.radius = Vec3.distance(out.center, box.max); out.radius = Vec3.distance(out.center, box.max);
Sphere3D.setExtrema(out, [
Vec3.create(box.min[0], box.min[1], box.min[2]),
Vec3.create(box.max[0], box.max[1], box.max[2]),
Vec3.create(box.max[0], box.min[1], box.min[2]),
Vec3.create(box.min[0], box.max[1], box.max[2]),
Vec3.create(box.min[0], box.min[1], box.max[2]),
Vec3.create(box.max[0], box.min[1], box.max[2]),
Vec3.create(box.max[0], box.max[1], box.min[2]),
Vec3.create(box.min[0], box.max[1], box.min[2]),
]);
return out; return out;
} }
......
...@@ -160,6 +160,20 @@ namespace Vec3 { ...@@ -160,6 +160,20 @@ namespace Vec3 {
return out; return out;
} }
export function addScalar(out: Vec3, a: Vec3, b: number) {
out[0] = a[0] + b;
out[1] = a[1] + b;
out[2] = a[2] + b;
return out;
}
export function subScalar(out: Vec3, a: Vec3, b: number) {
out[0] = a[0] - b;
out[1] = a[1] - b;
out[2] = a[2] - b;
return out;
}
/** /**
* Math.round the components of a Vec3 * Math.round the components of a Vec3
*/ */
...@@ -190,6 +204,16 @@ namespace Vec3 { ...@@ -190,6 +204,16 @@ namespace Vec3 {
return out; return out;
} }
/**
* Math.trunc the components of a Vec3
*/
export function trunc(out: Vec3, a: Vec3) {
out[0] = Math.trunc(a[0]);
out[1] = Math.trunc(a[1]);
out[2] = Math.trunc(a[2]);
return out;
}
/** /**
* Returns the minimum of two Vec3's * Returns the minimum of two Vec3's
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment