Android release v6.7_preview1
[xcsoar.git] / src / Waypoint / WaypointFilter.cpp
blob7a665c3807edfbf26dd22384e70f2a360de4e7d0
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 "WaypointFilter.hpp"
25 #include "Waypoint/Waypoint.hpp"
26 #include "Engine/Task/Shapes/FAITrianglePointValidator.hpp"
28 bool
29 WaypointFilter::CompareType(const Waypoint &waypoint, TypeFilter type,
30 const FAITrianglePointValidator &triangle_validator)
32 switch (type) {
33 case TypeFilter::ALL:
34 return true;
36 case TypeFilter::AIRPORT:
37 return waypoint.IsAirport();
39 case TypeFilter::LANDABLE:
40 return waypoint.IsLandable();
42 case TypeFilter::TURNPOINT:
43 return waypoint.IsTurnpoint();
45 case TypeFilter::START:
46 return waypoint.IsStartpoint();
48 case TypeFilter::FINISH:
49 return waypoint.IsFinishpoint();
51 case TypeFilter::FAI_TRIANGLE_LEFT:
52 return triangle_validator.IsFAITrianglePoint(waypoint, false);
54 case TypeFilter::FAI_TRIANGLE_RIGHT:
55 return triangle_validator.IsFAITrianglePoint(waypoint, true);
57 case TypeFilter::FILE_1:
58 return waypoint.file_num == 1;
60 case TypeFilter::FILE_2:
61 return waypoint.file_num == 2;
63 case TypeFilter::LAST_USED:
64 return false;
67 /* not reachable */
68 return false;
71 bool
72 WaypointFilter::CompareType(const Waypoint &waypoint,
73 const FAITrianglePointValidator &triangle_validator) const
75 return CompareType(waypoint, type_index, triangle_validator);
78 bool
79 WaypointFilter::CompareDirection(const Waypoint &waypoint, Angle angle,
80 GeoPoint location)
82 if (negative(angle.Native()))
83 return true;
85 auto bearing = location.Bearing(waypoint.location);
86 fixed direction_error = (bearing - angle).AsDelta().AbsoluteDegrees();
88 return direction_error < fixed(18);
91 bool
92 WaypointFilter::CompareDirection(const Waypoint &waypoint,
93 GeoPoint location) const
95 return CompareDirection(waypoint, direction, location);
98 bool
99 WaypointFilter::CompareName(const Waypoint &waypoint, const TCHAR *name)
101 return StringIsEqualIgnoreCase(waypoint.name.c_str(), name, _tcslen(name));
104 bool
105 WaypointFilter::CompareName(const Waypoint &waypoint) const
107 return CompareName(waypoint, name);
110 bool
111 WaypointFilter::Matches(const Waypoint &waypoint, GeoPoint location,
112 const FAITrianglePointValidator &triangle_validator) const
114 return CompareType(waypoint, triangle_validator) &&
115 (!positive(distance) || CompareName(waypoint)) &&
116 CompareDirection(waypoint, location);