| 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 "atlas/array/ArrayView.h" |
| 14 |
#include "atlas/library/config.h" |
| 15 |
#include "atlas/util/CoordinateEnums.h" |
| 16 |
#include "atlas/util/MicroDeg.h" |
| 17 |
#include "atlas/util/Point.h" |
| 18 |
|
| 19 |
namespace atlas { |
| 20 |
namespace util { |
| 21 |
|
| 22 |
// ------------------------------------------------------------------------------------ |
| 23 |
|
| 24 |
// Forward declarations |
| 25 |
class LonLatMicroDeg; |
| 26 |
uidx_t unique_lonlat(const LonLatMicroDeg&); |
| 27 |
|
| 28 |
// ------------------------------------------------------------------------------------ |
| 29 |
|
| 30 |
/// @brief LonLatMicroDegrees |
| 31 |
/// |
| 32 |
/// Data is stored and accessed in microdegrees in int type (32 bits per |
| 33 |
/// coordinate component) |
| 34 |
/// This structure is used to compare 2 lon-lat points in sorting algorithms |
| 35 |
/// or to use in sending in MPI buffers using minimal memory, |
| 36 |
/// The maximum range in degrees is [-2147.48 2147.48] |
| 37 |
class LonLatMicroDeg { |
| 38 |
public: |
| 39 |
// -- Constructors taking already microdegrees |
| 40 |
LonLatMicroDeg(int lonlat[2]) { |
| 41 |
p_[LON] = lonlat[LON]; |
| 42 |
p_[LAT] = lonlat[LAT]; |
| 43 |
} |
| 44 |
LonLatMicroDeg(int lon, int lat) { |
| 45 |
p_[LON] = lon; |
| 46 |
p_[LAT] = lat; |
| 47 |
} |
| 48 |
|
| 49 |
// -- Constructors taking degrees |
| 50 |
LonLatMicroDeg(const double& lon, const double& lat) { |
| 51 |
p_[LON] = microdeg(lon); |
| 52 |
p_[LAT] = microdeg(lat); |
| 53 |
} |
| 54 |
LonLatMicroDeg(const double lonlat[2]) { |
| 55 |
p_[LON] = microdeg(lonlat[LON]); |
| 56 |
p_[LAT] = microdeg(lonlat[LAT]); |
| 57 |
} |
| 58 |
// LonLatMicroDeg( const array::ArrayView<double,1>& lonlat ) { |
| 59 |
// p_[LON]=microdeg(lonlat[LON]); p_[LAT]=microdeg(lonlat[LAT]); } |
| 60 |
LonLatMicroDeg(const PointLonLat& p) { |
| 61 |
p_[LON] = microdeg(p.lon()); |
| 62 |
p_[LAT] = microdeg(p.lat()); |
| 63 |
} |
| 64 |
|
| 65 |
// -- Methods |
| 66 |
int lon() const { return p_[LON]; } |
| 67 |
int lat() const { return p_[LAT]; } |
| 68 |
void set_lon(int lon) { p_[LON] = lon; } |
| 69 |
void set_lat(int lat) { p_[LAT] = lat; } |
| 70 |
const int* data() const { return p_; } |
| 71 |
uidx_t unique() { return unique_lonlat(*this); } |
| 72 |
|
| 73 |
// -- Comparison operator |
| 74 |
bool operator<(const LonLatMicroDeg& other) const; |
| 75 |
|
| 76 |
private: |
| 77 |
int p_[2]; |
| 78 |
}; |
| 79 |
|
| 80 |
// ------------------------------------------------------------------------------------ |
| 81 |
|
| 82 |
inline bool LonLatMicroDeg::operator<(const LonLatMicroDeg& other) const { |
| 83 |
if (p_[LAT] > other.p_[LAT]) |
| 84 |
return true; |
| 85 |
if (p_[LAT] == other.p_[LAT]) |
| 86 |
return (p_[LON] < other.p_[LON]); |
| 87 |
return false; |
| 88 |
} |
| 89 |
|
| 90 |
// ------------------------------------------------------------------------------------ |
| 91 |
|
| 92 |
} // namespace util |
| 93 |
} // namespace atlas |
| 94 |
|
| 95 |
#include "atlas/util/Unique.h" |