-
Notifications
You must be signed in to change notification settings - Fork 4
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
Sg/calc angles #50
Conversation
There was a problem hiding this 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.
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? |
Maybe inconsistent? But I have no idea what the use case is 😂 (But generally I think we should make nestedness patterns identical for everthing) |
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. |
Given that we want Polygons to return If we want that to happen, I think we need to use 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. |
Flattenimg is fine too! Just somethimg consistent thst will also work on features without manually writing it all. You can easily flattten with |
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. |
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. |
What do you use these angles for in the end? Just so I get the purpose a little more. |
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? |
Ahh cool. We do need polygon clipping! But maybe people can hook up the angles/clipping part themselves? |
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. |
For now, I will try to finish this up today and get it merged. |
Amazing. What clipping algorithm is it? |
Greiner and Hormann (https://doi.org/10.1145/274363.274364) |
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. |
src/methods/angles.jl
Outdated
end | ||
|
||
# Points and single line segments have no angles | ||
_angles(::Type{T}, ::Union{GI.PointTrait, GI.LineTrait}, geom) where T = T[] |
There was a problem hiding this comment.
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?
_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[] |
src/GeometryOps.jl
Outdated
@@ -17,10 +17,15 @@ const GB = GeometryBasics | |||
|
|||
const TuplePoint = Tuple{Float64,Float64} | |||
const Edge = Tuple{TuplePoint,TuplePoint} | |||
const MultiGeomTrait = Union{ |
There was a problem hiding this comment.
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
There was a problem hiding this 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
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? |
Looks like a Makie plot is broken somewhere, maybe in the barycentric docs? |
Is there a way to run the documentation locally? This takes way too long to test... |
d1549bc
to
2e0457e
Compare
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. |
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.