]> git.mxchange.org Git - simgear.git/blob - simgear/timing/geocoord.cxx
9cb9f38b2a4e2ed28ad2c5bd158decbb717d0235
[simgear.git] / simgear / timing / geocoord.cxx
1 /* -*- Mode: C++ -*- *****************************************************
2  * geocoord.h
3  * Written by Durk Talsma. Started March 1998.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  *
19  **************************************************************************/
20
21 /*************************************************************************
22  *
23  * This file defines a small and simple class to store geocentric 
24  * coordinates. Basically, class SGGeoCoord is intended as a base class for
25  * any kind of of object, that can be categorized according to its 
26  * location on earth, be it navaids, or aircraft. This class for originally
27  * written for FlightGear, in order to store Timezone control points. 
28  *
29  ************************************************************************/
30 #include <simgear/math/SGMath.hxx>
31 #include "geocoord.h"
32
33 SGGeoCoord::SGGeoCoord(const SGGeoCoord& other)
34 {
35   lat = other.lat;
36   lon = other.lon;
37 }
38
39 SGGeoCoord* SGGeoCoordContainer::getNearest(const SGGeoCoord& ref) const
40 {
41   if (data.empty())
42     return 0;
43
44   float maxCosAng = -2;
45   SGVec3f refVec(ref.getX(), ref.getY(), ref.getZ());
46   SGGeoCoordVectorConstIterator i, nearest;
47   for (i = data.begin(); i != data.end(); ++i)
48     {
49       float cosAng = dot(refVec, SGVec3f((*i)->getX(), (*i)->getY(), (*i)->getZ()));
50       if (maxCosAng < cosAng)
51         {
52           maxCosAng = cosAng;
53           nearest = i;
54         }
55     }
56   return *nearest;
57 }
58
59
60 SGGeoCoordContainer::~SGGeoCoordContainer()
61 {
62     SGGeoCoordVectorIterator i = data.begin();
63   while (i != data.end())
64     delete *i++;
65 }