@@ -236,17 +236,22 @@ class normalize_spheroidal_coordinates
236
236
}
237
237
238
238
public:
239
- static inline void apply (CoordinateType& longitude)
239
+ static inline void apply (CoordinateType& longitude, bool exact = true )
240
240
{
241
241
// 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)
243
247
{
244
248
longitude = constants::half_period ();
245
249
}
246
250
else if (longitude > constants::half_period ())
247
251
{
248
252
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)
250
255
{
251
256
longitude = constants::half_period ();
252
257
}
@@ -259,7 +264,8 @@ class normalize_spheroidal_coordinates
259
264
260
265
static inline void apply (CoordinateType& longitude,
261
266
CoordinateType& latitude,
262
- bool normalize_poles = true )
267
+ bool normalize_poles = true ,
268
+ bool exact = true )
263
269
{
264
270
latitude_convert_if_polar<Units, IsEquatorial>::apply (latitude);
265
271
@@ -288,7 +294,7 @@ class normalize_spheroidal_coordinates
288
294
#endif // BOOST_GEOMETRY_NORMALIZE_LATITUDE
289
295
290
296
// normalize longitude
291
- apply (longitude);
297
+ apply (longitude, exact );
292
298
293
299
// finally normalize poles
294
300
if (normalize_poles)
@@ -353,22 +359,24 @@ inline void normalize_angle_cond(CoordinateType& angle)
353
359
*/
354
360
template <typename Units, typename CoordinateType>
355
361
inline void normalize_spheroidal_coordinates (CoordinateType& longitude,
356
- CoordinateType& latitude)
362
+ CoordinateType& latitude,
363
+ bool exact = true )
357
364
{
358
365
detail::normalize_spheroidal_coordinates
359
366
<
360
367
Units, CoordinateType
361
- >::apply (longitude, latitude);
368
+ >::apply (longitude, latitude, true , exact );
362
369
}
363
370
364
371
template <typename Units, bool IsEquatorial, typename CoordinateType>
365
372
inline void normalize_spheroidal_coordinates (CoordinateType& longitude,
366
- CoordinateType& latitude)
373
+ CoordinateType& latitude,
374
+ bool exact = true )
367
375
{
368
376
detail::normalize_spheroidal_coordinates
369
377
<
370
378
Units, CoordinateType, IsEquatorial
371
- >::apply (longitude, latitude);
379
+ >::apply (longitude, latitude, true , exact );
372
380
}
373
381
374
382
/* !
@@ -381,12 +389,12 @@ inline void normalize_spheroidal_coordinates(CoordinateType& longitude,
381
389
\ingroup utility
382
390
*/
383
391
template <typename Units, typename CoordinateType>
384
- inline void normalize_longitude (CoordinateType& longitude)
392
+ inline void normalize_longitude (CoordinateType& longitude, bool exact = true )
385
393
{
386
394
detail::normalize_spheroidal_coordinates
387
395
<
388
396
Units, CoordinateType
389
- >::apply (longitude);
397
+ >::apply (longitude, exact );
390
398
}
391
399
392
400
/* !
@@ -400,7 +408,7 @@ inline void normalize_longitude(CoordinateType& longitude)
400
408
template <typename Units, typename CoordinateType>
401
409
inline void normalize_azimuth (CoordinateType& angle)
402
410
{
403
- normalize_longitude<Units, CoordinateType>(angle);
411
+ math:: normalize_longitude<Units, CoordinateType>(angle, true );
404
412
}
405
413
406
414
/* !
@@ -435,7 +443,7 @@ inline CoordinateType longitude_distance_signed(CoordinateType const& longitude1
435
443
CoordinateType const & longitude2)
436
444
{
437
445
CoordinateType diff = longitude2 - longitude1;
438
- math::normalize_longitude<Units, CoordinateType>(diff);
446
+ math::normalize_longitude<Units, CoordinateType>(diff, true );
439
447
return diff;
440
448
}
441
449
0 commit comments