Skip to content

Commit

Permalink
perf(geom-isoline): minor optimizations
Browse files Browse the repository at this point in the history
- use Uint8Array for pre-coded cells
- cellValue() uses pre-computed index
  • Loading branch information
postspectacular committed Feb 8, 2019
1 parent 3ed4ea1 commit d990c3c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/geom-isoline/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const setBorder =

const encodeCrossings =
(src: ReadonlyVec, w: number, h: number, iso: number) => {
const out: number[] = new Array(src.length);
const out = new Uint8Array(src.length);
const w1 = w - 1;
const h1 = h - 1;
for (let y = 0, i = 0; y < h1; y++) {
Expand All @@ -47,8 +47,7 @@ const encodeCrossings =
};

const cellValue =
(src: ReadonlyVec, w: number, x: number, y: number) => {
const idx = y * w + x;
(src: ReadonlyVec, w: number, idx: number) => {
return (
src[idx] +
src[idx + 1] +
Expand Down Expand Up @@ -116,15 +115,16 @@ export function* isolines(src: ReadonlyVec, w: number, h: number, iso: number) {
next = true;
continue;
}
const id = coded[y * w + x];
const i = y * w + x;
const id = coded[i];
if (id === 5) {
[to, clear] = S5[
(cellValue(src, w, x, y) > iso ? 0 : 2) +
(cellValue(src, w, i) > iso ? 0 : 2) +
(from === 3 ? 0 : 1)
];
} else if (id === 10) {
[to, clear] = S10[
cellValue(src, w, x, y) > iso ?
cellValue(src, w, i) > iso ?
(from === 0 ? 0 : 1) :
(from === 2 ? 2 : 3)
];
Expand Down

0 comments on commit d990c3c

Please sign in to comment.