1 /*****************************************************************************
3 Module: FGMicroWeather.cpp
4 Author: Christian Mayer
6 Called by: FGLocalWeatherDatabase
8 ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.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 *****************************************************************************/
38 /****************************************************************************/
40 /****************************************************************************/
41 #include "FGMicroWeather.h"
42 #include "fg_constants.h"
44 /****************************************************************************/
45 /********************************** CODE ************************************/
46 /****************************************************************************/
47 FGMicroWeather::FGMicroWeather(const FGPhysicalProperties2D& p, const positionList& points)
53 FGMicroWeather::~FGMicroWeather()
57 /****************************************************************************/
58 /* Add the features to the micro weather */
60 /****************************************************************************/
61 void FGMicroWeather::addWind(const FGWindItem& x)
63 StoredWeather.Wind.insert(x);
66 void FGMicroWeather::addTurbulence(const FGTurbulenceItem& x)
68 StoredWeather.Turbulence.insert(x);
71 void FGMicroWeather::addTemperature(const FGTemperatureItem& x)
73 StoredWeather.Temperature.insert(x);
76 void FGMicroWeather::addAirPressure(const FGAirPressureItem& x)
78 cerr << "Error: caught attempt to add AirPressure which is logical wrong\n";
79 //StoredWeather.AirPressure.insert(x);
82 void FGMicroWeather::addVaporPressure(const FGVaporPressureItem& x)
84 StoredWeather.VaporPressure.insert(x);
87 void FGMicroWeather::addCloud(const FGCloudItem& x)
89 StoredWeather.Clouds.insert(x);
92 void FGMicroWeather::setSnowRainIntensity(const WeatherPrecition& x)
94 StoredWeather.SnowRainIntensity = x;
97 void FGMicroWeather::setSnowRainType(const SnowRainType& x)
99 StoredWeather.snowRainType = x;
102 void FGMicroWeather::setLightningProbability(const WeatherPrecition& x)
104 StoredWeather.LightningProbability = x;
107 void FGMicroWeather::setStoredWeather(const FGPhysicalProperties2D& x)
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 /****************************************************************************/
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;
123 bool FGMicroWeather::hasPoint(const Point2D& p) const
125 if (position.size()==0)
126 return true; //no border => this tile is infinite
128 if (position.size()==1)
129 return false; //a border on 1 point?!?
131 //when I'm here I've got at least 2 points
134 signed char side1, side2;
135 const_positionListIt it = position.begin();
136 const_positionListIt it2 = it; it2++;
141 if (it2 == position.end())
144 if (fabs(it->x() - it2->x()) >= FG_EPSILON)
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";
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";