diff --git a/src/mol-math/geometry/boundary.ts b/src/mol-math/geometry/boundary.ts index 3fac4a0d9f867dc97e8aff69820d9693bb50339d..52e1cb198bf531bba6625b9caa7693429c0df2d1 100644 --- a/src/mol-math/geometry/boundary.ts +++ b/src/mol-math/geometry/boundary.ts @@ -28,6 +28,11 @@ export function getBoundary(data: PositionData): Boundary { const { x, y, z, radius, indices } = data; 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); boundaryHelper.reset(); for (let t = 0; t < n; t++) { diff --git a/src/mol-math/geometry/primitives/box3d.ts b/src/mol-math/geometry/primitives/box3d.ts index 690aa826a995d0fe4ee90c8516d80c2932957e6e..e097da873db976fe104817951a63faed43b10fe8 100644 --- a/src/mol-math/geometry/primitives/box3d.ts +++ b/src/mol-math/geometry/primitives/box3d.ts @@ -1,5 +1,5 @@ /** - * 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 Alexander Rose <alexander.rose@weirdbyte.de> @@ -120,6 +120,14 @@ namespace Box3D { add(out, Vec3.transformMat4(tmpTransformV, Vec3.set(tmpTransformV, maxX, maxY, maxZ), m)); 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 }; \ No newline at end of file diff --git a/src/mol-math/geometry/primitives/sphere3d.ts b/src/mol-math/geometry/primitives/sphere3d.ts index 0199af4205fea38d955a0408618af634dce618f8..71b5fc9932576aa06f52d9ce8ccb33bf57639802 100644 --- a/src/mol-math/geometry/primitives/sphere3d.ts +++ b/src/mol-math/geometry/primitives/sphere3d.ts @@ -122,6 +122,18 @@ namespace Sphere3D { export function fromBox3D(out: Sphere3D, box: Box3D) { Vec3.scale(out.center, Vec3.add(out.center, box.max, box.min), 0.5); 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; } diff --git a/src/mol-math/linear-algebra/3d/vec3.ts b/src/mol-math/linear-algebra/3d/vec3.ts index fa9846712f498114d7fc896e6f97cf12165c3b48..a18d254530a42db0baa8d658de22688a6fd379ae 100644 --- a/src/mol-math/linear-algebra/3d/vec3.ts +++ b/src/mol-math/linear-algebra/3d/vec3.ts @@ -160,6 +160,20 @@ namespace Vec3 { 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 */ @@ -190,6 +204,16 @@ namespace Vec3 { 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 */