atlas
Point.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 
18 
19 #include <array>
20 #include <initializer_list>
21 
22 #include "eckit/geometry/Point2.h"
23 #include "eckit/geometry/Point3.h"
24 
25 #include "atlas/util/Earth.h"
26 
27 namespace atlas {
28 
29 using Point2 = eckit::geometry::Point2;
30 using Point3 = eckit::geometry::Point3;
31 
32 inline bool operator==( const Point2& p1, const Point2& p2 ) {
33  return eckit::geometry::points_equal( p1, p2 );
34 }
35 inline bool operator!=( const Point2& p1, const Point2& p2 ) {
36  return !eckit::geometry::points_equal( p1, p2 );
37 }
38 
40 class PointXY : public eckit::geometry::Point2 {
41  using array_t = std::array<double, 2>;
42 
43 public:
44  using Point2::Point2;
45 
46  PointXY() : Point2() {}
47 
48  // Allow initialization through PointXY xy = {0,0};
49  PointXY( std::initializer_list<double> list ) : PointXY( list.begin() ) {}
50  PointXY( const array_t& arr ) : PointXY( arr.data() ) {}
51 
52  double x() const { return x_[0]; }
53  double y() const { return x_[1]; }
54  double& x() { return x_[0]; }
55  double& y() { return x_[1]; }
56 
57  using Point2::assign;
58 
59  void assign( double x, double y ) {
60  x_[0] = x;
61  x_[1] = y;
62  }
63 };
64 
66 class PointXYZ : public eckit::geometry::Point3 {
67  using array_t = std::array<double, 3>;
68 
69  PointXYZ( double, double ) { /* No automatic converion allowed, otherwise
70  inherited from Point3 */
71  }
72 
73 public:
74  using Point3::Point3;
75  using Point3::x;
76 
77  PointXYZ() : Point3() {}
78 
79  // Allow initialization through PointXYZ xyz = {0,0,0};
80  PointXYZ( std::initializer_list<double> list ) : PointXYZ( list.begin() ) {}
81 
82  PointXYZ( const array_t& arr ) : PointXYZ( arr.data() ) {}
83 
84  double x() const { return x_[0]; }
85  double y() const { return x_[1]; }
86  double z() const { return x_[2]; }
87  double& x() { return x_[0]; }
88  double& y() { return x_[1]; }
89  double& z() { return x_[2]; }
90 
91  using Point3::assign;
92 
93  void assign( double x, double y, double z ) {
94  x_[0] = x;
95  x_[1] = y;
96  x_[2] = z;
97  }
98 };
99 
103 class PointLonLat : public eckit::geometry::Point2 {
104  using array_t = std::array<double, 2>;
105 
106 public:
107  using Point2::Point2;
108 
109  PointLonLat() : Point2() {}
110 
111  // Allow initialization through PointXY lonlat = {0,0};
112  PointLonLat( std::initializer_list<double> list ) : PointLonLat( list.begin() ) {}
113 
114  PointLonLat( const array_t& arr ) : PointLonLat( arr.data() ) {}
115 
116  double lon() const { return x_[0]; }
117  double lat() const { return x_[1]; }
118  double& lon() { return x_[0]; }
119  double& lat() { return x_[1]; }
120 
121  using Point2::assign;
122 
123  void assign( double lon, double lat ) {
124  x_[0] = lon;
125  x_[1] = lat;
126  }
127 
128  PointLonLat& operator*=( double a ) {
129  x_[0] *= a;
130  x_[1] *= a;
131  return *this;
132  }
133 
134  void normalise();
135 
136  void normalise( double west );
137 
138  void normalise( double west, double east );
139 };
140 
141 } // namespace atlas
142 
143 #ifndef DOXYGEN_SHOULD_SKIP_THIS
144 namespace eckit {
145 // When including "eckit/types/Types.h" we get an overload for
146 // std::ostream& operator<<( std::ostream&, std::vector<T> )
147 // The default VectorPrintSelector is however the [VectorPrintContracted],
148 // which does not compile when [T={PointXY,PointLonLat,PointXYZ}]
149 // Following changes the default for these types to [VectorPrintSimple]
150 class VectorPrintSimple;
151 template <typename T>
153 template <>
154 struct VectorPrintSelector<atlas::Point2> {
155  typedef VectorPrintSimple selector;
156 };
157 template <>
158 struct VectorPrintSelector<atlas::PointXY> {
159  typedef VectorPrintSimple selector;
160 };
161 template <>
162 struct VectorPrintSelector<atlas::PointLonLat> {
163  typedef VectorPrintSimple selector;
164 };
165 template <>
166 struct VectorPrintSelector<atlas::Point3> {
167  typedef VectorPrintSimple selector;
168 };
169 template <>
170 struct VectorPrintSelector<atlas::PointXYZ> {
171  typedef VectorPrintSimple selector;
172 };
173 } // namespace eckit
174 #endif
Point in arbitrary XYZ-coordinate system.
Definition: Point.h:66
Point in longitude-latitude coordinate system.
Definition: Point.h:103
Definition: Domain.h:19
Definition: Point.h:152
Point in arbitrary XY-coordinate system.
Definition: Point.h:40
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33