Skip to content

Commit

Permalink
perf(geom-voronoi): update computeDual(), update isBoundary()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 29, 2019
1 parent 2ff68db commit 4d19aa2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/geom-voronoi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ References:

Construction speed: 20k random points ([poisson disc samples, even
distribution](https://github.com/thi-ng/umbrella/tree/master/packages/poisson))
in ~980ms (MBP 2016)
in ~850ms (Chrome 72, MBP 2016)

## Installation

Expand Down
31 changes: 14 additions & 17 deletions packages/geom-voronoi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,22 @@ export class DVMesh<T> {
visitedEdges[e.id] = true;
if (!e.origin || !visitedVerts[e.origin.id]) {
let t = e.rot;
let isBounds = this.isBoundary(t);
const a = t.origin;
const a = t.origin.pos;
let isBounds = this.isBoundary(a);
t = t.lnext;
isBounds = isBounds && this.isBoundary(t);
const b = t.origin;
const b = t.origin.pos;
isBounds = isBounds && this.isBoundary(b);
t = t.lnext;
isBounds = isBounds && this.isBoundary(t);
const c = t.origin;
const c = t.origin.pos;
isBounds = isBounds && this.isBoundary(c);
const id = this.nextID++;
e.origin = {
pos: !isBounds ?
circumCenter2(a.pos, b.pos, c.pos) :
circumCenter2(a, b, c) :
ZERO2,
id: this.nextID++
id
};
visitedVerts[e.origin.id] = true;
visitedVerts[id] = true;
}
work.push(e.sym, e.onext, e.lnext);
}
Expand Down Expand Up @@ -229,7 +230,7 @@ export class DVMesh<T> {
if (visitedEdges[e.id] || visitedEdges[e.sym.id]) return;
const a = e.origin.pos;
const b = e.dest.pos;
if (!this.isBoundaryVertex(a) && !this.isBoundaryVertex(b)) {
if (!this.isBoundary(a) && !this.isBoundary(b)) {
if (boundsMinMax) {
const clip = liangBarsky2(a, b, boundsMinMax[0], boundsMinMax[1]);
clip && edges.push([clip[0], clip[1]]);
Expand All @@ -253,8 +254,8 @@ export class DVMesh<T> {
e = work.pop();
if (visitedEdges[e.id]) continue;
visitedEdges[e.id] = true;
if (!this.isBoundaryVertex(e.origin.pos) &&
!this.isBoundaryVertex(e.rot.origin.pos)) {
if (!this.isBoundary(e.origin.pos) &&
!this.isBoundary(e.rot.origin.pos)) {
if (edges || !visitedVerts[e.origin.id]) {
visitedVerts[e.origin.id] = true;
proc(e, visitedEdges, visitedVerts);
Expand All @@ -264,11 +265,7 @@ export class DVMesh<T> {
}
}

protected isBoundary(e: Edge<Vertex<T>>) {
return this.isBoundaryVertex(e.origin.pos);
}

protected isBoundaryVertex(v: ReadonlyVec) {
protected isBoundary(v: ReadonlyVec) {
const b = this.boundsTri;
return eqDelta2(b[0], v) ||
eqDelta2(b[1], v) ||
Expand Down

0 comments on commit 4d19aa2

Please sign in to comment.