File: PolygonArea.h

package info (click to toggle)
geographiclib 1.37-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,688 kB
  • ctags: 4,871
  • sloc: cpp: 31,440; sh: 11,632; cs: 9,411; ansic: 1,428; java: 1,333; python: 1,131; makefile: 758; xml: 381; pascal: 30
file content (387 lines) | stat: -rw-r--r-- 18,990 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#pragma once
/**
 * \file NETGeographicLib/PolygonArea.h
 * \brief Header for NETGeographicLib::PolygonArea class
 *
 * NETGeographicLib is copyright (c) Scott Heiman (2013)
 * GeographicLib is Copyright (c) Charles Karney (2010-2012)
 * <charles@karney.com> and licensed under the MIT/X11 License.
 * For more information, see
 * http://geographiclib.sourceforge.net/
 **********************************************************************/

namespace NETGeographicLib
{
    ref class Geodesic;
  /**
   * \brief .NET wrapper for GeographicLib::PolygonArea and PolygonAreaExact.
   *
   * This class allows .NET applications to access GeographicLib::PolygonArea.
   *
   * This computes the area of a geodesic polygon using the method given
   * Section 6 of
   * - C. F. F. Karney,
   *   <a href="http://dx.doi.org/10.1007/s00190-012-0578-z">
   *   Algorithms for geodesics</a>,
   *   J. Geodesy <b>87</b>, 43--55 (2013);
   *   DOI: <a href="http://dx.doi.org/10.1007/s00190-012-0578-z">
   *   10.1007/s00190-012-0578-z</a>;
   *   addenda: <a href="http://geographiclib.sf.net/geod-addenda.html">
   *   geod-addenda.html</a>.
   *
   * This class lets you add vertices one at a time to the polygon.  The area
   * and perimeter are accumulated in two times the standard floating point
   * precision to guard against the loss of accuracy with many-sided polygons.
   * At any point you can ask for the perimeter and area so far.  There's an
   * option to treat the points as defining a polyline instead of a polygon; in
   * that case, only the perimeter is computed.
   *
   * C# Example:
   * \include example-PolygonArea.cs
   * Managed C++ Example:
   * \include example-PolygonArea.cpp
   * Visual Basic Example:
   * \include example-PolygonArea.vb
   *
   * <B>INTERFACE DIFFERENCES:</B><BR>
   * The MajorRadius and Flattening functions are implemented as properties.
   **********************************************************************/
    public ref class PolygonArea
    {
        private:
        // a pointer to the unmanaged GeographicLib::PolygonArea
        GeographicLib::PolygonArea* m_pPolygonArea;

        // the finalize frees the unmanaged memory when the object is destroyed.
        !PolygonArea(void);
    public:

        /**
         * Constructor for PolygonArea.
         *
         * @param[in] earth the Geodesic object to use for geodesic calculations.
         * @param[in] polyline if true that treat the points as defining a polyline
         *   instead of a polygon.
         **********************************************************************/
        PolygonArea(Geodesic^ earth, bool polyline );

        /**
         * Constructor for PolygonArea that assumes a WGS84 ellipsoid.
         *
         * @param[in] polyline if true that treat the points as defining a polyline
         *   instead of a polygon.
         **********************************************************************/
        PolygonArea(const bool polyline );

        /**
         * The destructor calls the finalizer.
         **********************************************************************/
        ~PolygonArea()
        { this->!PolygonArea(); }

        /**
         * Clear PolygonArea, allowing a new polygon to be started.
         **********************************************************************/
        void Clear();

        /**
         * Add a point to the polygon or polyline.
         *
         * @param[in] lat the latitude of the point (degrees).
         * @param[in] lon the longitude of the point (degrees).
         *
         * \e lat should be in the range [&minus;90&deg;, 90&deg;] and \e
         * lon should be in the range [&minus;540&deg;, 540&deg;).
         **********************************************************************/
        void AddPoint(double lat, double lon);

        /**
         * Add an edge to the polygon or polyline.
         *
         * @param[in] azi azimuth at current point (degrees).
         * @param[in] s distance from current point to next point (meters).
         *
         * \e azi should be in the range [&minus;540&deg;, 540&deg;).  This does
         * nothing if no points have been added yet.  Use PolygonArea::CurrentPoint
         * to determine the position of the new vertex.
         **********************************************************************/
        void AddEdge(double azi, double s);

        /**
         * Return the results so far.
         *
         * @param[in] reverse if true then clockwise (instead of counter-clockwise)
         *   traversal counts as a positive area.
         * @param[in] sign if true then return a signed result for the area if
         *   the polygon is traversed in the "wrong" direction instead of returning
         *   the area for the rest of the earth.
         * @param[out] perimeter the perimeter of the polygon or length of the
         *   polyline (meters).
         * @param[out] area the area of the polygon (meters<sup>2</sup>); only set
         *   if \e polyline is false in the constructor.
         * @return the number of points.
         **********************************************************************/
        unsigned Compute(bool reverse, bool sign,
                [System::Runtime::InteropServices::Out] double% perimeter,
                [System::Runtime::InteropServices::Out] double% area);

        /**
         * Return the results assuming a tentative final test point is added;
         * however, the data for the test point is not saved.  This lets you report
         * a running result for the perimeter and area as the user moves the mouse
         * cursor.  Ordinary floating point arithmetic is used to accumulate the
         * data for the test point; thus the area and perimeter returned are less
         * accurate than if PolygonArea::AddPoint and PolygonArea::Compute are
         * used.
         *
         * @param[in] lat the latitude of the test point (degrees).
         * @param[in] lon the longitude of the test point (degrees).
         * @param[in] reverse if true then clockwise (instead of counter-clockwise)
         *   traversal counts as a positive area.
         * @param[in] sign if true then return a signed result for the area if
         *   the polygon is traversed in the "wrong" direction instead of returning
         *   the area for the rest of the earth.
         * @param[out] perimeter the approximate perimeter of the polygon or length
         *   of the polyline (meters).
         * @param[out] area the approximate area of the polygon
         *   (meters<sup>2</sup>); only set if polyline is false in the
         *   constructor.
         * @return the number of points.
         *
         * \e lat should be in the range [&minus;90&deg;, 90&deg;] and \e
         * lon should be in the range [&minus;540&deg;, 540&deg;).
         **********************************************************************/
        unsigned TestPoint(double lat, double lon, bool reverse, bool sign,
                [System::Runtime::InteropServices::Out] double% perimeter,
                [System::Runtime::InteropServices::Out] double% area);

        /**
         * Return the results assuming a tentative final test point is added via an
         * azimuth and distance; however, the data for the test point is not saved.
         * This lets you report a running result for the perimeter and area as the
         * user moves the mouse cursor.  Ordinary floating point arithmetic is used
         * to accumulate the data for the test point; thus the area and perimeter
         * returned are less accurate than if PolygonArea::AddEdge and
         * PolygonArea::Compute are used.
         *
         * @param[in] azi azimuth at current point (degrees).
         * @param[in] s distance from current point to final test point (meters).
         * @param[in] reverse if true then clockwise (instead of counter-clockwise)
         *   traversal counts as a positive area.
         * @param[in] sign if true then return a signed result for the area if
         *   the polygon is traversed in the "wrong" direction instead of returning
         *   the area for the rest of the earth.
         * @param[out] perimeter the approximate perimeter of the polygon or length
         *   of the polyline (meters).
         * @param[out] area the approximate area of the polygon
         *   (meters<sup>2</sup>); only set if polyline is false in the
         *   constructor.
         * @return the number of points.
         *
         * \e azi should be in the range [&minus;540&deg;, 540&deg;).
         **********************************************************************/
        unsigned TestEdge(double azi, double s, bool reverse, bool sign,
                [System::Runtime::InteropServices::Out] double% perimeter,
                [System::Runtime::InteropServices::Out] double% area);

        /** \name Inspector functions
         **********************************************************************/
        ///@{
        /**
         * @return \e a the equatorial radius of the ellipsoid (meters).  This is
         *   the value inherited from the Geodesic object used in the constructor.
         **********************************************************************/
        property double MajorRadius { double get(); }

        /**
         * @return \e f the flattening of the ellipsoid.  This is the value
         *   inherited from the Geodesic object used in the constructor.
         **********************************************************************/
        property double Flattening { double get(); }

        /**
         * Report the previous vertex added to the polygon or polyline.
         *
         * @param[out] lat the latitude of the point (degrees).
         * @param[out] lon the longitude of the point (degrees).
         *
         * If no points have been added, then NaNs are returned.  Otherwise, \e lon
         * will be in the range [&minus;180&deg;, 180&deg;).
         **********************************************************************/
        void CurrentPoint([System::Runtime::InteropServices::Out] double% lat,
                          [System::Runtime::InteropServices::Out] double% lon);
        ///@}
    };

    //*************************************************************************
    // PolygonAreaExact
    //*************************************************************************
    ref class GeodesicExact;

    public ref class PolygonAreaExact
    {
        private:
        // a pointer to the unmanaged GeographicLib::PolygonArea
        GeographicLib::PolygonAreaExact* m_pPolygonArea;

        // the finalize frees the unmanaged memory when the object is destroyed.
        !PolygonAreaExact(void);
    public:

        /**
         * Constructor for PolygonArea.
         *
         * @param[in] earth the Geodesic object to use for geodesic calculations.
         * @param[in] polyline if true that treat the points as defining a polyline
         *   instead of a polygon.
         **********************************************************************/
        PolygonAreaExact(GeodesicExact^ earth, bool polyline );

        /**
         * Constructor for PolygonArea that assumes a WGS84 ellipsoid.
         *
         * @param[in] polyline if true that treat the points as defining a polyline
         *   instead of a polygon.
         **********************************************************************/
        PolygonAreaExact(const bool polyline );

        /**
         * The destructor calls the finalizer.
         **********************************************************************/
        ~PolygonAreaExact()
        { this->!PolygonAreaExact(); }

        /**
         * Clear PolygonArea, allowing a new polygon to be started.
         **********************************************************************/
        void Clear();

        /**
         * Add a point to the polygon or polyline.
         *
         * @param[in] lat the latitude of the point (degrees).
         * @param[in] lon the longitude of the point (degrees).
         *
         * \e lat should be in the range [&minus;90&deg;, 90&deg;] and \e
         * lon should be in the range [&minus;540&deg;, 540&deg;).
         **********************************************************************/
        void AddPoint(double lat, double lon);

        /**
         * Add an edge to the polygon or polyline.
         *
         * @param[in] azi azimuth at current point (degrees).
         * @param[in] s distance from current point to next point (meters).
         *
         * \e azi should be in the range [&minus;540&deg;, 540&deg;).  This does
         * nothing if no points have been added yet.  Use PolygonArea::CurrentPoint
         * to determine the position of the new vertex.
         **********************************************************************/
        void AddEdge(double azi, double s);

        /**
         * Return the results so far.
         *
         * @param[in] reverse if true then clockwise (instead of counter-clockwise)
         *   traversal counts as a positive area.
         * @param[in] sign if true then return a signed result for the area if
         *   the polygon is traversed in the "wrong" direction instead of returning
         *   the area for the rest of the earth.
         * @param[out] perimeter the perimeter of the polygon or length of the
         *   polyline (meters).
         * @param[out] area the area of the polygon (meters<sup>2</sup>); only set
         *   if \e polyline is false in the constructor.
         * @return the number of points.
         **********************************************************************/
        unsigned Compute(bool reverse, bool sign,
                [System::Runtime::InteropServices::Out] double% perimeter,
                [System::Runtime::InteropServices::Out] double% area);

        /**
         * Return the results assuming a tentative final test point is added;
         * however, the data for the test point is not saved.  This lets you report
         * a running result for the perimeter and area as the user moves the mouse
         * cursor.  Ordinary floating point arithmetic is used to accumulate the
         * data for the test point; thus the area and perimeter returned are less
         * accurate than if PolygonArea::AddPoint and PolygonArea::Compute are
         * used.
         *
         * @param[in] lat the latitude of the test point (degrees).
         * @param[in] lon the longitude of the test point (degrees).
         * @param[in] reverse if true then clockwise (instead of counter-clockwise)
         *   traversal counts as a positive area.
         * @param[in] sign if true then return a signed result for the area if
         *   the polygon is traversed in the "wrong" direction instead of returning
         *   the area for the rest of the earth.
         * @param[out] perimeter the approximate perimeter of the polygon or length
         *   of the polyline (meters).
         * @param[out] area the approximate area of the polygon
         *   (meters<sup>2</sup>); only set if polyline is false in the
         *   constructor.
         * @return the number of points.
         *
         * \e lat should be in the range [&minus;90&deg;, 90&deg;] and \e
         * lon should be in the range [&minus;540&deg;, 540&deg;).
         **********************************************************************/
        unsigned TestPoint(double lat, double lon, bool reverse, bool sign,
                [System::Runtime::InteropServices::Out] double% perimeter,
                [System::Runtime::InteropServices::Out] double% area);

        /**
         * Return the results assuming a tentative final test point is added via an
         * azimuth and distance; however, the data for the test point is not saved.
         * This lets you report a running result for the perimeter and area as the
         * user moves the mouse cursor.  Ordinary floating point arithmetic is used
         * to accumulate the data for the test point; thus the area and perimeter
         * returned are less accurate than if PolygonArea::AddEdge and
         * PolygonArea::Compute are used.
         *
         * @param[in] azi azimuth at current point (degrees).
         * @param[in] s distance from current point to final test point (meters).
         * @param[in] reverse if true then clockwise (instead of counter-clockwise)
         *   traversal counts as a positive area.
         * @param[in] sign if true then return a signed result for the area if
         *   the polygon is traversed in the "wrong" direction instead of returning
         *   the area for the rest of the earth.
         * @param[out] perimeter the approximate perimeter of the polygon or length
         *   of the polyline (meters).
         * @param[out] area the approximate area of the polygon
         *   (meters<sup>2</sup>); only set if polyline is false in the
         *   constructor.
         * @return the number of points.
         *
         * \e azi should be in the range [&minus;540&deg;, 540&deg;).
         **********************************************************************/
        unsigned TestEdge(double azi, double s, bool reverse, bool sign,
                [System::Runtime::InteropServices::Out] double% perimeter,
                [System::Runtime::InteropServices::Out] double% area);

        /** \name Inspector functions
         **********************************************************************/
        ///@{
        /**
         * @return \e a the equatorial radius of the ellipsoid (meters).  This is
         *   the value inherited from the Geodesic object used in the constructor.
         **********************************************************************/
        property double MajorRadius { double get(); }

        /**
         * @return \e f the flattening of the ellipsoid.  This is the value
         *   inherited from the Geodesic object used in the constructor.
         **********************************************************************/
        property double Flattening { double get(); }

        /**
         * Report the previous vertex added to the polygon or polyline.
         *
         * @param[out] lat the latitude of the point (degrees).
         * @param[out] lon the longitude of the point (degrees).
         *
         * If no points have been added, then NaNs are returned.  Otherwise, \e lon
         * will be in the range [&minus;180&deg;, 180&deg;).
         **********************************************************************/
        void CurrentPoint([System::Runtime::InteropServices::Out] double% lat,
                          [System::Runtime::InteropServices::Out] double% lon);
        ///@}
    };
} // namespace NETGeographicLib