Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to delaunator@3 #60

Closed
wants to merge 9 commits into from
Closed

upgrade to delaunator@3 #60

wants to merge 9 commits into from

Conversation

Fil
Copy link
Member

@Fil Fil commented May 22, 2019

fixes #50

Demos:

Breaking changes:

  • delaunay.hull is now an Int32Array of point indices
  • removes delaunay.outedges from the API (and uses hullIndex internally).

(supersedes #59)

Fil added 6 commits May 22, 2019 01:04
fixes #50

note: I had to disable the tests for outeredges, because I'm not using the same outeredges (but they do point to the same nodes).
@Fil Fil mentioned this pull request May 22, 2019
Copy link
Collaborator

@mourner mourner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me! Commented with a few nits

<a href="#delaunay_outedges" name="delaunay_outedges">#</a> <i>delaunay</i>.<b>outedges</b>

The outgoing halfedge indexes as a Int32Array [*e0*, *e1*, *e2*, …]. For each point *i* on the convex hull, *outedges*[*i*] is the halfedge index *e* of the corresponding outgoing halfedge; for other points, the halfedge index is -1. The *outedges* table can be used to traverse the Delaunay triangulation; see also [*delaunay*.neighbors](#delaunay_neighbors).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's document hullIndex instead maybe?

Copy link
Member Author

@Fil Fil May 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it should be in the public API:

  • we have access to the hull if we need to reconstruct it, it's a linear op in time and memory
  • we should use neighbors(i) anyway

(Maybe it should be private?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to do that (ie: keeping this.hullIndex private) in a proper way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah don't worry about it, let's just leave it there without docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest either adding documentation for hullIndex to the README, or renaming it to _hullIndex to mark it clear that it’s private.

src/delaunay.js Outdated Show resolved Hide resolved
src/delaunay.js Outdated Show resolved Hide resolved
@JobLeonard
Copy link

JobLeonard commented May 22, 2019

https://observablehq.com/d/0f4a4cc6afcc02c3

Have you considered making a variant of delaunator that uses a mutable api, like I suggested in this delaunator issue? TypedArray allocation tends to be a major bottleneck in these kinds of algorithms, so this is likely to significantly improve performance in Lloyd's Algorithm. Especially if we want to use more points!

EDIT: Note, the linked comment contains a link to a gist with a changed constructor + update function that should enable this (but as of now it is untested)

@Fil
Copy link
Member Author

Fil commented May 22, 2019

Have you considered making a variant of delaunator that uses a mutable api

In this PR I've only focused on bringing delaunator@3 to d3-delaunay. But your approach looks very promising!

@JobLeonard
Copy link

Makes sense - plus the proposed mutable variant is not officially part of delaunator yet. I might fork your notebook later to see if it is even worth it (I hope so, the various stippling notebooks could use a performance boost!)

Copy link
Collaborator

@mourner mourner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 pending a look from @mbostock

Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor nits on coding style. I didn’t review the implementation (because I’m lazy, sorry!) but I greatly appreciate your contribution!

<a href="#delaunay_outedges" name="delaunay_outedges">#</a> <i>delaunay</i>.<b>outedges</b>

The outgoing halfedge indexes as a Int32Array [*e0*, *e1*, *e2*, …]. For each point *i* on the convex hull, *outedges*[*i*] is the halfedge index *e* of the corresponding outgoing halfedge; for other points, the halfedge index is -1. The *outedges* table can be used to traverse the Delaunay triangulation; see also [*delaunay*.neighbors](#delaunay_neighbors).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest either adding documentation for hullIndex to the README, or renaming it to _hullIndex to mark it clear that it’s private.

src/delaunay.js Outdated
const p = triangles[e % 3 === 2 ? e - 2 : e + 1];
if (halfedges[e] === -1 || inedges[p] === -1) inedges[p] = e;
}
for (let i = 0; i < hull.length; ++i) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let i = 0, n = hull.length

for (let i = 0, h; i < hull.length; ++i) {
h = hull[i];
context[i ? "lineTo" : "moveTo"](points[2 * h], points[2 * h + 1]);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d prefer the first context.moveTo broken out of the loop (so you don’t need to test i inside the loop). Also pull out n, and then const h = hull[i] * 2; inside the loop.

@Fil
Copy link
Member Author

Fil commented May 24, 2019

Superseded by #63. (The code is not different but I squashed the commit and did a bit of clean-up.)

@Fil Fil closed this May 24, 2019
@Fil Fil deleted the hullIndex branch May 24, 2019 13:52
@mourner
Copy link
Collaborator

mourner commented May 24, 2019

@Fil note that you can do this in existing PRs by doing git force --push to the PR branch.

@mourner
Copy link
Collaborator

mourner commented May 24, 2019

Or alternatively, we could enable the "Squash and merge" option for PR merge button (currently only "Rebase" is available). Are there specific reasons not to @mbostock?

@Fil
Copy link
Member Author

Fil commented May 24, 2019

@Fil note that you can do this in existing PRs by doing git force --push to the PR branch.

(Yep. But I had so many mix-ups in my local branches that I preferred a clean PR. And there was no way I could squash automatically because of conflicts with the early merge of d180502.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants