Browse Source

Add new strokes to fullnodes. Strokes appear one too late though

ssao
A.Olokhtonov 8 months ago
parent
commit
acdbf73a26
  1. 5
      client/aux.js
  2. 8
      client/bvh.js
  3. 6
      client/speed.js

5
client/aux.js

@ -156,6 +156,11 @@ function tv_add(tv, item) { @@ -156,6 +156,11 @@ function tv_add(tv, item) {
tv.data[tv.size++] = item;
}
function tv_add2(tv, item) {
tv_ensure_by(tv, 1);
tv_add(tv, item);
}
function tv_pop(tv) {
const result = tv.data[tv.size - 1];
tv.size--;

8
client/bvh.js

@ -98,7 +98,7 @@ function bvh_add_stroke(bvh, index, stroke) { @@ -98,7 +98,7 @@ function bvh_add_stroke(bvh, index, stroke) {
}
if (bvh.pqueue.capacity < Math.ceil(bvh.nodes.length * 1.2)) {
bvh.pqueue = new MinQueue(bvh.pqueue.capacity * 2);
bvh.pqueue = new MinQueue(bvh.nodes.length * 2);
}
// It's as easy as 1-2-3
@ -141,7 +141,7 @@ function bvh_add_stroke(bvh, index, stroke) { @@ -141,7 +141,7 @@ function bvh_add_stroke(bvh, index, stroke) {
bvh.nodes[new_parent].bbox = new_bbox;
bvh.nodes[new_parent].area = (new_bbox.x2 - new_bbox.x1) * (new_bbox.y2 - new_bbox.y1);
// 3. Refit
// 3. Refit and insert in fullnode
let refit_index = bvh.nodes[leaf_index].parent_index;
while (refit_index !== null) {
const child1 = bvh.nodes[refit_index].child1;
@ -149,6 +149,10 @@ function bvh_add_stroke(bvh, index, stroke) { @@ -149,6 +149,10 @@ function bvh_add_stroke(bvh, index, stroke) {
bvh.nodes[refit_index].bbox = quad_union(bvh.nodes[child1].bbox, bvh.nodes[child2].bbox);
if (bvh.nodes[refit_index].is_fullnode) {
tv_add2(bvh.nodes[refit_index].stroke_indices, index);
}
refit_index = bvh.nodes[refit_index].parent_index;
}
}

6
client/speed.js

@ -119,9 +119,9 @@ function wasm_ensure_by(state, nstrokes, ncoords) { @@ -119,9 +119,9 @@ function wasm_ensure_by(state, nstrokes, ncoords) {
}
if (realloc) {
const current_pages = state.wasm.memory.buffer.byteLength / (4096 * 16);
const need_pages = (state.wasm.coords_bytes * 3 + state.wasm.stroke_bytes * 2) / (4096 * 16); // TODO: figure out actual memory requirements
const grow_by = need_pages - current_pages;
const current_pages = Math.ceil(state.wasm.memory.buffer.byteLength / (4096 * 16));
const need_pages = Math.ceil((state.wasm.coords_bytes * 3 + state.wasm.stroke_bytes * 2) / (4096 * 16)); // TODO: figure out actual memory requirements
const grow_by = Math.max(1, need_pages - current_pages);
state.wasm.memory.grow(grow_by);
state.wasm.exports.free_static();

Loading…
Cancel
Save