Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / src / Engine / Route / ReachResult.hpp
blob92ac06745da29cd2ae8f593521e45ba068d92c60
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 #ifndef XCSOAR_REACH_RESULT_HPP
25 #define XCSOAR_REACH_RESULT_HPP
27 #include "Rough/RoughAltitude.hpp"
29 #include <stdint.h>
30 #include <stdlib.h>
32 /**
33 * The result of a reach calculation.
35 struct ReachResult {
36 enum class Validity : uint8_t {
37 INVALID,
38 VALID,
39 UNREACHABLE,
42 /**
43 * The arrival altitude for straight glide, ignoring terrain
44 * obstacles.
46 RoughAltitude direct;
48 /**
49 * The arrival altitude considering detour to avoid terrain
50 * obstacles. This attribute may only be used if #terrain_valid is
51 * #VALID.
53 RoughAltitude terrain;
55 /**
56 * This attribute describes whether the #terrain attribute is valid.
58 Validity terrain_valid;
60 void Clear() {
61 direct = terrain = -1;
62 terrain_valid = Validity::INVALID;
65 bool IsReachableDirect() const {
66 return direct.IsPositive();
69 bool IsReachableTerrain() const {
70 return terrain_valid == Validity::VALID && terrain.IsPositive();
73 bool IsDeltaConsiderable() const {
74 if (terrain_valid != Validity::VALID)
75 return false;
77 const int delta = abs((int)direct - (int)terrain);
78 return delta >= 10 && delta * 100 / (int)direct > 5;
81 bool IsReachRelevant() const {
82 return terrain_valid == Validity::VALID && terrain != direct;
85 void Add(RoughAltitude delta) {
86 direct += delta;
87 terrain += delta;
90 void Subtract(RoughAltitude delta) {
91 direct -= delta;
92 terrain -= delta;
96 #endif