Pārlūkot izejas kodu

math geo helpers

Alexander Rose 4 gadi atpakaļ
vecāks
revīzija
bcae586122

+ 5 - 0
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++) {

+ 9 - 1
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 };

+ 12 - 0
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;
     }
 

+ 24 - 0
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
      */