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"
34 * Class used to hold a geodetic point, its projected integer form.
39 FlatGeoPoint flat_location
;
52 SearchPoint() = default;
54 SearchPoint():projected(false) {}
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
)
71 SearchPoint(const GeoPoint
&_location
, const FlatGeoPoint
&_flat
)
72 :location(_location
), flat_location(_flat
)
82 * @param loc Location of search point
83 * @param tp Projection used
85 SearchPoint(const GeoPoint
&loc
, const TaskProjection
& tp
);
90 * @param floc Location of search point
91 * @param tp Projection used
93 SearchPoint(const FlatGeoPoint
&floc
, const TaskProjection
& tp
);
96 static SearchPoint
Invalid() {
97 return SearchPoint(GeoPoint::Invalid());
101 bool IsValid() const {
102 return location
.IsValid();
106 location
.SetInvalid();
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 {
127 * Accessor for flat projected coordinate
129 * @return Flat projected coordinate
131 const FlatGeoPoint
&GetFlatLocation() const {
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
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
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
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
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");