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
GeographicLib::Math::AngNormalize
static T AngNormalize(T x)
Definition: Math.hpp:440
GeographicLib::Math::NaN
static T NaN()
Definition: Math.hpp:830
GeographicLib::PolygonAreaT::_lat1
real _lat1
Definition: PolygonArea.hpp:75
GeographicLib::PolygonAreaT::_lat0
real _lat0
Definition: PolygonArea.hpp:75
s
RealScalar s
Definition: level1_cplx_impl.h:126
GeographicLib::PolygonAreaT::Clear
void Clear()
Definition: PolygonArea.hpp:132
GeographicLib
Namespace for GeographicLib.
Definition: JacobiConformal.hpp:15
GeographicLib::PolygonAreaT::Flattening
Math::real Flattening() const
Definition: PolygonArea.hpp:248
GeographicLib::PolygonAreaT::_num
unsigned _num
Definition: PolygonArea.hpp:72
sign
const EIGEN_DEVICE_FUNC SignReturnType sign() const
Definition: ArrayCwiseUnaryOps.h:219
Rhumb.hpp
Header for GeographicLib::Rhumb and GeographicLib::RhumbLine classes.
GeographicLib::PolygonAreaT::PolygonAreaExact
PolygonAreaT< GeodesicExact > PolygonAreaExact
Definition: PolygonArea.hpp:279
GeographicLib::PolygonAreaT::PolygonAreaRhumb
PolygonAreaT< Rhumb > PolygonAreaRhumb
Definition: PolygonArea.hpp:286
GeographicLib::PolygonAreaT::_areasum
Accumulator _areasum
Definition: PolygonArea.hpp:74
GeographicLib::Math::real
double real
Definition: Math.hpp:129
Accumulator.hpp
Header for GeographicLib::Accumulator class.
GeodesicExact.hpp
Header for GeographicLib::GeodesicExact class.
GeographicLib::PolygonAreaT
Polygon areas.
Definition: PolygonArea.hpp:65
GeographicLib::Accumulator
An accumulator for sums.
Definition: Accumulator.hpp:40
Eigen::bfloat16_impl::fmod
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmod(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:567
gtsam::cross
Point3 cross(const Point3 &p, const Point3 &q, OptionalJacobian< 3, 3 > H1, OptionalJacobian< 3, 3 > H2)
cross product
Definition: Point3.cpp:64
GeographicLib::PolygonAreaT::_lon1
real _lon1
Definition: PolygonArea.hpp:75
GeographicLib::Math::AngDiff
static T AngDiff(T x, T y, T &e)
Definition: Math.hpp:486
GeographicLib::PolygonAreaT::transitdirect
static int transitdirect(real lon1, real lon2)
Definition: PolygonArea.hpp:92
GeographicLib::PolygonAreaT::MajorRadius
Math::real MajorRadius() const
Definition: PolygonArea.hpp:242
GeographicLib::PolygonAreaT::AddEdge
void AddEdge(real azi, real s)
Definition: src/PolygonArea.cpp:38
GeographicLib::PolygonAreaT::PolygonAreaT
PolygonAreaT(const GeodType &earth, bool polyline=false)
Definition: PolygonArea.hpp:120
GeographicLib::PolygonAreaT::_lon0
real _lon0
Definition: PolygonArea.hpp:75
GeographicLib::PolygonAreaT::_mask
unsigned _mask
Definition: PolygonArea.hpp:71
GeographicLib::PolygonAreaT::TestPoint
unsigned TestPoint(real lat, real lon, bool reverse, bool sign, real &perimeter, real &area) const
Definition: src/PolygonArea.cpp:98
GeographicLib::PolygonAreaT::_area0
real _area0
Definition: PolygonArea.hpp:69
GeographicLib::PolygonAreaT::AddPoint
void AddPoint(real lat, real lon)
Definition: src/PolygonArea.cpp:17
GeographicLib::PolygonAreaT::Compute
unsigned Compute(bool reverse, bool sign, real &perimeter, real &area) const
Definition: src/PolygonArea.cpp:55
GeographicLib::PolygonAreaT::transit
static int transit(real lon1, real lon2)
Definition: PolygonArea.hpp:76
GeographicLib::PolygonAreaT::_earth
GeodType _earth
Definition: PolygonArea.hpp:68
GeographicLib::PolygonAreaT::CurrentPoint
void CurrentPoint(real &lat, real &lon) const
Definition: PolygonArea.hpp:259
reverse
void reverse(const MatrixType &m)
Definition: array_reverse.cpp:16
lon
static const double lon
Definition: testGeographicLib.cpp:34
GeographicLib::PolygonAreaT::_perimetersum
Accumulator _perimetersum
Definition: PolygonArea.hpp:74
GeographicLib::PolygonAreaT::_polyline
bool _polyline
Definition: PolygonArea.hpp:70
GeographicLib::PolygonAreaT::PolygonArea
PolygonAreaT< Geodesic > PolygonArea
Definition: PolygonArea.hpp:270
real
Definition: main.h:100
GeographicLib::PolygonAreaT::real
Math::real real
Definition: PolygonArea.hpp:67
GeographicLib::PolygonAreaT::_crossings
int _crossings
Definition: PolygonArea.hpp:73
GeographicLib::PolygonAreaT::TestEdge
unsigned TestEdge(real azi, real s, bool reverse, bool sign, real &perimeter, real &area) const
Definition: src/PolygonArea.cpp:151
Geodesic.hpp
Header for GeographicLib::Geodesic class.
lat
static const double lat
Definition: testGeographicLib.cpp:34


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:03:36