ソースを参照

optimize invertCantorPairing

Alexander Rose 3 年 前
コミット
e0e45b64ac
2 ファイル変更9 行追加7 行削除
  1. 5 3
      src/mol-data/util/hash-functions.ts
  2. 4 4
      src/mol-geo/geometry/mesh/mesh.ts

+ 5 - 3
src/mol-data/util/hash-functions.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2017-2021 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>
@@ -70,11 +70,13 @@ export function sortedCantorPairing(a: number, b: number) {
     return a < b ? cantorPairing(a, b) : cantorPairing(b, a);
 }
 
-export function invertCantorPairing(z: number) {
+export function invertCantorPairing(out: [number, number], z: number) {
     const w = Math.floor((Math.sqrt(8 * z + 1) - 1) / 2);
     const t = (w * w + w) / 2;
     const y = z - t;
-    return [w - y, y];
+    out[0] = w - y;
+    out[1] = y;
+    return out;
 }
 
 /**

+ 4 - 4
src/mol-geo/geometry/mesh/mesh.ts

@@ -396,11 +396,12 @@ export namespace Mesh {
 
     function getBorderVertices(edgeCounts: Map<number, number>) {
         const borderVertices = new Set<number>();
+        const pair: [number, number] = [0, 0];
         edgeCounts.forEach((c, z) => {
             if (c === 1) {
-                const [a, b] = invertCantorPairing(z);
-                borderVertices.add(a);
-                borderVertices.add(b);
+                invertCantorPairing(pair, z);
+                borderVertices.add(pair[0]);
+                borderVertices.add(pair[1]);
             }
         });
 
@@ -429,7 +430,6 @@ export namespace Mesh {
     function trimEdges(mesh: Mesh, neighboursMap: number[][]) {
         const { indexBuffer, triangleCount } = mesh;
         const ib = indexBuffer.ref.value;
-        // const vc = getVertexCounts(mesh);
 
         // new
         const index = ChunkedArray.create(Uint32Array, 3, 1024, triangleCount);