SectorZone: add attribute arc_boundary
[xcsoar.git] / src / Geo / SearchPoint.hpp
blob2c4c326592e6f92ec37ee6c8d8ee8b1fbcc95d80
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef SEARCH_POINT_HPP
23 #define SEARCH_POINT_HPP
25 #include "GeoPoint.hpp"
26 #include "Flat/FlatGeoPoint.hpp"
27 #include "Util/TypeTraits.hpp"
29 #include <assert.h>
31 class TaskProjection;
33 /**
34 * Class used to hold a geodetic point, its projected integer form.
36 class SearchPoint
38 GeoPoint location;
39 FlatGeoPoint flat_location;
41 #ifndef NDEBUG
42 bool projected;
43 #endif
45 public:
46 /**
47 * Dummy constructor
49 * @return Null object
51 #ifdef NDEBUG
52 SearchPoint() = default;
53 #else
54 SearchPoint():projected(false) {}
55 #endif
57 /**
58 * Constructor. The flat location is not initialized here; the
59 * method project() must be called before you can use it.
61 * @param loc Location of search point
62 * @param tp Projection used
64 SearchPoint(const GeoPoint &loc)
65 :location(loc)
66 #ifndef NDEBUG
67 , projected(false)
68 #endif
71 SearchPoint(const GeoPoint &_location, const FlatGeoPoint &_flat)
72 :location(_location), flat_location(_flat)
73 #ifndef NDEBUG
74 , projected(true)
75 #endif
79 /**
80 * Constructor
82 * @param loc Location of search point
83 * @param tp Projection used
85 SearchPoint(const GeoPoint &loc, const TaskProjection& tp);
87 /**
88 * Constructor
90 * @param floc Location of search point
91 * @param tp Projection used
93 SearchPoint(const FlatGeoPoint &floc, const TaskProjection& tp);
95 gcc_const
96 static SearchPoint Invalid() {
97 return SearchPoint(GeoPoint::Invalid());
100 gcc_pure
101 bool IsValid() const {
102 return location.IsValid();
105 void SetInvalid() {
106 location.SetInvalid();
107 #ifndef NDEBUG
108 projected = false;
109 #endif
113 * Calculate projected value of geodetic coordinate
115 * @param tp Projection used
117 void Project(const TaskProjection& tp);
120 * The actual location
122 const GeoPoint &GetLocation() const {
123 return location;
127 * Accessor for flat projected coordinate
129 * @return Flat projected coordinate
131 const FlatGeoPoint &GetFlatLocation() const {
132 assert(projected);
134 return flat_location;
138 * Test whether two points are coincident (by their geodetic coordinates)
140 * @param sp Point to compare with
142 * @return True if points coincident
144 gcc_pure
145 bool Equals(const SearchPoint& sp) const {
146 return sp.location == location;
150 * Calculate flat earth distance between two points
152 * @param sp Point to measure distance from
154 * @return Distance in projected units
156 gcc_pure
157 unsigned FlatDistanceTo(const SearchPoint &sp) const {
158 return flat_location.Distance(sp.flat_location);
162 * Calculate the "flat" square distance. This is cheaper than
163 * flat_distance(), because it does not need to calculate the square
164 * root.
166 gcc_pure
167 unsigned FlatSquareDistanceTo(const SearchPoint& sp) const {
168 return flat_location.DistanceSquared(sp.flat_location);
172 * Rank two points according to longitude, then latitude
174 * @param other Point to compare to
176 * @return True if this point is further left (or if equal, lower) than the other
178 gcc_pure
179 bool Sort(const SearchPoint &other) const {
180 return location.Sort(other.location);
184 * distance from this to the reference
186 fixed DistanceTo(const GeoPoint &ref) const {
187 return location.Distance(ref);
191 static_assert(is_trivial_ndebug<SearchPoint>::value, "type is not trivial");
194 #endif