1 /**
2  * \file NETGeographicLib/Gnomonic.cpp
3  * \brief Implementation for NETGeographicLib::Gnomonic class
4  *
5  * NETGeographicLib is copyright (c) Scott Heiman (2013)
6  * GeographicLib is Copyright (c) Charles Karney (2010-2012)
7  * <charles@karney.com> and licensed under the MIT/X11 License.
8  * For more information, see
9  * https://geographiclib.sourceforge.io/
10  **********************************************************************/
11 #include "stdafx.h"
12 #include "GeographicLib/Gnomonic.hpp"
13 #include "Gnomonic.h"
14 #include "Geodesic.h"
15 #include "NETGeographicLib.h"
16 
17 using namespace NETGeographicLib;
18 
19 const char BADALLOC[] = "Failed to allocate memory for a GeographicLib::Gnomonic";
20 
21 //*****************************************************************************
22 Gnomonic::!Gnomonic(void)
23 {
24     if ( m_pGnomonic != NULL )
25     {
26         delete m_pGnomonic;
27         m_pGnomonic = NULL;
28     }
29 }
30 
31 //*****************************************************************************
32 Gnomonic::Gnomonic( Geodesic^ earth )
33 {
34     try
35     {
36         const GeographicLib::Geodesic* pGeodesic =
37             reinterpret_cast<const GeographicLib::Geodesic*>(
38                 earth->GetUnmanaged()->ToPointer() );
39         m_pGnomonic = new GeographicLib::Gnomonic( *pGeodesic );
40     }
41     catch ( std::bad_alloc )
42     {
43         throw gcnew GeographicErr( BADALLOC );
44     }
45 }
46 
47 //*****************************************************************************
Gnomonic()48 Gnomonic::Gnomonic()
49 {
50     try
51     {
52         m_pGnomonic = new GeographicLib::Gnomonic( GeographicLib::Geodesic::WGS84() );
53     }
54     catch ( std::bad_alloc )
55     {
56         throw gcnew GeographicErr( BADALLOC );
57     }
58 }
59 
60 //*****************************************************************************
61 void Gnomonic::Forward(double lat0, double lon0, double lat, double lon,
62                 [System::Runtime::InteropServices::Out] double% x,
63                 [System::Runtime::InteropServices::Out] double% y,
64                 [System::Runtime::InteropServices::Out] double% azi,
65                 [System::Runtime::InteropServices::Out] double% rk)
66 {
67     double lx, ly, lazi, lrk;
68     m_pGnomonic->Forward( lat0, lon0, lat, lon, lx, ly, lazi, lrk );
69     x = lx;
70     y = ly;
71     azi = lazi;
72     rk = lrk;
73 }
74 
75 //*****************************************************************************
76 void Gnomonic::Reverse(double lat0, double lon0, double x, double y,
77                 [System::Runtime::InteropServices::Out] double% lat,
78                 [System::Runtime::InteropServices::Out] double% lon,
79                 [System::Runtime::InteropServices::Out] double% azi,
80                 [System::Runtime::InteropServices::Out] double% rk)
81 {
82     double llat, llon, lazi, lrk;
83     m_pGnomonic->Reverse( lat0, lon0, x, y, llat, llon, lazi, lrk );
84     lat = llat;
85     lon = llon;
86     azi = lazi;
87     rk = lrk;
88 }
89 
90 //*****************************************************************************
91 void Gnomonic::Forward(double lat0, double lon0, double lat, double lon,
92                 [System::Runtime::InteropServices::Out] double% x,
93                 [System::Runtime::InteropServices::Out] double% y)
94 {
95     double lx, ly;
96     m_pGnomonic->Forward( lat0, lon0, lat, lon, lx, ly );
97     x = lx;
98     y = ly;
99 }
100 
101 //*****************************************************************************
102 void Gnomonic::Reverse(double lat0, double lon0, double x, double y,
103                 [System::Runtime::InteropServices::Out] double% lat,
104                 [System::Runtime::InteropServices::Out] double% lon)
105 {
106     double llat, llon;
107     m_pGnomonic->Reverse( lat0, lon0, x, y, llat, llon );
108     lat = llat;
109     lon = llon;
110 }
111 
112 //*****************************************************************************
get()113 double Gnomonic::EquatorialRadius::get() { return m_pGnomonic->EquatorialRadius(); }
114 
115 //*****************************************************************************
get()116 double Gnomonic::Flattening::get() { return m_pGnomonic->Flattening(); }
117