-
Notifications
You must be signed in to change notification settings - Fork 578
(Multi)polygon helper functions #1104
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
Merged
Merged
Changes from all commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
df1b842
area.c
ajfriend b6d9ddb
adding in more stuff
ajfriend 8080e56
merp
ajfriend 5c8950a
kahan accumulator
ajfriend b82cab2
neumaier_add
ajfriend ec26cb8
notes
ajfriend 74e277f
benchmark area
ajfriend c915b51
turn it to 11.
ajfriend a74b9d9
sadly, no improvement from reusing some trig
ajfriend 98ecbee
back to original
ajfriend db21eb0
simplify
ajfriend 04640ef
try adding constants
ajfriend 2349ab4
format, we must
ajfriend 0dd6a5e
Adder docs
ajfriend 7528234
bench
ajfriend 4a4fb07
adder docs
ajfriend 6bd3299
Settled on Kahan implementation
ajfriend 1b21bed
Tighten tolerances in testH3CellAreaExhaustive.c due to compensated sum
ajfriend 64853b3
6
ajfriend 3547c47
notes
ajfriend 0c73921
starting new tests
ajfriend 31fd416
tests work
ajfriend 61702f1
more tests
ajfriend 4b33b02
comments
ajfriend 26eb143
docstring
ajfriend 06b2a6b
better docstrings
ajfriend f55e1b1
Adder note
ajfriend 0c939fc
don't need these imports
ajfriend a292924
clean a few more imports
ajfriend 00f45a2
format
ajfriend 39be84c
needs constants
ajfriend 53e5be9
format
ajfriend 139f483
try fuzzer
ajfriend afa64f1
.mdx
ajfriend f855776
docs in h3api.h.in
ajfriend e48b735
rads2
ajfriend 11b277a
python plan
ajfriend 226da8c
show, don't tell
ajfriend c274bff
benchmark clean up
ajfriend 43f19a9
never say never again
ajfriend fffd723
ugh, would have been cooler if it compiled the first time
ajfriend efcbea0
remove justfile
ajfriend 6e955c9
lighten the h3api.h.in description, as per usual in that file
ajfriend fdcbc17
Merge branch 'master' into cagnoli_area
ajfriend dfeb6d8
simplify adder initialization
ajfriend 6db33a3
drop numVerts < 3
ajfriend e2c20b0
degenerate loop tests
ajfriend eeb3046
try _compareArea(NULL, 0, 0.0);
ajfriend 28105c3
remove docs
ajfriend a3ee94d
drop H3_EXPORT
ajfriend 571d72e
move geoLoopAreaRads2 out of public API for now
ajfriend 7d0f56a
slim down benchmark
ajfriend 77278a6
clear these comments, maybe?
ajfriend fa555e3
try adding area.h to APP_SOURCE_FILES
ajfriend 64e9ad8
can't fail if you don't try!
ajfriend a059397
minor
ajfriend b24442f
remove justfile
ajfriend dd316e0
Adder adder = {};
ajfriend c727543
(multi)polygon area functions
ajfriend 8c12e2f
degenerate loop note
ajfriend 861bc81
destroy sigs
ajfriend 59fefdc
destroy implementations
ajfriend 246f2f4
createGlobalMultiPolygon
ajfriend 4164d37
testGeoMultiPolygon.c
ajfriend 808c398
try constants
ajfriend 8f1c085
H3_EXPORT
ajfriend e6bbf55
rename to createGlobeMultiPolygon
ajfriend c24fffa
handle errors. add function docs
ajfriend a154a82
test for geoMultiPolygonAreaRads2
ajfriend fb79132
better test; more coverage
ajfriend 741470d
Merge branch 'master' into cagnoli_area2
ajfriend bedf3fa
fix missing brace from github merge
ajfriend bdb0521
remove destroyGeoLoop and destroyGeoPolygon from public API
ajfriend ff56f5a
move global poly function
ajfriend 82fdb50
remove unnecessary import
ajfriend f65a365
remove justfile
ajfriend 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * Copyright 2025 Uber Technologies, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** @file | ||
| * @brief tests for GeoMultiPolygon, GeoPolygon, and GeoLoop | ||
| * | ||
| * usage: `testGeoMultiPolygon` | ||
| */ | ||
|
|
||
| #include <math.h> | ||
| #include <string.h> | ||
|
|
||
| #include "algos.h" | ||
| #include "alloc.h" | ||
| #include "area.h" | ||
| #include "h3api.h" | ||
| #include "test.h" | ||
| #include "utility.h" | ||
|
|
||
| SUITE(geoMultiPolygon) { | ||
| TEST(globalMultiPolygonArea) { | ||
| double tol = 1e-14; | ||
| double out; | ||
|
|
||
| GeoMultiPolygon mpoly = createGlobeMultiPolygon(); | ||
| t_assertSuccess(geoMultiPolygonAreaRads2(mpoly, &out)); | ||
| t_assert(fabs(out - 4 * M_PI) < tol, "area should match"); | ||
|
|
||
| H3_EXPORT(destroyGeoMultiPolygon)(&mpoly); | ||
| } | ||
|
|
||
| TEST(holeSameAsOuter) { | ||
| /** | ||
| * TODO: Replace with simpler test. | ||
| * | ||
| * I needed a test to exercize the "hole" branches of | ||
| * `destroyGeoMultiPolygon` and `geoMultiPolygonAreaRads2`. | ||
| * | ||
| * This is a verbose test because we have to allocate the | ||
| * `GeoMultiPolygon`. When we add in the `cellsToMultiPolygon` function, | ||
| * I can replace this with a much shorter, clearer test. | ||
| */ | ||
|
|
||
| // Create a polygon with a triangle outer and a hole of exactly | ||
| // the same size, so the resulting polygon and multipolygons should | ||
| // have 0 area. | ||
| LatLng _outer[] = { | ||
| // Counter-clockwise points | ||
| {M_PI_2, 0}, | ||
| {0, 0}, | ||
| {0, M_PI_2}, | ||
| }; | ||
| LatLng _hole[] = { | ||
| // Same as above, but clockwise points | ||
| {M_PI_2, 0}, | ||
| {0, M_PI_2}, | ||
| {0, 0}, | ||
| }; | ||
|
|
||
| GeoLoop outer = { | ||
| .numVerts = 3, | ||
| .verts = H3_MEMORY(malloc)(3 * sizeof(LatLng)), | ||
| }; | ||
| GeoLoop hole = { | ||
| .numVerts = 3, | ||
| .verts = H3_MEMORY(malloc)(3 * sizeof(LatLng)), | ||
| }; | ||
|
|
||
| memcpy(outer.verts, _outer, 3 * sizeof(LatLng)); | ||
| memcpy(hole.verts, _hole, 3 * sizeof(LatLng)); | ||
|
|
||
| GeoPolygon poly = { | ||
| .geoloop = outer, | ||
| .numHoles = 1, | ||
| .holes = H3_MEMORY(malloc)(sizeof(GeoLoop)), | ||
| }; | ||
| poly.holes[0] = hole; | ||
|
|
||
| GeoMultiPolygon mpoly = { | ||
| .numPolygons = 1, | ||
| .polygons = H3_MEMORY(malloc)(sizeof(GeoPolygon)), | ||
| }; | ||
| mpoly.polygons[0] = poly; | ||
|
|
||
| double out; | ||
| t_assertSuccess(geoMultiPolygonAreaRads2(mpoly, &out)); | ||
| t_assert(fabs(out) < 1e-14, "Area should be 0"); | ||
|
|
||
| H3_EXPORT(destroyGeoMultiPolygon)(&mpoly); | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.