]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/FGMicroWeather.cpp
Various SGI portability tweaks.
[flightgear.git] / src / WeatherCM / FGMicroWeather.cpp
1 /*****************************************************************************
2
3  Module:       FGMicroWeather.cpp
4  Author:       Christian Mayer
5  Date started: 28.05.99
6  Called by:    FGLocalWeatherDatabase
7
8  ---------- Copyright (C) 1999  Christian Mayer (vader@t-online.de) ----------
9
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 ------------------------------------------------------------------------------
29 Handle the weather areas
30
31 HISTORY
32 ------------------------------------------------------------------------------
33 28.05.1999 Christian Mayer      Created
34 16.06.1999 Durk Talsma          Portability for Linux
35 20.06.1999 Christian Mayer      added lots of consts
36 *****************************************************************************/
37
38 /****************************************************************************/
39 /* INCLUDES                                                                 */
40 /****************************************************************************/
41 #include "FGMicroWeather.h"
42 #include "fg_constants.h"
43
44 /****************************************************************************/
45 /********************************** CODE ************************************/
46 /****************************************************************************/
47 FGMicroWeather::FGMicroWeather(const FGPhysicalProperties2D& p, const positionList& points)
48 {
49     StoredWeather = p;
50     position = points;
51 }
52
53 FGMicroWeather::~FGMicroWeather()
54 {
55 }
56
57 /****************************************************************************/
58 /* Add the features to the micro weather                                    */
59 /* return succss                                                            */
60 /****************************************************************************/
61 void FGMicroWeather::addWind(const FGWindItem& x)
62 {
63     StoredWeather.Wind.insert(x);
64 }
65
66 void FGMicroWeather::addTurbulence(const FGTurbulenceItem& x)
67 {
68     StoredWeather.Turbulence.insert(x);
69 }
70
71 void FGMicroWeather::addTemperature(const FGTemperatureItem& x)
72 {
73     StoredWeather.Temperature.insert(x);
74 }
75
76 void FGMicroWeather::addAirPressure(const FGAirPressureItem& x)
77 {
78     cerr << "Error: caught attempt to add AirPressure which is logical wrong\n";
79     //StoredWeather.AirPressure.insert(x);
80 }
81
82 void FGMicroWeather::addVaporPressure(const FGVaporPressureItem& x)
83 {
84     StoredWeather.VaporPressure.insert(x);
85 }
86
87 void FGMicroWeather::addCloud(const FGCloudItem& x)
88 {
89     StoredWeather.Clouds.insert(x);
90 }
91
92 void FGMicroWeather::setSnowRainIntensity(const WeatherPrecition& x)
93 {
94     StoredWeather.SnowRainIntensity = x;
95 }
96
97 void FGMicroWeather::setSnowRainType(const SnowRainType& x)
98 {
99     StoredWeather.snowRainType = x;
100 }
101
102 void FGMicroWeather::setLightningProbability(const WeatherPrecition& x)
103 {
104     StoredWeather.LightningProbability = x;
105 }
106
107 void FGMicroWeather::setStoredWeather(const FGPhysicalProperties2D& x)
108 {
109     StoredWeather = x;
110 }
111
112 /****************************************************************************/
113 /* return true if p is inside this micro weather                            */
114 /* code stolen from $FG_ROOT/Simulator/Objects/fragment.cxx, which was      */
115 /* written by Curtis L. Olson - curt@me.umn.edu                             */
116 /****************************************************************************/
117
118 template <class T> //template to help with the calulation
119 inline const int FG_SIGN(const T& x) {
120     return x < T(0) ? -1 : 1;
121 }
122
123 bool FGMicroWeather::hasPoint(const Point2D& p) const
124 {
125     if (position.size()==0)
126         return true;    //no border => this tile is infinite
127     
128     if (position.size()==1)
129         return false;   //a border on 1 point?!?
130
131     //when I'm here I've got at least 2 points
132     
133     WeatherPrecition t;
134     signed char side1, side2;
135     const_positionListIt it = position.begin();
136     const_positionListIt it2 = it; it2++;
137
138     for (;;)
139     {
140         
141         if (it2 == position.end())
142             break;
143
144         if (fabs(it->x() - it2->x()) >= FG_EPSILON)
145         {
146             t = (it->y() - it2->y()) / (it->x() - it2->x());
147             side1 = FG_SIGN (t * (StoredWeather.p.x() - it2->x()) + it2->y() - StoredWeather.p.y());
148             side2 = FG_SIGN (t * (              p.x() - it2->x()) + it2->y() -               p.y());
149             if ( side1 != side2 ) 
150                 return false; //cout << "failed side check\n";
151         }
152         else
153         {
154             t = (it->x() - it2->x()) / (it->y() - it2->y());
155             side1 = FG_SIGN (t * (StoredWeather.p.y() - it2->y()) + it2->x() - StoredWeather.p.x());
156             side2 = FG_SIGN (t * (              p.y() - it2->y()) + it2->x() -               p.x());
157             if ( side1 != side2 ) 
158                 return false; //cout << "failed side check\n";
159         }
160
161         it++; it2++;
162     }
163
164     return true;
165 }