SectorZone: add attribute arc_boundary
[xcsoar.git] / src / Geo / GeoVector.hpp
blobf8fe654c9859b6e162ffa3eb5333e36ca9131bd2
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.
23 #ifndef GEO_VECTOR_HPP
24 #define GEO_VECTOR_HPP
26 #include "Math/Angle.hpp"
27 #include "Compiler.h"
29 #include <type_traits>
31 struct GeoPoint;
33 /**
34 * A constant bearing vector in lat/lon coordinates.
35 * Should later be extended to handle
36 * separately constant bearing and minimum-distance paths.
39 struct GeoVector {
40 /** Distance in meters */
41 fixed distance;
43 /** Bearing (true north) */
44 Angle bearing;
46 /** Empty non-initializing constructor */
47 GeoVector() = default;
49 /** Constructor given supplied distance/bearing */
50 constexpr
51 GeoVector(fixed _distance, Angle _bearing)
52 :distance(_distance), bearing(_bearing) {}
54 /**
55 * Constructor given start and end location.
56 * Computes Distance/Bearing internally.
58 GeoVector(const GeoPoint &source, const GeoPoint &target);
60 /**
61 * Create the zero vector: zero distance, undefined bearing.
63 constexpr static GeoVector Zero() {
64 return GeoVector(fixed(0), Angle::Zero());
67 /**
68 * Create an invalid instance.
70 constexpr
71 static GeoVector Invalid() {
72 return GeoVector(fixed(-1), Angle::Zero());
75 /**
76 * Returns the end point of the geovector projected from the start point.
77 * Assumes constant bearing.
79 gcc_pure
80 GeoPoint EndPoint(const GeoPoint &source) const;
82 /**
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;
91 /**
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)
99 gcc_pure
100 fixed MinimumDistance(const GeoPoint &source, const GeoPoint &ref) const;
102 constexpr
103 inline bool IsValid() const {
104 return !negative(distance);
107 void SetInvalid() {
108 distance = fixed(-1);
112 static_assert(std::is_trivial<GeoVector>::value, "type is not trivial");
114 #endif