PolygonArea.hpp
Go to the documentation of this file.
1 
10 #if !defined(GEOGRAPHICLIB_POLYGONAREA_HPP)
11 #define GEOGRAPHICLIB_POLYGONAREA_HPP 1
12 
15 #include <GeographicLib/Rhumb.hpp>
17 
18 namespace GeographicLib {
19 
64  template <class GeodType = Geodesic>
65  class PolygonAreaT {
66  private:
67  typedef Math::real real;
68  GeodType _earth;
69  real _area0; // Full ellipsoid area
70  bool _polyline; // Assume polyline (don't close and skip area)
71  unsigned _mask;
72  unsigned _num;
76  static int transit(real lon1, real lon2) {
77  // Return 1 or -1 if crossing prime meridian in east or west direction.
78  // Otherwise return zero.
79  // Compute lon12 the same way as Geodesic::Inverse.
80  lon1 = Math::AngNormalize(lon1);
81  lon2 = Math::AngNormalize(lon2);
82  real lon12 = Math::AngDiff(lon1, lon2);
83  // Treat 0 as negative in these tests. This balances +/- 180 being
84  // treated as positive, i.e., +180.
85  int cross =
86  lon1 <= 0 && lon2 > 0 && lon12 > 0 ? 1 :
87  (lon2 <= 0 && lon1 > 0 && lon12 < 0 ? -1 : 0);
88  return cross;
89  }
90  // an alternate version of transit to deal with longitudes in the direct
91  // problem.
92  static int transitdirect(real lon1, real lon2) {
93  // We want to compute exactly
94  // int(floor(lon2 / 360)) - int(floor(lon1 / 360))
95  // Since we only need the parity of the result we can use std::remquo;
96  // but this is buggy with g++ 4.8.3 (glibc version < 2.22), see
97  // https://sourceware.org/bugzilla/show_bug.cgi?id=17569
98  // and requires C++11. So instead we do
99 #if GEOGRAPHICLIB_CXX11_MATH && GEOGRAPHICLIB_PRECISION != 4
100  using std::remainder;
101  lon1 = remainder(lon1, real(720)); lon2 = remainder(lon2, real(720));
102  return ( (lon2 >= 0 && lon2 < 360 ? 0 : 1) -
103  (lon1 >= 0 && lon1 < 360 ? 0 : 1) );
104 #else
105  using std::fmod;
106  lon1 = fmod(lon1, real(720)); lon2 = fmod(lon2, real(720));
107  return ( ((lon2 >= 0 && lon2 < 360) || lon2 < -360 ? 0 : 1) -
108  ((lon1 >= 0 && lon1 < 360) || lon1 < -360 ? 0 : 1) );
109 #endif
110  }
111  public:
112 
120  PolygonAreaT(const GeodType& earth, bool polyline = false)
121  : _earth(earth)
122  , _area0(_earth.EllipsoidArea())
123  , _polyline(polyline)
124  , _mask(GeodType::LATITUDE | GeodType::LONGITUDE | GeodType::DISTANCE |
125  (_polyline ? GeodType::NONE :
126  GeodType::AREA | GeodType::LONG_UNROLL))
127  { Clear(); }
128 
132  void Clear() {
133  _num = 0;
134  _crossings = 0;
135  _areasum = 0;
136  _perimetersum = 0;
137  _lat0 = _lon0 = _lat1 = _lon1 = Math::NaN();
138  }
139 
148  void AddPoint(real lat, real lon);
149 
159  void AddEdge(real azi, real s);
160 
177  unsigned Compute(bool reverse, bool sign,
178  real& perimeter, real& area) const;
179 
205  unsigned TestPoint(real lat, real lon, bool reverse, bool sign,
206  real& perimeter, real& area) const;
207 
231  unsigned TestEdge(real azi, real s, bool reverse, bool sign,
232  real& perimeter, real& area) const;
233 
236 
242  Math::real MajorRadius() const { return _earth.MajorRadius(); }
243 
248  Math::real Flattening() const { return _earth.Flattening(); }
249 
259  void CurrentPoint(real& lat, real& lon) const
260  { lat = _lat1; lon = _lon1; }
262  };
263 
271 
280 
287 
288 } // namespace GeographicLib
289 
290 #endif // GEOGRAPHICLIB_POLYGONAREA_HPP
static T AngNormalize(T x)
Definition: Math.hpp:440
static T NaN()
Definition: Math.hpp:830
Math::real Flattening() const
unsigned TestEdge(real azi, real s, bool reverse, bool sign, real &perimeter, real &area) const
static const double lat
PolygonAreaT< Rhumb > PolygonAreaRhumb
static T AngDiff(T x, T y, T &e)
Definition: Math.hpp:486
Header for GeographicLib::Rhumb and GeographicLib::RhumbLine classes.
void AddEdge(real azi, real s)
PolygonAreaT(const GeodType &earth, bool polyline=false)
An accumulator for sums.
Definition: Accumulator.hpp:40
Header for GeographicLib::Geodesic class.
PolygonAreaT< GeodesicExact > PolygonAreaExact
Math::real MajorRadius() const
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmod(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:567
Point3 cross(const Point3 &p, const Point3 &q, OptionalJacobian< 3, 3 > H1, OptionalJacobian< 3, 3 > H2)
cross product
Definition: Point3.cpp:64
Header for GeographicLib::Accumulator class.
EIGEN_DEVICE_FUNC const SignReturnType sign() const
Namespace for GeographicLib.
unsigned TestPoint(real lat, real lon, bool reverse, bool sign, real &perimeter, real &area) const
RealScalar s
unsigned Compute(bool reverse, bool sign, real &perimeter, real &area) const
static int transitdirect(real lon1, real lon2)
Definition: PolygonArea.hpp:92
void AddPoint(real lat, real lon)
void CurrentPoint(real &lat, real &lon) const
Header for GeographicLib::GeodesicExact class.
void reverse(const MatrixType &m)
static const double lon
PolygonAreaT< Geodesic > PolygonArea
static int transit(real lon1, real lon2)
Definition: PolygonArea.hpp:76


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:35:14