atlas
NormaliseLongitude.h
Go to the documentation of this file.
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 
14 
15 namespace atlas {
16 namespace util {
17 
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  constexpr NormaliseLongitude( const NormaliseLongitude& other ) : west_( other.west_ ), east_( other.east_ ) {}
30 
31  double operator()( double lon ) const {
32  while ( lon < west_ ) {
33  lon += 360.;
34  }
35  while ( lon > east_ ) {
36  lon -= 360.;
37  }
38  return lon;
39  }
40 
41 private:
42  double west_;
43  double east_;
44 
45 public:
46  static constexpr double eps_ = 1.e-11;
47 };
48 
49 } // namespace util
50 } // namespace atlas
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
Definition: NormaliseLongitude.h:18