-
Notifications
You must be signed in to change notification settings - Fork 565
Vec3d indexing refactor #1145
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
Vec3d indexing refactor #1145
Changes from all commits
Commits
Show all changes
91 commits
Select commit
Hold shift + click to select a range
432cf47
Add Vec3d math functions: dot, cross, normalize, mag, distSq, latLngT…
holoskii 4b6daca
Refactor faceijk.c: Vec3d as core coordinate type
holoskii fe7b36a
Add Vec3d unit tests
holoskii 4eefbfa
Route latLngToCell/cellToLatLng through Vec3d; remove dead LatLng-onl…
ajfriend 4aa3b63
cell boundary code to Vec3d path; remove _hex2dToGeo, _geoAzDistanceR…
ajfriend 0c5dcba
vec3ToCell validation tests
ajfriend 6c3eedf
align function names and struct: hex2d -> vec2d
ajfriend 2f159ed
use Vec2 and Vec3 everywhere
ajfriend 4021953
normalize
ajfriend 2a55747
h3 -> cell; years
ajfriend 35b3302
bench
ajfriend f7e9e44
update bench
ajfriend 2f5a9f4
correctness
ajfriend b310c51
test vertices and along edges
ajfriend f1f1938
_vec3TangentBasis helper
ajfriend e2d586e
vec3LinComb helper
ajfriend 3f21332
return by value
ajfriend 8709618
pass by value
ajfriend 1a50e33
clean
ajfriend 2e36bd2
test for inlining
ajfriend 12c8f5d
header-only; suffering on LTO
ajfriend 9916417
header only
ajfriend ad41cde
clean up benchmark script
ajfriend b770a1c
_vec3ToFaceIjk
ajfriend 7977187
output params
ajfriend 3f7dd6e
header version of _ijkToVec2
ajfriend e7278d9
revert
ajfriend 7e9d540
revert
ajfriend 6670909
redo
ajfriend 0040fd6
inline ijk ops
ajfriend 64290b4
going header only
ajfriend 0c0171d
directedEdgeToBoundary bench
ajfriend b106a0e
justfile
ajfriend 421eca4
revert coorijk header change
ajfriend 397748a
comments
ajfriend 0382015
update benchmarks
ajfriend e834f8c
again
ajfriend b8194f3
reduce digits on testCliEdgeLengthM
ajfriend 0235f15
vertexToLatLng benchmark
ajfriend d54ee33
cover line in latLng.c
ajfriend 863d4c8
remove temporary benchmarks and assignment tests
ajfriend 9b20e30
_faceIjkToCell back to _faceIjkToH3
ajfriend 3229a5c
restore Vec3d
ajfriend 739e2b1
missed a few
ajfriend 82eb168
test files
ajfriend ddff3a2
vec2d.h
ajfriend 8ca67fc
Vec2d
ajfriend d64eb6a
vec2 names
ajfriend 35a3332
more vec2 names
ajfriend ae94a89
names
ajfriend b883add
comments
ajfriend 4ec1613
years
ajfriend cd3b96a
years
ajfriend dd94efb
boop
ajfriend a27bf9e
years
ajfriend d3862ad
old test
ajfriend 6d2a8bf
haven't i done this one already?
ajfriend d3ac597
_hex2dToVec3
ajfriend 93e67a3
pass output by reference
ajfriend 72d41f4
_vec3ToHex2d
ajfriend 21eace6
forward declare
ajfriend ef61c27
comment
ajfriend a4f4e55
bah
ajfriend 2d83319
bah bah
ajfriend 02bfc81
move around _vec3ToClosestFace
ajfriend 83ea8ac
todo
ajfriend 2bca783
bring benchmarks back in
ajfriend 80fa000
nits
ajfriend 6a4f594
pass by value
ajfriend 2dbd994
expression
ajfriend 9fe2828
_vec3TangentBasis
ajfriend 2d48ca0
nits
ajfriend b2232b6
boop
ajfriend fd2a985
i swear...
ajfriend 7d568f0
boop
ajfriend a2ce573
9 digits
ajfriend 218c973
move
ajfriend e63e313
8 digits
ajfriend 4dc91f7
comments align
ajfriend bd5c9a5
better names for vec3LinComb
ajfriend 9fcb5aa
dead code: remove faceCenterGeo definition
ajfriend a06d168
remove benchmarks and justfile
ajfriend 1aa5d4a
camel_case
ajfriend c739284
fix more snakeCase
ajfriend 5cffa92
small norm handling
ajfriend 81ae468
static void _hex2dToVec3
ajfriend 04275a2
_faceIjkToVec3 g
ajfriend a9acd9e
fix doc comment on _faceIjkToVec3
ajfriend 466a712
avoid Vec3d casts
ajfriend 665fd28
unit vector comments
ajfriend 5177e31
add vec3ToCell tests
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
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,148 @@ | ||
| /* | ||
| * Copyright 2026 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 testVec3.c | ||
| * @brief Tests the Vec3d helpers used by the geodesic polyfill path. | ||
| */ | ||
|
|
||
| #include <float.h> | ||
| #include <math.h> | ||
|
|
||
| #include "h3Index.h" | ||
| #include "test.h" | ||
| #include "vec3d.h" | ||
|
|
||
| SUITE(Vec3d) { | ||
| TEST(dotProduct) { | ||
| Vec3d a = {.x = 1.0, .y = 0.0, .z = 0.0}; | ||
| Vec3d b = {.x = -1.0, .y = 0.0, .z = 0.0}; | ||
| t_assert(vec3Dot(a, b) == -1.0, "dot product matches expected value"); | ||
| } | ||
|
|
||
| TEST(crossProductOrthogonality) { | ||
| Vec3d i = {.x = 1.0, .y = 0.0, .z = 0.0}; | ||
| Vec3d j = {.x = 0.0, .y = 1.0, .z = 0.0}; | ||
| Vec3d k = vec3Cross(i, j); | ||
| t_assert(fabs(k.x - 0.0) < DBL_EPSILON, "x component zero"); | ||
| t_assert(fabs(k.y - 0.0) < DBL_EPSILON, "y component zero"); | ||
| t_assert(fabs(k.z - 1.0) < DBL_EPSILON, "z component one"); | ||
| t_assert(fabs(vec3Dot(k, i)) < DBL_EPSILON, "cross is orthogonal to i"); | ||
| t_assert(fabs(vec3Dot(k, j)) < DBL_EPSILON, "cross is orthogonal to j"); | ||
| } | ||
|
|
||
| TEST(normalizeAndMagnitude) { | ||
| Vec3d v = {.x = 3.0, .y = -4.0, .z = 12.0}; | ||
| double magSq = vec3NormSq(v); | ||
| t_assert(fabs(magSq - 169.0) < DBL_EPSILON, | ||
| "magnitude squared matches"); | ||
| t_assert(fabs(vec3Norm(v) - 13.0) < DBL_EPSILON, "magnitude matches"); | ||
|
|
||
| vec3Normalize(&v); | ||
| t_assert(fabs(vec3Norm(v) - 1.0) < DBL_EPSILON, | ||
| "normalized vector is unit"); | ||
|
|
||
| Vec3d zero = {.x = 0.0, .y = 0.0, .z = 0.0}; | ||
| vec3Normalize(&zero); | ||
| t_assert(zero.x == 0.0 && zero.y == 0.0 && zero.z == 0.0, | ||
| "zero vector remains unchanged when normalizing"); | ||
| } | ||
|
|
||
| TEST(distance) { | ||
| Vec3d a = {.x = 0.0, .y = 0.0, .z = 0.0}; | ||
| Vec3d b = {.x = 1.0, .y = 2.0, .z = 2.0}; | ||
| t_assert(fabs(vec3DistSq(a, b) - 9.0) < DBL_EPSILON, | ||
| "distance squared matches"); | ||
| } | ||
|
|
||
| TEST(latLngToVec3_unitSphere) { | ||
| LatLng geo = {.lat = 0.5, .lng = -1.3}; | ||
| Vec3d v = latLngToVec3(geo); | ||
| t_assert(fabs(vec3Norm(v) - 1.0) < DBL_EPSILON, | ||
| "converted vector lives on the unit sphere"); | ||
| } | ||
|
|
||
| TEST(vec3ToCell_invalidRes) { | ||
| Vec3d v = {.x = 1.0, .y = 0.0, .z = 0.0}; | ||
| H3Index out; | ||
| t_assert(vec3ToCell(&v, -1, &out) == E_RES_DOMAIN, | ||
| "negative resolution is rejected"); | ||
| t_assert(vec3ToCell(&v, 16, &out) == E_RES_DOMAIN, | ||
| "resolution above max is rejected"); | ||
| } | ||
|
|
||
| TEST(cellToVec3_unitSphere) { | ||
| // cellToVec3 should return a point on the unit sphere. | ||
| LatLng p = {.lat = 0.6, .lng = -1.2}; | ||
| H3Index h; | ||
| t_assertSuccess(H3_EXPORT(latLngToCell)(&p, 5, &h)); | ||
|
|
||
| Vec3d v; | ||
| t_assertSuccess(cellToVec3(h, &v)); | ||
| t_assert(fabs(vec3Norm(v) - 1.0) < DBL_EPSILON, | ||
| "cellToVec3 result is on the unit sphere"); | ||
| } | ||
|
|
||
| TEST(cellToVec3_matchesCellToLatLng) { | ||
| // vec3ToLatLng(cellToVec3(cell)) should agree with cellToLatLng. | ||
| LatLng p = {.lat = 0.3, .lng = 2.1}; | ||
| H3Index h; | ||
| t_assertSuccess(H3_EXPORT(latLngToCell)(&p, 7, &h)); | ||
|
|
||
| Vec3d v; | ||
| t_assertSuccess(cellToVec3(h, &v)); | ||
| LatLng fromVec3 = vec3ToLatLng(v); | ||
|
|
||
| LatLng fromCell; | ||
| t_assertSuccess(H3_EXPORT(cellToLatLng)(h, &fromCell)); | ||
|
|
||
| t_assert(fabs(fromVec3.lat - fromCell.lat) < DBL_EPSILON, | ||
| "lat matches cellToLatLng"); | ||
| t_assert(fabs(fromVec3.lng - fromCell.lng) < DBL_EPSILON, | ||
| "lng matches cellToLatLng"); | ||
| } | ||
|
|
||
| TEST(cellToVec3_roundTrip) { | ||
| // vec3ToCell(cellToVec3(cell)) should return the same cell. | ||
| LatLng p = {.lat = -0.4, .lng = 0.8}; | ||
| H3Index h; | ||
| t_assertSuccess(H3_EXPORT(latLngToCell)(&p, 9, &h)); | ||
|
|
||
| Vec3d v; | ||
| t_assertSuccess(cellToVec3(h, &v)); | ||
|
|
||
| H3Index h2; | ||
| t_assertSuccess(vec3ToCell(&v, 9, &h2)); | ||
| t_assert(h2 == h, "round-trip through Vec3d returns same cell"); | ||
| } | ||
|
|
||
| TEST(cellToVec3_invalidCell) { | ||
| Vec3d v; | ||
| t_assert(cellToVec3(0x7fffffffffffffff, &v) == E_CELL_INVALID, | ||
| "invalid cell gives E_CELL_INVALID"); | ||
| } | ||
|
|
||
| TEST(vec3ToCell_nonFinite) { | ||
| H3Index out; | ||
| Vec3d nanX = {.x = NAN, .y = 0.0, .z = 0.0}; | ||
| t_assert(vec3ToCell(&nanX, 0, &out) == E_DOMAIN, "NaN x is rejected"); | ||
| Vec3d infY = {.x = 0.0, .y = INFINITY, .z = 0.0}; | ||
| t_assert(vec3ToCell(&infY, 0, &out) == E_DOMAIN, | ||
| "infinite y is rejected"); | ||
| Vec3d infZ = {.x = 0.0, .y = 0.0, .z = -INFINITY}; | ||
| t_assert(vec3ToCell(&infZ, 0, &out) == E_DOMAIN, | ||
| "infinite z is rejected"); | ||
| } | ||
ajfriend marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.