Skip to content

Commit fd147f6

Browse files
committed
fix: relax half period checks in normalization of longitudes
1 parent 82ef735 commit fd147f6

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

include/boost/geometry/strategies/normalize.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct assign_loop<1, DimensionCount>
123123
template <typename PointIn, typename PointOut, bool IsEquatorial = true>
124124
struct normalize_point
125125
{
126-
static inline void apply(PointIn const& point_in, PointOut& point_out)
126+
static inline void apply(PointIn const& point_in, PointOut& point_out, bool exact = true)
127127
{
128128
using in_coordinate_type = coordinate_type_t<PointIn>;
129129

@@ -135,7 +135,7 @@ struct normalize_point
135135
typename geometry::detail::cs_angular_units<PointIn>::type,
136136
IsEquatorial,
137137
in_coordinate_type
138-
>(longitude, latitude);
138+
>(longitude, latitude, exact);
139139

140140
assign_loop
141141
<
@@ -221,13 +221,13 @@ struct cartesian_box
221221
struct spherical_point
222222
{
223223
template <typename PointIn, typename PointOut>
224-
static inline void apply(PointIn const& point_in, PointOut& point_out)
224+
static inline void apply(PointIn const& point_in, PointOut& point_out, bool exact = true)
225225
{
226226
detail::normalize_point
227227
<
228228
PointIn, PointOut,
229229
(! std::is_same<cs_tag_t<PointIn>, spherical_polar_tag>::value)
230-
>::apply(point_in, point_out);
230+
>::apply(point_in, point_out, exact);
231231
}
232232
};
233233

include/boost/geometry/strategies/spherical/point_in_point.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ class point_point_on_spheroid
7171
typedef typename helper_geometry<Point2>::type helper_point_type2;
7272

7373
helper_point_type1 point1_normalized;
74-
strategy::normalize::spherical_point::apply(point1, point1_normalized);
74+
strategy::normalize::spherical_point::apply(point1, point1_normalized, false);
7575
helper_point_type2 point2_normalized;
76-
strategy::normalize::spherical_point::apply(point2, point2_normalized);
76+
strategy::normalize::spherical_point::apply(point2, point2_normalized, false);
7777

7878
return point_point_generic
7979
<

include/boost/geometry/util/normalize_spheroidal_coordinates.hpp

+21-13
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,22 @@ class normalize_spheroidal_coordinates
236236
}
237237

238238
public:
239-
static inline void apply(CoordinateType& longitude)
239+
static inline void apply(CoordinateType& longitude, bool exact = true)
240240
{
241241
// normalize longitude
242-
if (math::equals(math::abs(longitude), constants::half_period()))
242+
CoordinateType const epsilon = CoordinateType(1e-07);
243+
bool const is_integer = std::numeric_limits<CoordinateType>::is_integer;
244+
245+
if (exact || is_integer ? math::equals(math::abs(longitude), constants::half_period())
246+
: math::abs(math::abs(longitude) - constants::half_period()) <= epsilon)
243247
{
244248
longitude = constants::half_period();
245249
}
246250
else if (longitude > constants::half_period())
247251
{
248252
longitude = normalize_up(longitude);
249-
if (math::equals(longitude, -constants::half_period()))
253+
if (exact || is_integer ? math::equals(longitude, -constants::half_period())
254+
: math::abs(longitude + constants::half_period()) <= epsilon)
250255
{
251256
longitude = constants::half_period();
252257
}
@@ -259,7 +264,8 @@ class normalize_spheroidal_coordinates
259264

260265
static inline void apply(CoordinateType& longitude,
261266
CoordinateType& latitude,
262-
bool normalize_poles = true)
267+
bool normalize_poles = true,
268+
bool exact = true)
263269
{
264270
latitude_convert_if_polar<Units, IsEquatorial>::apply(latitude);
265271

@@ -288,7 +294,7 @@ class normalize_spheroidal_coordinates
288294
#endif // BOOST_GEOMETRY_NORMALIZE_LATITUDE
289295

290296
// normalize longitude
291-
apply(longitude);
297+
apply(longitude, exact);
292298

293299
// finally normalize poles
294300
if (normalize_poles)
@@ -353,22 +359,24 @@ inline void normalize_angle_cond(CoordinateType& angle)
353359
*/
354360
template <typename Units, typename CoordinateType>
355361
inline void normalize_spheroidal_coordinates(CoordinateType& longitude,
356-
CoordinateType& latitude)
362+
CoordinateType& latitude,
363+
bool exact = true)
357364
{
358365
detail::normalize_spheroidal_coordinates
359366
<
360367
Units, CoordinateType
361-
>::apply(longitude, latitude);
368+
>::apply(longitude, latitude, true, exact);
362369
}
363370

364371
template <typename Units, bool IsEquatorial, typename CoordinateType>
365372
inline void normalize_spheroidal_coordinates(CoordinateType& longitude,
366-
CoordinateType& latitude)
373+
CoordinateType& latitude,
374+
bool exact = true)
367375
{
368376
detail::normalize_spheroidal_coordinates
369377
<
370378
Units, CoordinateType, IsEquatorial
371-
>::apply(longitude, latitude);
379+
>::apply(longitude, latitude, true, exact);
372380
}
373381

374382
/*!
@@ -381,12 +389,12 @@ inline void normalize_spheroidal_coordinates(CoordinateType& longitude,
381389
\ingroup utility
382390
*/
383391
template <typename Units, typename CoordinateType>
384-
inline void normalize_longitude(CoordinateType& longitude)
392+
inline void normalize_longitude(CoordinateType& longitude, bool exact = true)
385393
{
386394
detail::normalize_spheroidal_coordinates
387395
<
388396
Units, CoordinateType
389-
>::apply(longitude);
397+
>::apply(longitude, exact);
390398
}
391399

392400
/*!
@@ -400,7 +408,7 @@ inline void normalize_longitude(CoordinateType& longitude)
400408
template <typename Units, typename CoordinateType>
401409
inline void normalize_azimuth(CoordinateType& angle)
402410
{
403-
normalize_longitude<Units, CoordinateType>(angle);
411+
math::normalize_longitude<Units, CoordinateType>(angle, true);
404412
}
405413

406414
/*!
@@ -435,7 +443,7 @@ inline CoordinateType longitude_distance_signed(CoordinateType const& longitude1
435443
CoordinateType const& longitude2)
436444
{
437445
CoordinateType diff = longitude2 - longitude1;
438-
math::normalize_longitude<Units, CoordinateType>(diff);
446+
math::normalize_longitude<Units, CoordinateType>(diff, true);
439447
return diff;
440448
}
441449

test/algorithms/overlay/get_turns_linear_linear_geo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void test_radian()
2424
boost::geometry::strategies::relate::geographic<> wgs84(sph_wgs84);
2525

2626
test_geometry<ls, mls>(
27-
"LINESTRING(0 0, -3.14159265358979 0)",
27+
"LINESTRING(0 0,-3.14159265358979 0)",
2828
"MULTILINESTRING((-2.1467549799530232 -0.12217304763960295,"
2929
"-2.5481807079117185 -0.90757121103705041,"
3030
"-2.6529004630313784 0.85521133347722067,"

test/algorithms/set_operations/difference/difference_linear_linear.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ BOOST_AUTO_TEST_CASE( test_difference_ml_ml_degenerate )
11601160
{
11611161
#ifdef BOOST_GEOMETRY_TEST_DEBUG
11621162
std::cout << std::endl << std::endl << std::endl;
1163-
std::cout << "*** MULTILINESTRING / MULTILINESTRING DIFFERENCE"
1163+
std::cout << "*** MULTILINESTRING / MULTILINESTRING DIFFERENCE"
11641164
<< " (DEGENERATE) ***"
11651165
<< std::endl;
11661166
std::cout << std::endl;
@@ -1247,7 +1247,7 @@ BOOST_AUTO_TEST_CASE( test_difference_ml_ml_spikes )
12471247
{
12481248
#ifdef BOOST_GEOMETRY_TEST_DEBUG
12491249
std::cout << std::endl << std::endl << std::endl;
1250-
std::cout << "*** MULTILINESTRING / MULTILINESTRING DIFFERENCE"
1250+
std::cout << "*** MULTILINESTRING / MULTILINESTRING DIFFERENCE"
12511251
<< " (WITH SPIKES) ***"
12521252
<< std::endl;
12531253
std::cout << std::endl;
@@ -1452,7 +1452,7 @@ BOOST_AUTO_TEST_CASE( test_difference_ls_mls_geo_rad )
14521452
bg::srs::spheroid<double> sph_wgs84(6378137.0, 6356752.3142451793);
14531453
boost::geometry::strategy::intersection::geographic_segments<> wgs84(sph_wgs84);
14541454

1455-
ls g1 = from_wkt<ls>("LINESTRING(0 0, -3.14159265358979 0)");
1455+
ls g1 = from_wkt<ls>("LINESTRING(0 0,-3.14159265358979 0)");
14561456
mls g2 = from_wkt<mls>("MULTILINESTRING((-2.1467549799530232 -0.12217304763960295,"
14571457
"-2.5481807079117185 -0.90757121103705041,"
14581458
"-2.6529004630313784 0.85521133347722067,"

0 commit comments

Comments
 (0)