-
Notifications
You must be signed in to change notification settings - Fork 503
Move Vec3d to its own files #67
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2018 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 generateFaceCenterPoint.c | ||
* @brief Generates the faceCenterPoint table | ||
* | ||
* usage: `generateFaceCenterPoint` | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include "faceijk.h" | ||
#include "vec3d.h" | ||
|
||
/** | ||
* Generates and prints the faceCenterPoint table. | ||
*/ | ||
static void generate() { | ||
printf("static const Vec3d faceCenterPoint[NUM_ICOSA_FACES] = {\n"); | ||
for (int i = 0; i < NUM_ICOSA_FACES; i++) { | ||
GeoCoord centerCoords = faceCenterGeo[i]; | ||
Vec3d centerPoint; | ||
_geoToVec3d(¢erCoords, ¢erPoint); | ||
printf(" {%.16f, %.16f, %.16f}, // face %2d\n", centerPoint.x, | ||
centerPoint.y, centerPoint.z, i); | ||
} | ||
printf("};\n"); | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
// check command line args | ||
if (argc > 1) { | ||
fprintf(stderr, "usage: %s\n", argv[0]); | ||
exit(1); | ||
} | ||
|
||
generate(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2018 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. | ||
*/ | ||
|
||
#include <float.h> | ||
#include <math.h> | ||
#include <stdlib.h> | ||
#include "test.h" | ||
#include "vec3d.h" | ||
|
||
BEGIN_TESTS(Vec3d); | ||
|
||
TEST(_pointSquareDist) { | ||
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. Thanks for adding tests! |
||
Vec3d v1 = {0, 0, 0}; | ||
Vec3d v2 = {1, 0, 0}; | ||
Vec3d v3 = {0, 1, 1}; | ||
Vec3d v4 = {1, 1, 1}; | ||
Vec3d v5 = {1, 1, 2}; | ||
|
||
t_assert(fabs(_pointSquareDist(&v1, &v1)) < DBL_EPSILON, | ||
"distance to self is 0"); | ||
t_assert(fabs(_pointSquareDist(&v1, &v2) - 1) < DBL_EPSILON, | ||
"distance to <1,0,0> is 1"); | ||
t_assert(fabs(_pointSquareDist(&v1, &v3) - 2) < DBL_EPSILON, | ||
"distance to <0,1,1> is 2"); | ||
t_assert(fabs(_pointSquareDist(&v1, &v4) - 3) < DBL_EPSILON, | ||
"distance to <1,1,1> is 3"); | ||
t_assert(fabs(_pointSquareDist(&v1, &v5) - 6) < DBL_EPSILON, | ||
"distance to <1,1,2> is 6"); | ||
} | ||
|
||
TEST(_geoToVec3d) { | ||
Vec3d origin = {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. For my info - why not 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. I understand this should be the same as initializing all members to 0, https://stackoverflow.com/questions/11152160/initializing-a-struct-to-0 |
||
|
||
GeoCoord c1 = {0, 0}; | ||
Vec3d p1; | ||
_geoToVec3d(&c1, &p1); | ||
t_assert(fabs(_pointSquareDist(&origin, &p1) - 1) < EPSILON_RAD, | ||
"Geo point is on the unit sphere"); | ||
|
||
GeoCoord c2 = {M_PI_2, 0}; | ||
Vec3d p2; | ||
_geoToVec3d(&c2, &p2); | ||
t_assert(fabs(_pointSquareDist(&p1, &p2) - 2) < EPSILON_RAD, | ||
"Geo point is on another axis"); | ||
|
||
GeoCoord c3 = {M_PI, 0}; | ||
Vec3d p3; | ||
_geoToVec3d(&c3, &p3); | ||
t_assert(fabs(_pointSquareDist(&p1, &p3) - 4) < EPSILON_RAD, | ||
"Geo point is the other side of the sphere"); | ||
} | ||
|
||
END_TESTS(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2018 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 vec3d.h | ||
* @brief 3D floating point vector functions. | ||
*/ | ||
|
||
#ifndef VEC3D_H | ||
#define VEC3D_H | ||
|
||
#include "geoCoord.h" | ||
|
||
/** @struct Vec3D | ||
* @brief 3D floating point structure | ||
*/ | ||
typedef struct { | ||
double x; ///< x component | ||
double y; ///< y component | ||
double z; ///< z component | ||
} Vec3d; | ||
|
||
void _geoToVec3d(const GeoCoord* geo, Vec3d* point); | ||
double _pointSquareDist(const Vec3d* p1, const Vec3d* p2); | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,13 @@ | |
#include "coordijk.h" | ||
#include "geoCoord.h" | ||
#include "h3Index.h" | ||
#include "vec3d.h" | ||
|
||
/** square root of 7 */ | ||
#define M_SQRT7 2.6457513110645905905016157536392604257102L | ||
|
||
/** @brief icosahedron face centers in lat/lon radians */ | ||
static const GeoCoord faceCenterGeo[NUM_ICOSA_FACES] = { | ||
const GeoCoord faceCenterGeo[NUM_ICOSA_FACES] = { | ||
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. For my info: Why drop 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. Static is incompatible with extern, because a static variable would only be visible within the same compilation unit (think .c file) and extern is needed for the generator. 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. You don't need 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. My mistake. Looks good. |
||
{0.803582649718989942, 1.248397419617396099}, // face 0 | ||
{1.307747883455638156, 2.536945009877921159}, // face 1 | ||
{1.054751253523952054, -1.347517358900396623}, // face 2 | ||
|
@@ -60,24 +61,24 @@ static const GeoCoord faceCenterGeo[NUM_ICOSA_FACES] = { | |
static const Vec3d faceCenterPoint[NUM_ICOSA_FACES] = { | ||
{0.2199307791404606, 0.6583691780274996, 0.7198475378926182}, // face 0 | ||
{-0.2139234834501421, 0.1478171829550703, 0.9656017935214205}, // face 1 | ||
{0.1092625278784797, -0.4811951572873209, 0.8697775121287253}, // face 2 | ||
{0.1092625278784797, -0.4811951572873210, 0.8697775121287253}, // face 2 | ||
{0.7428567301586791, -0.3593941678278028, 0.5648005936517033}, // face 3 | ||
{0.8112534709140969, 0.3448953237639384, 0.4721387736413930}, // face 4 | ||
{-0.1055498149613921, 0.9794457296411413, 0.1718874610009365}, // face 5 | ||
{-0.8075407579970092, 0.1533552485898819, 0.5695261994882688}, // face 6 | ||
{-0.8075407579970092, 0.1533552485898818, 0.5695261994882688}, // face 6 | ||
{-0.2846148069787907, -0.8644080972654206, 0.4144792552473539}, // face 7 | ||
{0.7405621473854481, -0.6673299564565524, -0.0789837646326737}, // face 8 | ||
{0.7405621473854482, -0.6673299564565524, -0.0789837646326737}, // face 8 | ||
{0.8512303986474293, 0.4722343788582681, -0.2289137388687808}, // face 9 | ||
{-0.7405621473854481, 0.6673299564565525, 0.0789837646326737}, // face 10 | ||
{-0.7405621473854481, 0.6673299564565524, 0.0789837646326737}, // face 10 | ||
{-0.8512303986474292, -0.4722343788582682, 0.2289137388687808}, // face 11 | ||
{0.1055498149613920, -0.9794457296411413, -0.1718874610009365}, // face 12 | ||
{0.1055498149613919, -0.9794457296411413, -0.1718874610009365}, // face 12 | ||
{0.8075407579970092, -0.1533552485898819, -0.5695261994882688}, // face 13 | ||
{0.2846148069787908, 0.8644080972654204, -0.4144792552473539}, // face 14 | ||
{-0.7428567301586791, 0.3593941678278027, -0.5648005936517033}, // face 15 | ||
{-0.8112534709140971, -0.3448953237639383, -0.4721387736413930}, // face 16 | ||
{-0.8112534709140971, -0.3448953237639382, -0.4721387736413930}, // face 16 | ||
{-0.2199307791404607, -0.6583691780274996, -0.7198475378926182}, // face 17 | ||
{0.2139234834501420, -0.1478171829550704, -0.9656017935214205}, // face 18 | ||
{-0.1092625278784796, 0.4811951572873209, -0.8697775121287253}, // face 19 | ||
{-0.1092625278784796, 0.4811951572873210, -0.8697775121287253}, // face 19 | ||
}; | ||
|
||
/** @brief icosahedron face ijk axes as azimuth in radians from face center to | ||
|
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.
Any need for this block, when the script takes no args?
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.
It just checks that no (unused) args were provided.
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.
Same comment as other review (#69), you can always do
int main(void)
in this case. No need to be "strict" about it.