| 1 |
/* |
| 2 |
* (C) Copyright 2013 ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
/// @file NormaliseLongitude.h |
| 14 |
|
| 15 |
namespace atlas { |
| 16 |
namespace util { |
| 17 |
|
| 18 |
class NormaliseLongitude { |
| 19 |
public: |
| 20 |
// Normalise longitude between (west - eps, east - eps ) with west = 0., east = 360. |
| 21 |
constexpr NormaliseLongitude(): west_(-eps_), east_(360. - eps_) {} |
| 22 |
|
| 23 |
// Normalise longitude between ( west-eps, east-eps ) with east = west + 360 |
| 24 |
constexpr NormaliseLongitude(double west): west_(west - eps_), east_(west + 360. - eps_) {} |
| 25 |
|
| 26 |
// Normalise longitude between ( west-eps, east+eps ) |
| 27 |
constexpr NormaliseLongitude(double west, double east): west_(west - eps_), east_(east + eps_) {} |
| 28 |
|
| 29 |
double operator()(double lon) const { |
| 30 |
while (lon < west_) { |
| 31 |
lon += 360.; |
| 32 |
} |
| 33 |
while (lon > east_) { |
| 34 |
lon -= 360.; |
| 35 |
} |
| 36 |
return lon; |
| 37 |
} |
| 38 |
|
| 39 |
private: |
| 40 |
double west_; |
| 41 |
double east_; |
| 42 |
|
| 43 |
public: |
| 44 |
static constexpr double eps_ = 1.e-11; |
| 45 |
}; |
| 46 |
|
| 47 |
} // namespace util |
| 48 |
} // namespace atlas |