Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d2654a9

Browse files
committedFeb 12, 2020
Readability improved
1 parent d1f75d3 commit d2654a9

12 files changed

+672
-673
lines changed
 

‎README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ C++ Geometry Library provides utility functions for the computation of geometric
2424

2525
* [Spherical](https://developers.google.com/maps/documentation/javascript/reference#spherical) contains spherical geometry utilities allowing you to compute angles, distances and areas from latitudes and longitudes.
2626
* [Poly](https://developers.google.com/maps/documentation/javascript/reference#poly) utility functions for computations involving polygons and polylines.
27-
* [Encoding](https://developers.google.com/maps/documentation/javascript/reference#encoding) utilities for polyline encoding and decoding.
2827

2928
## Usage
3029

@@ -66,9 +65,9 @@ int main() {
6665

6766
### PolyUtil class
6867

69-
* [`containsLocation(LatLng point, LatLngList polygon, bool geodesic = false)`](#containsLocation)
70-
* [`isLocationOnEdge(LatLng point, LatLngList polygon, double tolerance = PolyUtil::DEFAULT_TOLERANCE, bool geodesic = true)`](#isLocationOnEdge)
71-
* [`isLocationOnPath(LatLng point, LatLngList polyline, double tolerance = PolyUtil::DEFAULT_TOLERANCE, bool geodesic = true)`](#isLocationOnPath)
68+
* [`containsLocation(LatLng point, LatLngList polygon, bool geodesic)`](#containsLocation)
69+
* [`isLocationOnEdge(LatLng point, LatLngList polygon, double tolerance, bool geodesic)`](#isLocationOnEdge)
70+
* [`isLocationOnPath(LatLng point, LatLngList polyline, double tolerance, bool geodesic)`](#isLocationOnPath)
7271
* [`distanceToLine(LatLng point, LatLng start, LatLng end)`](#distanceToLine)
7372

7473
### SphericalUtil class
@@ -360,6 +359,5 @@ assert(SphericalUtil::computeSignedArea(path) == -SphericalUtil::computeSignedAr
360359

361360
## License
362361

363-
Geometry Library Google Maps API V3 is released under the MIT License. See the bundled
364-
[LICENSE](https://github.com/alexpechkarev/geometry-library/blob/master/LICENSE)
365-
file for details.
362+
Geometry Library Google Maps API V3 is released under the MIT License.
363+
See the bundled [LICENSE](https://github.com/alexpechkarev/geometry-library/blob/master/LICENSE) file for details.

‎include/LatLng.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
class LatLng {
2020
public:
21-
double lat; // The latitude of this location
22-
double lng; // The longitude of this location
21+
double lat; // The latitude of this location
22+
double lng; // The longitude of this location
2323

2424
/**
2525
* Constructs a location with a latitude/longitude pair.
@@ -30,10 +30,14 @@ class LatLng {
3030
LatLng(double lat, double lng)
3131
: lat(lat), lng(lng) {}
3232

33-
bool operator==(const LatLng& other) {
34-
return isCoordinateEqual(lat, other.lat) &&
33+
LatLng(const LatLng & point) = default;
34+
35+
LatLng& operator=(const LatLng & other) = default;
36+
37+
bool operator==(const LatLng & other) {
38+
return isCoordinateEqual(lat, other.lat) &&
3539
isCoordinateEqual(lng, other.lng);
36-
}
40+
}
3741

3842

3943
private:

‎include/MathUtil.hpp

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -21,104 +21,104 @@
2121
#define M_PI 3.14159265358979323846
2222

2323
inline double deg2rad(double degrees) {
24-
return degrees * M_PI / 180.0;
24+
return degrees * M_PI / 180.0;
2525
}
2626

2727
inline double rad2deg(double angle) {
28-
return angle * 180.0 / M_PI;
28+
return angle * 180.0 / M_PI;
2929
}
3030

3131
class MathUtil {
3232
public:
33-
/**
34-
* The earth's radius, in meters.
35-
* Mean radius as defined by IUGG.
36-
*/
37-
static constexpr double EARTH_RADIUS = 6371009.0;
38-
39-
/**
40-
* Restrict x to the range [low, high].
41-
*/
42-
static inline double clamp(double x, double low, double high) {
43-
return x < low ? low : (x > high ? high : x);
44-
}
45-
46-
/**
47-
* Wraps the given value into the inclusive-exclusive interval between min and max.
48-
* @param n The value to wrap.
49-
* @param min The minimum.
50-
* @param max The maximum.
51-
*/
52-
static inline double wrap(double n, double min, double max) {
53-
return (n >= min && n < max) ? n : (MathUtil::mod(n - min, max - min) + min);
54-
}
55-
56-
/**
57-
* Returns the non-negative remainder of x / m.
58-
* @param x The operand.
59-
* @param m The modulus.
60-
*/
61-
static inline double mod(double x, double m) {
62-
return remainder(remainder(x, m) + m, m);
63-
}
64-
65-
/**
66-
* Returns mercator Y corresponding to latitude.
67-
* See http://en.wikipedia.org/wiki/Mercator_projection .
68-
*/
69-
static inline double mercator(double lat) {
70-
return log(tan(lat * 0.5 + M_PI / 4.0));
71-
}
72-
73-
/**
74-
* Returns latitude from mercator Y.
75-
*/
76-
static inline double inverseMercator(double y) {
77-
return 2.0 * atan(exp(y)) - M_PI / 2.0;
78-
}
79-
80-
/**
81-
* Returns haversine(angle-in-radians).
82-
* hav(x) == (1 - cos(x)) / 2 == sin(x / 2)^2.
83-
*/
84-
static inline double hav(double x) {
85-
double sinHalf = sin(x * 0.5);
86-
return sinHalf * sinHalf;
87-
}
88-
89-
/**
90-
* Computes inverse haversine. Has good numerical stability around 0.
91-
* arcHav(x) == acos(1 - 2 * x) == 2 * asin(sqrt(x)).
92-
* The argument must be in [0, 1], and the result is positive.
93-
*/
94-
static inline double arcHav(double x) {
95-
return 2.0 * asin(sqrt(x));
96-
}
97-
98-
// Given h==hav(x), returns sin(abs(x)).
99-
static inline double sinFromHav(double h) {
100-
return 2.0 * sqrt(h * (1.0 - h));
101-
}
102-
103-
// Returns hav(asin(x)).
104-
static inline double havFromSin(double x) {
105-
double x2 = x * x;
106-
return x2 / (1.0 + sqrt(1.0 - x2)) * 0.5;
107-
}
108-
109-
// Returns sin(arcHav(x) + arcHav(y)).
110-
static inline double sinSumFromHav(double x, double y) {
111-
double a = sqrt(x * (1 - x));
112-
double b = sqrt(y * (1 - y));
113-
return 2.0 * (a + b - 2 * (a * y + b * x));
114-
}
115-
116-
/**
117-
* Returns hav() of distance from (lat1, lng1) to (lat2, lng2) on the unit sphere.
118-
*/
119-
static inline double havDistance(double lat1, double lat2, double dLng) {
120-
return MathUtil::hav(lat1 - lat2) + MathUtil::hav(dLng) * cos(lat1) * cos(lat2);
121-
}
33+
/**
34+
* The earth's radius, in meters.
35+
* Mean radius as defined by IUGG.
36+
*/
37+
static constexpr double EARTH_RADIUS = 6371009.0;
38+
39+
/**
40+
* Restrict x to the range [low, high].
41+
*/
42+
static inline double clamp(double x, double low, double high) {
43+
return x < low ? low : (x > high ? high : x);
44+
}
45+
46+
/**
47+
* Wraps the given value into the inclusive-exclusive interval between min and max.
48+
* @param n The value to wrap.
49+
* @param min The minimum.
50+
* @param max The maximum.
51+
*/
52+
static inline double wrap(double n, double min, double max) {
53+
return (n >= min && n < max) ? n : (MathUtil::mod(n - min, max - min) + min);
54+
}
55+
56+
/**
57+
* Returns the non-negative remainder of x / m.
58+
* @param x The operand.
59+
* @param m The modulus.
60+
*/
61+
static inline double mod(double x, double m) {
62+
return remainder(remainder(x, m) + m, m);
63+
}
64+
65+
/**
66+
* Returns mercator Y corresponding to latitude.
67+
* See http://en.wikipedia.org/wiki/Mercator_projection .
68+
*/
69+
static inline double mercator(double lat) {
70+
return log(tan(lat * 0.5 + M_PI / 4.0));
71+
}
72+
73+
/**
74+
* Returns latitude from mercator Y.
75+
*/
76+
static inline double inverseMercator(double y) {
77+
return 2.0 * atan(exp(y)) - M_PI / 2.0;
78+
}
79+
80+
/**
81+
* Returns haversine(angle-in-radians).
82+
* hav(x) == (1 - cos(x)) / 2 == sin(x / 2)^2.
83+
*/
84+
static inline double hav(double x) {
85+
double sinHalf = sin(x * 0.5);
86+
return sinHalf * sinHalf;
87+
}
88+
89+
/**
90+
* Computes inverse haversine. Has good numerical stability around 0.
91+
* arcHav(x) == acos(1 - 2 * x) == 2 * asin(sqrt(x)).
92+
* The argument must be in [0, 1], and the result is positive.
93+
*/
94+
static inline double arcHav(double x) {
95+
return 2.0 * asin(sqrt(x));
96+
}
97+
98+
// Given h==hav(x), returns sin(abs(x)).
99+
static inline double sinFromHav(double h) {
100+
return 2.0 * sqrt(h * (1.0 - h));
101+
}
102+
103+
// Returns hav(asin(x)).
104+
static inline double havFromSin(double x) {
105+
double x2 = x * x;
106+
return x2 / (1.0 + sqrt(1.0 - x2)) * 0.5;
107+
}
108+
109+
// Returns sin(arcHav(x) + arcHav(y)).
110+
static inline double sinSumFromHav(double x, double y) {
111+
double a = sqrt(x * (1 - x));
112+
double b = sqrt(y * (1 - y));
113+
return 2.0 * (a + b - 2 * (a * y + b * x));
114+
}
115+
116+
/**
117+
* Returns hav() of distance from (lat1, lng1) to (lat2, lng2) on the unit sphere.
118+
*/
119+
static inline double havDistance(double lat1, double lat2, double dLng) {
120+
return MathUtil::hav(lat1 - lat2) + MathUtil::hav(dLng) * cos(lat1) * cos(lat2);
121+
}
122122
};
123123

124124
#endif // GEOMETRY_LIBRARY_MATH_UTIL

‎include/PolyUtil.hpp

Lines changed: 271 additions & 271 deletions
Large diffs are not rendered by default.

‎include/SphericalUtil.hpp

Lines changed: 215 additions & 215 deletions
Large diffs are not rendered by default.

‎tests/SphericalUtil/computeAngleBetween.hpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@ TEST(SphericalUtil, computeAngleBetween) {
1111
LatLng back = { 0.0, -180.0 };
1212
LatLng left = { 0.0, -90.0 };
1313

14-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(up, up), 0, 1e-6);
15-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(down, down), 0, 1e-6);
16-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(left, left), 0, 1e-6);
17-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(right, right), 0, 1e-6);
18-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(front, front), 0, 1e-6);
19-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(back, back), 0, 1e-6);
20-
21-
// Adjacent vertices
22-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(up, front), M_PI / 2, 1e-6);
23-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(up, right), M_PI / 2, 1e-6);
24-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(up, back), M_PI / 2, 1e-6);
25-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(up, left), M_PI / 2, 1e-6);
26-
27-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(down, front), M_PI / 2, 1e-6);
28-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(down, right), M_PI / 2, 1e-6);
29-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(down, back), M_PI / 2, 1e-6);
30-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(down, left), M_PI / 2, 1e-6);
31-
32-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(back, up), M_PI / 2, 1e-6);
33-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(back, right), M_PI / 2, 1e-6);
34-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(back, down), M_PI / 2, 1e-6);
35-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(back, left), M_PI / 2, 1e-6);
36-
37-
// Opposite vertices
38-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(up, down), M_PI, 1e-6);
39-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(front, back), M_PI, 1e-6);
40-
EXPECT_NEAR(SphericalUtil::computeAngleBetween(left, right), M_PI, 1e-6);
14+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(up, up), 0, 1e-6);
15+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(down, down), 0, 1e-6);
16+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(left, left), 0, 1e-6);
17+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(right, right), 0, 1e-6);
18+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(front, front), 0, 1e-6);
19+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(back, back), 0, 1e-6);
20+
21+
// Adjacent vertices
22+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(up, front), M_PI / 2, 1e-6);
23+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(up, right), M_PI / 2, 1e-6);
24+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(up, back), M_PI / 2, 1e-6);
25+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(up, left), M_PI / 2, 1e-6);
26+
27+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(down, front), M_PI / 2, 1e-6);
28+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(down, right), M_PI / 2, 1e-6);
29+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(down, back), M_PI / 2, 1e-6);
30+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(down, left), M_PI / 2, 1e-6);
31+
32+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(back, up), M_PI / 2, 1e-6);
33+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(back, right), M_PI / 2, 1e-6);
34+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(back, down), M_PI / 2, 1e-6);
35+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(back, left), M_PI / 2, 1e-6);
36+
37+
// Opposite vertices
38+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(up, down), M_PI, 1e-6);
39+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(front, back), M_PI, 1e-6);
40+
EXPECT_NEAR(SphericalUtil::computeAngleBetween(left, right), M_PI, 1e-6);
4141
}

‎tests/SphericalUtil/computeArea.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55

66
TEST(SphericalUtil, computeArea) {
7-
LatLng up = { 90.0, 0.0 };
8-
LatLng down = {-90.0, 0.0 };
9-
LatLng front = { 0.0, 0.0 };
10-
LatLng right = { 0.0, 90.0 };
11-
LatLng back = { 0.0, -180.0 };
12-
LatLng left = { 0.0, -90.0 };
7+
LatLng up = { 90.0, 0.0 };
8+
LatLng down = {-90.0, 0.0 };
9+
LatLng front = { 0.0, 0.0 };
10+
LatLng right = { 0.0, 90.0 };
1311

1412
std::vector<LatLng> first = { right, up, front, down, right };
1513
EXPECT_NEAR(SphericalUtil::computeArea(first), M_PI * MathUtil::EARTH_RADIUS * MathUtil::EARTH_RADIUS, .4);

‎tests/SphericalUtil/computeDistanceBetween.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55

66
TEST(SphericalUtil, computeDistanceBetween) {
7-
LatLng up = { 90.0, 0.0};
8-
LatLng down = {-90.0, 0.0};
7+
LatLng up = { 90.0, 0.0};
8+
LatLng down = {-90.0, 0.0};
99

10-
EXPECT_NEAR(SphericalUtil::computeDistanceBetween(up, down), M_PI * MathUtil::EARTH_RADIUS, 1e-6);
10+
EXPECT_NEAR(SphericalUtil::computeDistanceBetween(up, down), M_PI * MathUtil::EARTH_RADIUS, 1e-6);
1111
}

‎tests/SphericalUtil/computeHeading.hpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ TEST(SphericalUtil, computeHeading) {
1111
LatLng back = { 0.0, -180.0 };
1212
LatLng left = { 0.0, -90.0 };
1313

14-
// Opposing vertices for which there is a result
15-
EXPECT_NEAR(SphericalUtil::computeHeading(up, down), -180, 1e-6);
16-
EXPECT_NEAR(SphericalUtil::computeHeading(down, up), 0, 1e-6);
17-
18-
// Adjacent vertices for which there is a result
19-
EXPECT_NEAR(SphericalUtil::computeHeading(front, up), 0, 1e-6);
20-
EXPECT_NEAR(SphericalUtil::computeHeading(right, up), 0, 1e-6);
21-
EXPECT_NEAR(SphericalUtil::computeHeading(back, up), 0, 1e-6);
22-
EXPECT_NEAR(SphericalUtil::computeHeading(down, up), 0, 1e-6);
23-
24-
EXPECT_NEAR(SphericalUtil::computeHeading(front, down), -180, 1e-6);
25-
EXPECT_NEAR(SphericalUtil::computeHeading(right, down), -180, 1e-6);
26-
EXPECT_NEAR(SphericalUtil::computeHeading(back, down), -180, 1e-6);
27-
EXPECT_NEAR(SphericalUtil::computeHeading(left, down), -180, 1e-6);
28-
29-
EXPECT_NEAR(SphericalUtil::computeHeading(right, front), -90, 1e-6);
30-
EXPECT_NEAR(SphericalUtil::computeHeading(left, front), 90, 1e-6);
31-
32-
EXPECT_NEAR(SphericalUtil::computeHeading(front, right), 90, 1e-6);
33-
EXPECT_NEAR(SphericalUtil::computeHeading(back, right), -90, 1e-6);
14+
// Opposing vertices for which there is a result
15+
EXPECT_NEAR(SphericalUtil::computeHeading(up, down), -180, 1e-6);
16+
EXPECT_NEAR(SphericalUtil::computeHeading(down, up), 0, 1e-6);
17+
18+
// Adjacent vertices for which there is a result
19+
EXPECT_NEAR(SphericalUtil::computeHeading(front, up), 0, 1e-6);
20+
EXPECT_NEAR(SphericalUtil::computeHeading(right, up), 0, 1e-6);
21+
EXPECT_NEAR(SphericalUtil::computeHeading(back, up), 0, 1e-6);
22+
EXPECT_NEAR(SphericalUtil::computeHeading(down, up), 0, 1e-6);
23+
24+
EXPECT_NEAR(SphericalUtil::computeHeading(front, down), -180, 1e-6);
25+
EXPECT_NEAR(SphericalUtil::computeHeading(right, down), -180, 1e-6);
26+
EXPECT_NEAR(SphericalUtil::computeHeading(back, down), -180, 1e-6);
27+
EXPECT_NEAR(SphericalUtil::computeHeading(left, down), -180, 1e-6);
28+
29+
EXPECT_NEAR(SphericalUtil::computeHeading(right, front), -90, 1e-6);
30+
EXPECT_NEAR(SphericalUtil::computeHeading(left, front), 90, 1e-6);
31+
32+
EXPECT_NEAR(SphericalUtil::computeHeading(front, right), 90, 1e-6);
33+
EXPECT_NEAR(SphericalUtil::computeHeading(back, right), -90, 1e-6);
3434
}

‎tests/SphericalUtil/computeOffset.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#define EXPECT_NEAR_LatLan(actual, expected) \
66
EXPECT_NEAR(actual.lat, expected.lat, 1e-6);
77
// Issue #2
8-
// Account for the convergence of longitude lines at the poles
9-
// double cosLat = cos(deg2rad(actual.lat));
10-
// EXPECT_NEAR(cosLat * actual.lng, cosLat * expected.lng, 1e-6);
8+
// Account for the convergence of longitude lines at the poles
9+
// double cosLat = cos(deg2rad(actual.lat));
10+
// EXPECT_NEAR(cosLat * actual.lng, cosLat * expected.lng, 1e-6);
1111

1212
TEST(SphericalUtil, computeOffset) {
1313
LatLng up = { 90.0, 0.0 };
@@ -17,22 +17,22 @@ TEST(SphericalUtil, computeOffset) {
1717
LatLng back = { 0.0, -180.0 };
1818
LatLng left = { 0.0, -90.0 };
1919

20-
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffset(front, 0, 0));
21-
EXPECT_NEAR_LatLan(up, SphericalUtil::computeOffset(front, M_PI * MathUtil::EARTH_RADIUS / 2, 0));
20+
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffset(front, 0, 0));
21+
EXPECT_NEAR_LatLan(up, SphericalUtil::computeOffset(front, M_PI * MathUtil::EARTH_RADIUS / 2, 0));
2222
EXPECT_NEAR_LatLan(down, SphericalUtil::computeOffset(front, M_PI * MathUtil::EARTH_RADIUS / 2, 180));
23-
EXPECT_NEAR_LatLan(left, SphericalUtil::computeOffset(front, M_PI * MathUtil::EARTH_RADIUS / 2, -90));
23+
EXPECT_NEAR_LatLan(left, SphericalUtil::computeOffset(front, M_PI * MathUtil::EARTH_RADIUS / 2, -90));
2424
EXPECT_NEAR_LatLan(right, SphericalUtil::computeOffset(front, M_PI * MathUtil::EARTH_RADIUS / 2, 90));
2525
EXPECT_NEAR_LatLan(back, SphericalUtil::computeOffset(front, M_PI * MathUtil::EARTH_RADIUS, 0));
2626
EXPECT_NEAR_LatLan(back, SphericalUtil::computeOffset(front, M_PI * MathUtil::EARTH_RADIUS, 90));
2727

28-
// From left
29-
EXPECT_NEAR_LatLan(left, SphericalUtil::computeOffset(left, 0, 0));
30-
EXPECT_NEAR_LatLan(up, SphericalUtil::computeOffset(left, M_PI * MathUtil::EARTH_RADIUS / 2, 0));
31-
EXPECT_NEAR_LatLan(down, SphericalUtil::computeOffset(left, M_PI * MathUtil::EARTH_RADIUS / 2, 180));
32-
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffset(left, M_PI * MathUtil::EARTH_RADIUS / 2, 90));
33-
EXPECT_NEAR_LatLan(back, SphericalUtil::computeOffset(left, M_PI * MathUtil::EARTH_RADIUS / 2, -90));
34-
EXPECT_NEAR_LatLan(right, SphericalUtil::computeOffset(left, M_PI * MathUtil::EARTH_RADIUS, 0));
35-
EXPECT_NEAR_LatLan(right, SphericalUtil::computeOffset(left, M_PI * MathUtil::EARTH_RADIUS, 90));
28+
// From left
29+
EXPECT_NEAR_LatLan(left, SphericalUtil::computeOffset(left, 0, 0));
30+
EXPECT_NEAR_LatLan(up, SphericalUtil::computeOffset(left, M_PI * MathUtil::EARTH_RADIUS / 2, 0));
31+
EXPECT_NEAR_LatLan(down, SphericalUtil::computeOffset(left, M_PI * MathUtil::EARTH_RADIUS / 2, 180));
32+
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffset(left, M_PI * MathUtil::EARTH_RADIUS / 2, 90));
33+
EXPECT_NEAR_LatLan(back, SphericalUtil::computeOffset(left, M_PI * MathUtil::EARTH_RADIUS / 2, -90));
34+
EXPECT_NEAR_LatLan(right, SphericalUtil::computeOffset(left, M_PI * MathUtil::EARTH_RADIUS, 0));
35+
EXPECT_NEAR_LatLan(right, SphericalUtil::computeOffset(left, M_PI * MathUtil::EARTH_RADIUS, 90));
3636

37-
// NOTE: Heading is undefined at the poles, so we do not test from up/down.
37+
// NOTE: Heading is undefined at the poles, so we do not test from up/down.
3838
}

‎tests/SphericalUtil/computeOffsetOrigin.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
TEST(SphericalUtil, computeOffsetOrigin) {
1414
LatLng front = { 0.0, 0.0 };
1515

16-
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffsetOrigin(front, 0, 0));
16+
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffsetOrigin(front, 0, 0));
1717

18-
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffsetOrigin(LatLng( 0, 45), M_PI * MathUtil::EARTH_RADIUS / 4, 90));
19-
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffsetOrigin(LatLng( 0, -45), M_PI * MathUtil::EARTH_RADIUS / 4, -90));
20-
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffsetOrigin(LatLng( 45, 0), M_PI * MathUtil::EARTH_RADIUS / 4, 0));
21-
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffsetOrigin(LatLng(-45, 0), M_PI * MathUtil::EARTH_RADIUS / 4, 180));
18+
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffsetOrigin(LatLng( 0, 45), M_PI * MathUtil::EARTH_RADIUS / 4, 90));
19+
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffsetOrigin(LatLng( 0, -45), M_PI * MathUtil::EARTH_RADIUS / 4, -90));
20+
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffsetOrigin(LatLng( 45, 0), M_PI * MathUtil::EARTH_RADIUS / 4, 0));
21+
EXPECT_NEAR_LatLan(front, SphericalUtil::computeOffsetOrigin(LatLng(-45, 0), M_PI * MathUtil::EARTH_RADIUS / 4, 180));
2222

2323
// Issue #3
24-
// Situations with no solution, should return null.
25-
//
26-
// First 'over' the pole.
27-
// EXPECT_NULL(SphericalUtil::computeOffsetOrigin(LatLng(80, 0), M_PI * MathUtil::EARTH_RADIUS / 4, 180));
28-
29-
// Second a distance that doesn't fit on the earth.
30-
// EXPECT_NULL(SphericalUtil::computeOffsetOrigin(LatLng(80, 0), M_PI * MathUtil::EARTH_RADIUS / 4, 90));
24+
// Situations with no solution, should return null.
25+
//
26+
// First 'over' the pole.
27+
// EXPECT_NULL(SphericalUtil::computeOffsetOrigin(LatLng(80, 0), M_PI * MathUtil::EARTH_RADIUS / 4, 180));
28+
29+
// Second a distance that doesn't fit on the earth.
30+
// EXPECT_NULL(SphericalUtil::computeOffsetOrigin(LatLng(80, 0), M_PI * MathUtil::EARTH_RADIUS / 4, 90));
3131
}

‎tests/SphericalUtil/interpolate.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ TEST(SphericalUtil, interpolate) {
1515
LatLng up = { 90.0, 0.0 };
1616
LatLng down = {-90.0, 0.0 };
1717
LatLng front = { 0.0, 0.0 };
18-
LatLng right = { 0.0, 90.0 };
1918
LatLng back = { 0.0, -180.0 };
2019
LatLng left = { 0.0, -90.0 };
2120

0 commit comments

Comments
 (0)
Please sign in to comment.