1 /*****************************************************************************
3 Module: FGMicroWeather.cpp
4 Author: Christian Mayer
6 Called by: FGLocalWeatherDatabase
8 -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
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
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
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.
24 Further information about the GNU General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 ------------------------------------------------------------------------------
29 Handle the weather areas
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 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's
38 19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D
39 and lots of wee code cleaning
40 *****************************************************************************/
42 /****************************************************************************/
44 /****************************************************************************/
45 #include <Include/compiler.h>
46 #include <Include/fg_constants.h>
48 #include "FGMicroWeather.h"
50 /****************************************************************************/
51 /********************************** CODE ************************************/
52 /****************************************************************************/
53 FGMicroWeather::FGMicroWeather(const FGPhysicalProperties2D& p, const positionList& points)
59 FGMicroWeather::~FGMicroWeather()
63 /****************************************************************************/
64 /* Add the features to the micro weather */
66 /****************************************************************************/
67 void FGMicroWeather::addWind(const WeatherPrecision alt, const FGWindItem& x)
69 StoredWeather.Wind[alt] = x;
72 void FGMicroWeather::addTurbulence(const WeatherPrecision alt, const FGTurbulenceItem& x)
74 StoredWeather.Turbulence[alt] = x;
77 void FGMicroWeather::addTemperature(const WeatherPrecision alt, const WeatherPrecision x)
79 StoredWeather.Temperature[alt] = x;
82 void FGMicroWeather::addAirPressure(const WeatherPrecision alt, const WeatherPrecision x)
84 cerr << "Error: caught attempt to add AirPressure which is logical wrong\n";
85 //StoredWeather.AirPressure[alt] = x;
88 void FGMicroWeather::addVaporPressure(const WeatherPrecision alt, const WeatherPrecision x)
90 StoredWeather.VaporPressure[alt] = x;
93 void FGMicroWeather::addCloud(const WeatherPrecision alt, const FGCloudItem& x)
95 StoredWeather.Clouds[alt] = x;
98 void FGMicroWeather::setSnowRainIntensity(const WeatherPrecision x)
100 StoredWeather.SnowRainIntensity = x;
103 void FGMicroWeather::setSnowRainType(const SnowRainType x)
105 StoredWeather.snowRainType = x;
108 void FGMicroWeather::setLightningProbability(const WeatherPrecision x)
110 StoredWeather.LightningProbability = x;
113 void FGMicroWeather::setStoredWeather(const FGPhysicalProperties2D& x)
118 /****************************************************************************/
119 /* return true if p is inside this micro weather */
120 /* code stolen from $FG_ROOT/Simulator/Objects/fragment.cxx, which was */
121 /* written by Curtis L. Olson - curt@me.umn.edu */
122 /****************************************************************************/
124 template <class T> //template to help with the calulation
125 inline const int FG_SIGN(const T& x) {
126 return x < T(0) ? -1 : 1;
129 bool FGMicroWeather::hasPoint(const sgVec2& p) const
131 if (position.size()==0)
132 return true; //no border => this tile is infinite
134 if (position.size()==1)
135 return false; //a border on 1 point?!?
137 //when I'm here I've got at least 2 points
140 signed char side1, side2;
141 const_positionListIt it = position.begin();
142 const_positionListIt it2 = it; it2++;
147 if (it2 == position.end())
150 if (fabs(it->p[0] - it2->p[0]) >= FG_EPSILON)
152 t = (it->p[1] - it2->p[1]) / (it->p[0] - it2->p[0]);
154 side1 = FG_SIGN (t * (StoredWeather.p[0] - it2->p[0]) + it2->p[1] - StoredWeather.p[1]);
155 side2 = FG_SIGN (t * ( p[0] - it2->p[0]) + it2->p[1] - p[1]);
156 if ( side1 != side2 )
157 return false; //cout << "failed side check\n";
161 t = (it->p[0] - it2->p[0]) / (it->p[1] - it2->p[1]);
163 side1 = FG_SIGN (t * (StoredWeather.p[1] - it2->p[1]) + it2->p[0] - StoredWeather.p[0]);
164 side2 = FG_SIGN (t * ( p[1] - it2->p[1]) + it2->p[0] - p[0]);
165 if ( side1 != side2 )
166 return false; //cout << "failed side check\n";