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

Add a convex hull algorithm #160

Merged
merged 16 commits into from
Jul 28, 2024
Merged

Add a convex hull algorithm #160

merged 16 commits into from
Jul 28, 2024

Conversation

asinghvi17
Copy link
Member

Via DelaunayTriangulation.jl.

Needs to be updated to latest main as well as some tests + a GEOS algorithm.

Copy link
Contributor

@DanielVandH DanielVandH left a comment

Choose a reason for hiding this comment

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

Know it's in draft but happened to notice a couple of things here

src/methods/convex_hull.jl Outdated Show resolved Hide resolved

# TODO: have this respect the CRS by pulling it out of `geometries`.
function convex_hull(::DelaunayTriangulationMethod, geometries)
# Extract all points as tuples. We have to collect and allocate
Copy link
Contributor

@DanielVandH DanielVandH Jun 13, 2024

Choose a reason for hiding this comment

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

Is this true? You can provide whatever point types you like so long as you extend the interfaces (which are hopefully sufficiently documented) from DelaunayTriangulation.jl appropriately. I give a complete example here https://juliageometry.github.io/DelaunayTriangulation.jl/dev/tutorials/custom_primitive/, maybe something goes wrong in convex_hull that I'm not aware of?

Highlighted the wrong part of the text for this comment but I'm referring to the need to flatten and collect the points

Copy link
Member Author

Choose a reason for hiding this comment

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

We have to flatten anyway to get a vector, and getting x and y values from C pointers is pretty bad for performance - best to do it once. I can update the comment with better verbiage, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Plus, we'd have to extend the interface for every GeoInterface compatible type, which would probably mean either piracy or changes on the DelaunayTriangulation end. (Though if you do want to allow GeoInterface as a fallback it would be pretty easy I think).

Copy link
Contributor

Choose a reason for hiding this comment

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

We have to flatten anyway to get a vector, and getting x and y values from C pointers is pretty bad for performance - best to do it once. I can update the comment with better verbiage, though.

I have no preference either way just wanted to see if you were aware (I wasn't aware of the need for getting the values from C pointers, so fair enough). The verbiage is alright

Plus, we'd have to extend the interface for every GeoInterface compatible type, which would probably mean either piracy or changes on the DelaunayTriangulation end. (Though if you do want to allow GeoInterface as a fallback it would be pretty easy I think).

It would probably be welcome as a package extension in DelaunayTriangulation. I'm not familiar with the interfaces though, so I probably won't be delving into that. Just leaving the code as is is fine anyway, it works and would be fast enough :).

Copy link
Member Author

Choose a reason for hiding this comment

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

It would probably just be:

DT.getx(p) = DT.getx(GI.trait(p), p)
DT.gety(p) = DT.gety(GI.trait(p), p)
DT.number_type(p) = DT.number_type(GI.trait(p), p)

DT.getx(::GI.PointTrait, p) = GI.x(p)
DT.gety(::GI.PointTrait, p) = GI.y(p)
DT.number_type(::GI.PointTrait, p) = typeof(GI.x(p))

src/methods/convex_hull.jl Outdated Show resolved Hide resolved
src/methods/convex_hull.jl Outdated Show resolved Hide resolved
src/methods/convex_hull.jl Outdated Show resolved Hide resolved
src/methods/convex_hull.jl Outdated Show resolved Hide resolved
asinghvi17 and others added 4 commits July 21, 2024 19:44
@asinghvi17 asinghvi17 marked this pull request as ready for review July 26, 2024 06:18
@asinghvi17 asinghvi17 requested review from rafaqz and skygering July 26, 2024 08:16
@asinghvi17
Copy link
Member Author

This is good to go from my end of things!

src/methods/convex_hull.jl Outdated Show resolved Hide resolved
src/GeometryOps.jl Outdated Show resolved Hide resolved
@asinghvi17
Copy link
Member Author

GEOS's convex hull is wound clockwise? Somehow? Simple features dictates the opposite but I guess this is following ESRI...

@asinghvi17 asinghvi17 changed the title [WIP] Implement a convex hull algorithm Add a convex hull algorithm Jul 27, 2024
@asinghvi17 asinghvi17 merged commit ca428c6 into main Jul 28, 2024
4 checks passed
@asinghvi17 asinghvi17 deleted the as/deltri branch July 30, 2024 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants