]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/FGPhysicalProperty.h
e546588035e07ab88584840bda6feb47e3eac015
[flightgear.git] / src / WeatherCM / FGPhysicalProperty.h
1 /*****************************************************************************
2
3  Header:       FGPhysicalProperty.h     
4  Author:       Christian Mayer
5  Date started: 28.05.99
6
7  -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) --------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  details.
18
19  You should have received a copy of the GNU General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 FUNCTIONAL DESCRIPTION
27 ------------------------------------------------------------------------------
28 Define the simulated physical property of the weather in one point
29
30 HISTORY
31 ------------------------------------------------------------------------------
32 28.05.1999 Christian Mayer      Created
33 16.06.1999 Durk Talsma          Portability for Linux
34 20.06.1999 Christian Mayer      Changed struct to class
35 20.06.1999 Christian Mayer      added lots of consts
36 30.06.1999 Christian Mayer      STL portability
37 11.10.1999 Christian Mayer      changed set<> to map<> on Bernie Bright's 
38                                 suggestion
39 19.10.1999 Christian Mayer      change to use PLIB's sg instead of Point[2/3]D
40                                 and lots of wee code cleaning
41 *****************************************************************************/
42
43 /****************************************************************************/
44 /* SENTRY                                                                   */
45 /****************************************************************************/
46 #ifndef FGPhysicalProperty_H
47 #define FGPhysicalProperty_H
48
49 /****************************************************************************/
50 /* INCLUDES                                                                 */
51 /****************************************************************************/
52 #include <Include/compiler.h>
53
54 #include <vector>
55
56 #include "sg.h"
57
58 #include "FGWeatherDefs.h"
59 #include "FGPhysicalProperties.h"
60
61 FG_USING_STD(vector);
62 FG_USING_NAMESPACE(std);
63
64 /****************************************************************************/
65 /* used for output:                                                         */
66 /****************************************************************************/
67 class FGPhysicalProperty;
68 bool operator == (const FGPhysicalProperty& a, const FGPhysicalProperty& b);  // p1 == p2?
69
70 class FGPhysicalProperty
71 {
72 private:
73 protected:
74 public:
75     sgVec3           Wind;              //Wind vector
76     sgVec3           Turbulence;        //Turbulence vector
77     WeatherPrecision Temperature;       //in deg. Kelvin (I *only* accept SI!)
78     WeatherPrecision AirPressure;       //in Pascal (I *only* accept SI!)
79     WeatherPrecision VaporPressure;     //in Pascal (I *only* accept SI!)
80
81     FGPhysicalProperty();   //consructor to fill it with FG standart weather
82     FGPhysicalProperty(const FGPhysicalProperties& p, const WeatherPrecision altitude);
83
84     //allow calculations for easier handling such as interpolating
85     FGPhysicalProperty& operator =  ( const FGPhysicalProperty& p );    // assignment of a FGPhysicalProperty
86     FGPhysicalProperty& operator += ( const FGPhysicalProperty& p );    // incrementation by a FGPhysicalProperty
87     FGPhysicalProperty& operator -= ( const FGPhysicalProperty& p );    // decrementation by a FGPhysicalProperty
88     FGPhysicalProperty& operator *= ( const double d );                 // multiplication by a constant
89     FGPhysicalProperty& operator /= ( const double d );                 // division by a constant
90
91     friend FGPhysicalProperty operator - (const FGPhysicalProperty& p);                 // -p1
92     friend bool operator == (const FGPhysicalProperty& a, const FGPhysicalProperty& b); // p1 == p2?
93 };
94
95 class FGPhysicalProperty3D : public FGPhysicalProperty
96 {
97 private:
98 protected:
99 public:
100     sgVec3 p;       //position of the property (lat/lon/alt)
101 };
102
103 typedef vector<FGPhysicalProperty>               FGPhysicalPropertyVector;
104 typedef FGPhysicalPropertyVector::iterator       FGPhysicalPropertyVectorIt;
105 typedef FGPhysicalPropertyVector::const_iterator FGPhysicalPropertyVectorConstIt;
106
107 typedef vector<FGPhysicalProperty3D>               FGPhysicalProperty3DVector;
108 typedef FGPhysicalProperty3DVector::iterator       FGPhysicalProperty3DVectorIt;
109 typedef FGPhysicalProperty3DVector::const_iterator FGPhysicalProperty3DVectorConstIt;
110
111 inline FGPhysicalProperty& FGPhysicalProperty::operator = ( const FGPhysicalProperty& p )
112 {
113     sgCopyVec3(Wind, p.Wind); 
114     sgCopyVec3(Turbulence, p.Turbulence); 
115     Temperature = p.Temperature; 
116     AirPressure = p.AirPressure; 
117     VaporPressure = p.VaporPressure; 
118     return *this;
119 }
120
121 inline FGPhysicalProperty& FGPhysicalProperty::operator += ( const FGPhysicalProperty& p )
122 {
123     sgAddVec3(Wind, p.Wind); 
124     sgAddVec3(Turbulence, p.Turbulence); 
125     Temperature += p.Temperature; 
126     AirPressure += p.AirPressure; 
127     VaporPressure += p.VaporPressure; 
128     return *this;
129 }
130
131 inline FGPhysicalProperty& FGPhysicalProperty::operator -= ( const FGPhysicalProperty& p )
132 {
133     sgSubVec3(Wind, p.Wind); 
134     sgSubVec3(Turbulence, p.Turbulence); 
135     Temperature -= p.Temperature; 
136     AirPressure -= p.AirPressure; 
137     VaporPressure -= p.VaporPressure; 
138     return *this;
139 }
140
141 inline FGPhysicalProperty& FGPhysicalProperty::operator *= ( const double d )
142 {
143     sgScaleVec3(Wind, d); 
144     sgScaleVec3(Turbulence, d); 
145     Temperature *= d; 
146     AirPressure *= d; 
147     VaporPressure *= d; 
148     return *this;
149 }
150
151 inline FGPhysicalProperty& FGPhysicalProperty::operator /= ( const double d )
152 {
153     sgScaleVec3(Wind, 1.0 / d); 
154     sgScaleVec3(Turbulence, 1.0 / d); 
155     Temperature /= d; 
156     AirPressure /= d; 
157     VaporPressure /= d; 
158     return *this;
159 }
160
161 inline  FGPhysicalProperty operator - (const FGPhysicalProperty& p)
162 {
163     FGPhysicalProperty x;
164     sgNegateVec3(x.Wind, p.Wind); 
165     sgNegateVec3(x.Turbulence, p.Turbulence); 
166     x.Temperature = -p.Temperature; 
167     x.AirPressure = -p.AirPressure; 
168     x.VaporPressure = -p.VaporPressure; 
169     return x;
170 }
171
172 inline bool operator == (const FGPhysicalProperty& a, const FGPhysicalProperty& b)
173 {
174     return (
175     sgEqualVec3(a.Wind, b.Wind) &&
176     sgEqualVec3(a.Turbulence, b.Turbulence) && 
177     (a.Temperature == b.Temperature) && 
178     (a.AirPressure == b.AirPressure) && 
179     (a.VaporPressure == b.VaporPressure)); 
180 }
181
182 inline bool operator != (const FGPhysicalProperty& a, const FGPhysicalProperty& b)
183 {
184     return !(a == b);
185 }
186
187 inline FGPhysicalProperty operator + (const FGPhysicalProperty& a, const FGPhysicalProperty& b)
188 {
189     return FGPhysicalProperty(a) += b;
190 }
191
192 inline FGPhysicalProperty operator - (const FGPhysicalProperty& a, const FGPhysicalProperty& b)
193 {
194     return FGPhysicalProperty(a) -= b;
195 }
196
197 inline FGPhysicalProperty operator * (const FGPhysicalProperty& a, const WeatherPrecision b)
198 {
199     return FGPhysicalProperty(a) *= b;
200 }
201
202 inline FGPhysicalProperty operator * (const WeatherPrecision b, const FGPhysicalProperty& a)
203 {
204     return FGPhysicalProperty(a) *= b;
205 }
206
207 inline FGPhysicalProperty operator / (const FGPhysicalProperty& a, const WeatherPrecision b)
208 {
209     return FGPhysicalProperty(a) *= (1.0/b);
210 }
211
212 /****************************************************************************/
213 #endif /*FGPhysicalProperty_H*/