| 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 |
#include <array> |
| 14 |
#include "atlas/util/LonLatMicroDeg.h" |
| 15 |
|
| 16 |
namespace atlas { |
| 17 |
namespace util { |
| 18 |
|
| 19 |
class PeriodicTransform { |
| 20 |
protected: |
| 21 |
double x_translation_; |
| 22 |
|
| 23 |
public: |
| 24 |
PeriodicTransform() { x_translation_ = 360.; } |
| 25 |
PeriodicTransform(const double& translation) { x_translation_ = translation; } |
| 26 |
|
| 27 |
void operator()(double source[2], double dest[2], double direction, double scale = 1.) const { |
| 28 |
dest[0] = source[0] + direction * x_translation_ * scale; |
| 29 |
dest[1] = source[1]; |
| 30 |
} |
| 31 |
|
| 32 |
void operator()(int source[2], int dest[2], int direction, int scale = 1) const { |
| 33 |
dest[0] = source[0] + direction * static_cast<int>(x_translation_ * scale); |
| 34 |
dest[1] = source[1]; |
| 35 |
} |
| 36 |
|
| 37 |
void operator()(double inplace[2], double direction, double scale = 1.) const { |
| 38 |
inplace[0] = inplace[0] + direction * x_translation_ * scale; |
| 39 |
// inplace[1] = inplace[1]; null operation |
| 40 |
} |
| 41 |
|
| 42 |
void operator()(int inplace[2], int direction, int scale = 1) const { |
| 43 |
inplace[0] = inplace[0] + direction * static_cast<int>(x_translation_ * scale); |
| 44 |
// inplace[1] = inplace[1]; null operation |
| 45 |
} |
| 46 |
|
| 47 |
void operator()(util::LonLatMicroDeg& inplace, int direction) const { |
| 48 |
inplace.set_lon(inplace.lon() + direction * util::microdeg(x_translation_)); |
| 49 |
// inplace.set_lat( inplace.lat() ); null operation |
| 50 |
} |
| 51 |
|
| 52 |
void operator()(std::array<double, 2>& inplace) const { |
| 53 |
inplace[0] = inplace[0] + x_translation_; |
| 54 |
// inplace[1] = inplace[1]; null operation |
| 55 |
} |
| 56 |
}; |
| 57 |
|
| 58 |
} // namespace util |
| 59 |
} // namespace atlas |