]> git.mxchange.org Git - simgear.git/blob - simgear/timing/geocoord.cxx
Merge branch 'maint' into next
[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 #ifdef HAVE_CONFIG_H
31 #  include <simgear_config.h>
32 #endif
33
34 #include <simgear/math/SGMath.hxx>
35 #include "geocoord.h"
36
37 SGGeoCoord::SGGeoCoord(const SGGeoCoord& other)
38 {
39   lat = other.lat;
40   lon = other.lon;
41 }
42
43 SGGeoCoord* SGGeoCoordContainer::getNearest(const SGGeoCoord& ref) const
44 {
45   if (data.empty())
46     return 0;
47
48   float maxCosAng = -2;
49   SGVec3f refVec(ref.getX(), ref.getY(), ref.getZ());
50   SGGeoCoordVectorConstIterator i, nearest;
51   for (i = data.begin(); i != data.end(); ++i)
52     {
53       float cosAng = dot(refVec, SGVec3f((*i)->getX(), (*i)->getY(), (*i)->getZ()));
54       if (maxCosAng < cosAng)
55         {
56           maxCosAng = cosAng;
57           nearest = i;
58         }
59     }
60   return *nearest;
61 }
62
63
64 SGGeoCoordContainer::~SGGeoCoordContainer()
65 {
66     SGGeoCoordVectorIterator i = data.begin();
67   while (i != data.end())
68     delete *i++;
69 }