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.
23 #ifndef GEO_VECTOR_HPP
24 #define GEO_VECTOR_HPP
26 #include "Math/Angle.hpp"
29 #include <type_traits>
34 * A constant bearing vector in lat/lon coordinates.
35 * Should later be extended to handle
36 * separately constant bearing and minimum-distance paths.
40 /** Distance in meters */
43 /** Bearing (true north) */
46 /** Empty non-initializing constructor */
47 GeoVector() = default;
49 /** Constructor given supplied distance/bearing */
51 GeoVector(fixed _distance
, Angle _bearing
)
52 :distance(_distance
), bearing(_bearing
) {}
55 * Constructor given start and end location.
56 * Computes Distance/Bearing internally.
58 GeoVector(const GeoPoint
&source
, const GeoPoint
&target
);
61 * Create the zero vector: zero distance, undefined bearing.
63 constexpr static GeoVector
Zero() {
64 return GeoVector(fixed(0), Angle::Zero());
68 * Create an invalid instance.
71 static GeoVector
Invalid() {
72 return GeoVector(fixed(-1), Angle::Zero());
76 * Returns the end point of the geovector projected from the start point.
77 * Assumes constant bearing.
80 GeoPoint
EndPoint(const GeoPoint
&source
) const;
83 * Returns the end point of the geovector projected from the start point.
84 * Assumes constand Bearing.
86 * @param source start of vector
87 * @return location of end point
89 GeoPoint
MidPoint(const GeoPoint
&source
) const;
92 * Minimum distance from a point on the vector to the reference
94 * @param source Start of vector
95 * @param ref Point to test
97 * @return Distance (m)
100 fixed
MinimumDistance(const GeoPoint
&source
, const GeoPoint
&ref
) const;
103 inline bool IsValid() const {
104 return !negative(distance
);
108 distance
= fixed(-1);
112 static_assert(std::is_trivial
<GeoVector
>::value
, "type is not trivial");