-
Notifications
You must be signed in to change notification settings - Fork 5
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/area dist debug #33
Merged
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
aba090f
Fix up intersection point base calculation
skygering ab16785
Update intersects and add line tests
skygering 7e75e86
Add more tests and debug intersects
skygering a7a7367
Add comments to point_in_poly
skygering b99e37d
Remove CairoMakie
skygering 319bd88
Update equals and overlaps
skygering 0b9799d
Remove use of findfirst for 1.6 compat
skygering 90fff1c
Updated geom, multi-geom equality
skygering ab211f3
Merge branch 'asinghvi17:main' into sg/update_intersects
skygering 6184971
Merge pull request #1 from Caltech-OCTO/sg/update_intersects
skygering 4443707
Merge branch 'main' of github.com:Caltech-OCTO/GeometryOps.jl
skygering d21698f
Merge branch 'main' of github.com:Caltech-OCTO/GeometryOps.jl
skygering 881c98a
Update area for empty geoms
skygering fbc25c3
Polygon area base case
skygering 44eb25a
Update GI call
skygering 32ae923
testing updates
skygering d20837d
Update empty check
skygering f176f95
Added area calculations for empty geoms and collections
skygering 77bfda4
Remove try file
skygering aadfc98
Update area and dist with type param
skygering File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/Manifest.toml | ||
/docs/build/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,23 +71,53 @@ computed slighly differently for different geometries: | |
signed_area(geom) = signed_area(GI.trait(geom), geom) | ||
|
||
# Points | ||
area(::GI.PointTrait, point) = zero(typeof(GI.x(point))) | ||
area(::GI.PointTrait, point) = GI.isempty(point) ? | ||
0 : zero(typeof(GI.x(point))) | ||
|
||
signed_area(trait::GI.PointTrait, point) = area(trait, point) | ||
|
||
# MultiPoints | ||
function area(::GI.MultiPointTrait, multipoint) | ||
GI.isempty(multipoint) && return 0 | ||
np = GI.npoint(multipoint) | ||
np == 0 && return 0 | ||
return zero(typeof(GI.x(GI.getpoint(multipoint, np)))) | ||
end | ||
|
||
signed_area(trait::GI.MultiPointTrait, multipoint) = area(trait, multipoint) | ||
|
||
# Curves | ||
area(::CT, curve) where CT <: GI.AbstractCurveTrait = | ||
zero(typeof(GI.x(GI.getpoint(curve, 1)))) | ||
function area(::CT, curve) where CT <: GI.AbstractCurveTrait | ||
GI.isempty(curve) && return 0 | ||
np = GI.npoint(curve) | ||
np == 0 && return 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
return zero(typeof(GI.x(GI.getpoint(curve, np)))) | ||
end | ||
|
||
signed_area(trait::CT, curve) where CT <: GI.AbstractCurveTrait = | ||
area(trait, curve) | ||
|
||
# MultiCurves | ||
function area(::MCT, multicurve) where MCT <: GI.AbstractMultiCurveTrait | ||
GI.isempty(multicurve) && return 0 | ||
ng = GI.ngeom(multicurve) | ||
ng == 0 && return 0 | ||
np = GI.npoint(GI.getgeom(multicurve, ng)) | ||
np == 0 && return 0 | ||
return zero(typeof(GI.x(GI.getpoint(GI.getgeom(multicurve, ng), np)))) | ||
end | ||
|
||
signed_area(trait::MCT, curve) where MCT <: GI.AbstractMultiCurveTrait = | ||
area(trait, curve) | ||
|
||
# Polygons | ||
area(trait::GI.PolygonTrait, geom) = abs(signed_area(trait, geom)) | ||
|
||
function signed_area(::GI.PolygonTrait, poly) | ||
GI.isempty(poly) && return 0 | ||
s_area = _signed_area(GI.getexterior(poly)) | ||
area = abs(s_area) | ||
area == 0 && return area | ||
# Remove hole areas from total | ||
for hole in GI.gethole(poly) | ||
area -= abs(_signed_area(hole)) | ||
|
@@ -97,9 +127,12 @@ function signed_area(::GI.PolygonTrait, poly) | |
end | ||
|
||
# MultiPolygons | ||
area(::GI.MultiPolygonTrait, geom) = | ||
sum((area(poly) for poly in GI.getpolygon(geom))) | ||
area(::GI.MultiPolygonTrait, multipoly) = | ||
sum((area(poly) for poly in GI.getpolygon(multipoly)), init = 0) | ||
|
||
# GeometryCollections | ||
area(::GI.GeometryCollectionTrait, collection) = | ||
sum((area(geom) for geom in GI.getgeom(collection)), init = 0) | ||
#= | ||
Helper function: | ||
|
||
|
@@ -111,6 +144,7 @@ to be closed. | |
function _signed_area(geom) | ||
# Close curve, even if last point isn't explicitly repeated | ||
np = GI.npoint(geom) | ||
np == 0 && return 0 | ||
first_last_equal = equals(GI.getpoint(geom, 1), GI.getpoint(geom, np)) | ||
np -= first_last_equal ? 1 : 0 | ||
# Integrate the area under the curve | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could we make area always return
Float64
for type stability?Another option is to check the type once at the start, then push it through as the first argument
T
to an_area(T, trait, geom)
method that returns e.g.zero(T)
. We can let users specify it too if they need to