Skip to content

Commit ec1dc3e

Browse files
committed
Skip unnecessary, error-introducing longitude normalization on antimeridian-crossing box.
1 parent 0ba089b commit ec1dc3e

4 files changed

Lines changed: 21 additions & 7 deletions

File tree

include/boost/geometry/util/normalize_spheroidal_box_coordinates.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ class normalize_spheroidal_box_coordinates
4949
bool band)
5050
{
5151
normalize::apply(longitude1, latitude1, false);
52-
normalize::apply(longitude2, latitude2, false);
52+
const bool crosses_antimeridian =
53+
longitude2 > longitude1
54+
&& longitude2 > constants::half_period()
55+
&& longitude2 <= constants::period();
56+
normalize::apply(longitude2, latitude2, false, true, crosses_antimeridian);
5357

5458
latitude_convert_if_polar<Units, IsEquatorial>::apply(latitude1);
5559
latitude_convert_if_polar<Units, IsEquatorial>::apply(latitude2);

include/boost/geometry/util/normalize_spheroidal_coordinates.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ class normalize_spheroidal_coordinates
223223
}
224224

225225
public:
226-
static inline void apply(CoordinateType& longitude, bool exact = true)
226+
static inline void apply(CoordinateType& longitude, bool exact = true,
227+
bool allow_antimeridian_crossing = false)
227228
{
228229
// normalize longitude
229230
CoordinateType const epsilon = std::numeric_limits<float>::epsilon();
@@ -234,7 +235,7 @@ class normalize_spheroidal_coordinates
234235
{
235236
longitude = constants::half_period();
236237
}
237-
else if (longitude > constants::half_period())
238+
else if ( ! allow_antimeridian_crossing && longitude > constants::half_period())
238239
{
239240
longitude = normalize_up(longitude);
240241
if (exact || is_integer ? math::equals(longitude, -constants::half_period())
@@ -252,7 +253,8 @@ class normalize_spheroidal_coordinates
252253
static inline void apply(CoordinateType& longitude,
253254
CoordinateType& latitude,
254255
bool normalize_poles = true,
255-
bool exact = true)
256+
bool exact = true,
257+
bool allow_antimeridian_crossing = false)
256258
{
257259
latitude_convert_if_polar<Units, IsEquatorial>::apply(latitude);
258260

@@ -281,7 +283,7 @@ class normalize_spheroidal_coordinates
281283
#endif // BOOST_GEOMETRY_NORMALIZE_LATITUDE
282284

283285
// normalize longitude
284-
apply(longitude, exact);
286+
apply(longitude, exact, allow_antimeridian_crossing);
285287

286288
// finally normalize poles
287289
if (normalize_poles)
@@ -302,7 +304,8 @@ class normalize_spheroidal_coordinates
302304
#endif // BOOST_GEOMETRY_NORMALIZE_LATITUDE
303305

304306
BOOST_GEOMETRY_ASSERT(! math::larger_or_equals(constants::min_longitude(), longitude));
305-
BOOST_GEOMETRY_ASSERT(! math::larger(longitude, constants::max_longitude()));
307+
BOOST_GEOMETRY_ASSERT(! math::larger(longitude, constants::max_longitude())
308+
|| allow_antimeridan_crossing);
306309
}
307310
};
308311

test/algorithms/envelope_expand/expand_on_spheroid.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,13 @@ void test_expand_point()
591591
from_wkt<B>("BOX(10 -90,100 90)"),
592592
from_wkt<G>("POINT(-95 -90)"),
593593
10, -90, 100, 90);
594+
595+
// box crosses anti-meridian and contains point so it should not be changed
596+
tester::apply("p21",
597+
from_wkt<B>("BOX(170 0 190.4 2)"),
598+
from_wkt<G>("POINT(175 1)"),
599+
170, 0, 190.4, 2,
600+
0.0);
594601
}
595602

596603
BOOST_AUTO_TEST_CASE( expand_point )

test/algorithms/envelope_expand/test_envelope_expand_on_spheroid.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ struct box_check_equals
246246
&& (bg::get<0, 1>(box) < 0
247247
? equals(bg::get<0, 1>(box), lat_min)
248248
: equals_with_eps(bg::get<0, 1>(box), lat_min))
249-
&& equals_with_eps(bg::get<1, 0>(box), lon_max)
249+
&& equals(bg::get<1, 0>(box), lon_max)
250250
&& (bg::get<1, 1>(box) > 0
251251
? equals(bg::get<1, 1>(box), lat_max)
252252
: equals_with_eps(bg::get<1, 1>(box), lat_max));

0 commit comments

Comments
 (0)