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

Sg/calc angles #50

Merged
merged 13 commits into from
Jan 26, 2024
Merged

Sg/calc angles #50

merged 13 commits into from
Jan 26, 2024

Conversation

skygering
Copy link
Collaborator

Calculate angles of given geometries.

The only thing I am concerned about here again is type stability. Right now, points, lines, line strings, and linear rings all return Vectors of Floats, while Polygons return Vectors of Vectors of Floats.

And then a multi-geometry returns a vector of its element's angle return types. I don't really see a way to get around it.

@skygering skygering requested a review from rafaqz January 19, 2024 01:52
Copy link
Member

@rafaqz rafaqz left a comment

Choose a reason for hiding this comment

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

LGTM

Instead of manually looping you could use applyreduce to get down to LineString/LinearRing/MultiPoint/Point targets and get vectors back. That would make it more generic. (Multipoint would also be an empty vector?)

I think applyreduce with identity or collect as op will return the unwrapped vectors?
But we may want to use filter to remove empty child vectors.

src/methods/angles.jl Outdated Show resolved Hide resolved
@skygering
Copy link
Collaborator Author

What do you think about polygons just returning a vector, rather than a nested vector? And then the angles after the first n are angles of holes... or do you think it needs to be nested?

@rafaqz
Copy link
Member

rafaqz commented Jan 19, 2024

Maybe inconsistent? But I have no idea what the use case is 😂

(But generally I think we should make nestedness patterns identical for everthing)

@skygering
Copy link
Collaborator Author

Yeah, it matches up more with the conventions. It is just irritating for me because none of the polygons in my simulations have holes and I don't need the extra allocations 😆

I have a decent amount of geometry code that I have written in the last year and a half floating around my model and I am going to try to move as much of it as I can into GeometryOps, both for the cleanliness of my model and also in case other people find it useful. So if there is slightly "off-topic" code coming in, that is why.

@skygering
Copy link
Collaborator Author

Given that we want Polygons to return Vector{Vector{T}}, I am not sure that applyreduce is the correct strategy. So then a "multi-geom" will be type Vector{Union{Vector, Vector{Vector{T}}}}.

If we want that to happen, I think we need to use push! as the applyreduce operation given that something like vcat would get rid of the nesting. Honestly, though, I kind of want to get rid of the nesting. I feel like it could be equally valid to just return a Vector of angles, there they are in the order provided by GI.getgeom, and then GI.getring. If someone wants the angles of a specific sub-geometry or sub-ring, they can calculate that... or figure it out by the number of points in each sub-geom/ring.

This also gets rid of the issue of empty Vectors (no angles, no elements). Versus if we filter out empty ones and we are nesting, I feel like that is strange as it leaves a missing slot for an existing geometry.

What do you think? Because I think it is going to be type-unstable if we keep the nesting for multi-geoms due to the depth of nesting depending on the type of sub-geometry.

@rafaqz
Copy link
Member

rafaqz commented Jan 20, 2024

Flattenimg is fine too! Just somethimg consistent thst will also work on features without manually writing it all.

You can easily flattten with applyreduce, or use GO.flatten ;)

@rafaqz
Copy link
Member

rafaqz commented Jan 21, 2024

Also not sure what you mean by multi-geom - where does the Union come from?

You should only be able to get a Union if you start with a Union.

@skygering
Copy link
Collaborator Author

By multi-geom I am referring to multipolygons, multipoints, multicurves, and geometry collections.

I think flattening is fine. We are just giving back a list of the angles of the shape.

@rafaqz
Copy link
Member

rafaqz commented Jan 22, 2024

What do you use these angles for in the end? Just so I get the purpose a little more.

@skygering
Copy link
Collaborator Author

So for me, the polygons are all pieces of ice on the ocean. Really sharp angles are un-physical and in the real world would probably fracture off. So I check the angle, and if it is smaller than a threshold, break off the corner, adding a new edge to the polygon and making the corner its own piece.

I also have code that breaks polygons through a given line segment to implement this (and more general fracturing), but that feels maybe a bit too niche to put in this library. Thoughts?

@rafaqz
Copy link
Member

rafaqz commented Jan 22, 2024

Ahh cool.

We do need polygon clipping!

But maybe people can hook up the angles/clipping part themselves?

@skygering
Copy link
Collaborator Author

skygering commented Jan 22, 2024

Polygon-polygon clipping is entering a PR this week (I hope)! My intern is just cleaning up a few things, although there will probably be some more things to clean up afterward.

Ah, you're right! That is just clipping a polygon by a line. I hadn't thought of it like that. Perfect! I will move that code into the library sometime soon-ish then.

@skygering
Copy link
Collaborator Author

For now, I will try to finish this up today and get it merged.

@rafaqz
Copy link
Member

rafaqz commented Jan 22, 2024

Amazing. What clipping algorithm is it?

@skygering
Copy link
Collaborator Author

skygering commented Jan 22, 2024

Greiner and Hormann (https://doi.org/10.1145/274363.274364)

@skygering
Copy link
Collaborator Author

Okay, I think this is good to go! I switched the polygon hole angles to the interior, which means they do need their own function but I use apply reduce for everything else.

end

# Points and single line segments have no angles
_angles(::Type{T}, ::Union{GI.PointTrait, GI.LineTrait}, geom) where T = T[]
Copy link
Member

Choose a reason for hiding this comment

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

Maybe MultiPointTrait is missing here?

Suggested change
_angles(::Type{T}, ::Union{GI.PointTrait, GI.LineTrait}, geom) where T = T[]
_angles(::Type{T}, ::Union{GI.PointTrait, GI.LineTrait, GI.MultiPointTrait}, geom) where T = T[]

@@ -17,10 +17,15 @@ const GB = GeometryBasics

const TuplePoint = Tuple{Float64,Float64}
const Edge = Tuple{TuplePoint,TuplePoint}
const MultiGeomTrait = Union{
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this isn't used now

Copy link
Member

@rafaqz rafaqz left a comment

Choose a reason for hiding this comment

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

LGTM, few minor things

@skygering
Copy link
Collaborator Author

I can't figure out why the documentation is failing. I removed the angle documentation just to see if that was causing it. But I don't think I changed anything that would cause the docs to fail... The error messages also aren't that helpful. Have you every seen anything like this?

@rafaqz
Copy link
Member

rafaqz commented Jan 23, 2024

Looks like a Makie plot is broken somewhere, maybe in the barycentric docs?

@skygering
Copy link
Collaborator Author

Is there a way to run the documentation locally? This takes way too long to test...

@skygering
Copy link
Collaborator Author

Okay, so what I think happened is that with the updates to Documentor, it started running examples within comments, rather than just in DocStrings. I assumed it was the whole time, but I guess not given the number of issues. I fixed the errors, and many of the warnings, but there are still warnings left. Fixing those should be a separate PR.

@skygering skygering mentioned this pull request Jan 26, 2024
@skygering skygering merged commit 249cef4 into JuliaGeo:main Jan 26, 2024
3 checks passed
@skygering skygering deleted the sg/calc_angles branch January 26, 2024 22:19
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.

2 participants