CirclingWind: eliminate attributes min_vector, max_vector
[xcsoar.git] / src / Computer / ThermalBandComputer.cpp
blob0f41f71bd029f58ee36fcbd113528bc407757f6d
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "ThermalBandComputer.hpp"
25 #include "NMEA/MoreData.hpp"
26 #include "NMEA/Derived.hpp"
27 #include "Settings.hpp"
29 void
30 ThermalBandComputer::Reset()
32 last_vario_available.Clear();
35 void
36 ThermalBandComputer::Compute(const MoreData &basic,
37 const DerivedInfo &calculated,
38 ThermalBandInfo &tbi,
39 const ComputerSettings &settings)
41 if (!basic.NavAltitudeAvailable())
42 return;
44 const fixed h_safety =
45 settings.task.route_planner.safety_height_terrain +
46 calculated.GetTerrainBaseFallback();
48 tbi.working_band_height = basic.TE_altitude - h_safety;
49 if (negative(tbi.working_band_height)) {
50 tbi.working_band_fraction = fixed(0);
51 return;
54 const fixed max_height = tbi.max_thermal_height;
55 if (positive(max_height))
56 tbi.working_band_fraction = tbi.working_band_height / max_height;
57 else
58 tbi.working_band_fraction = fixed(1);
60 tbi.working_band_ceiling = std::max(max_height + h_safety,
61 basic.TE_altitude);
64 last_vario_available.FixTimeWarp(basic.brutto_vario_available);
65 if (basic.brutto_vario_available.Modified(last_vario_available)) {
66 last_vario_available = basic.brutto_vario_available;
68 // JMW TODO accuracy: Should really work out dt here,
69 // but i'm assuming constant time steps
71 if (tbi.max_thermal_height == fixed(0))
72 tbi.max_thermal_height = tbi.working_band_height;
74 // only do this if in thermal and have been climbing
75 if (calculated.circling && calculated.turning &&
76 positive(calculated.average))
77 tbi.Add(tbi.working_band_height, basic.brutto_vario);