Branch data Line data Source code
1 : : // ----------------- BEGIN LICENSE BLOCK --------------------------------- 2 : : // 3 : : // Copyright (C) 2018-2021 Intel Corporation 4 : : // 5 : : // SPDX-License-Identifier: MIT 6 : : // 7 : : // ----------------- END LICENSE BLOCK ----------------------------------- 8 : : /** 9 : : * @file 10 : : */ 11 : : 12 : : #pragma once 13 : : 14 : : #include "ad/map/point/GeoEdgeValidInputRange.hpp" 15 : : #include "ad/map/point/GeoPointValidInputRange.hpp" 16 : : #include "ad/map/point/PointOperation.hpp" 17 : : #include "ad/physics/Distance.hpp" 18 : : 19 : : /** @brief namespace ad */ 20 : : namespace ad { 21 : : /** @brief namespace map */ 22 : : namespace map { 23 : : /** @brief namespace point */ 24 : : namespace point { 25 : : 26 : : /** 27 : : * @brief constant defining the unknown altitude 28 : : */ 29 : : extern Altitude const AltitudeUnknown; 30 : : 31 : : /** 32 : : * @brief checks if the given GeoPoint is valid 33 : : * 34 : : * The point is valid if it's within valid input range. 35 : : */ 36 : 576859 : inline bool isValid(GeoPoint const &point, bool const logErrors = true) 37 : : { 38 : 576859 : return withinValidInputRange(point, logErrors); 39 : : } 40 : : 41 : : /** 42 : : * @brief checks if the given GeoEdge is valid 43 : : * 44 : : * The point is valid if it's within valid input range. 45 : : */ 46 : : inline bool isValid(GeoEdge const &edge, bool const logErrors = true) 47 : : { 48 : : return withinValidInputRange(edge, logErrors); 49 : : } 50 : : 51 : : /** 52 : : * @brief Convert degrees to radians. 53 : : * @param[in] deg Decimal degrees. 54 : : * @return Radians. 55 : : */ 56 : 970822 : inline double degree2radians(double degree) 57 : : { 58 : 970822 : return degree * M_PI / 180.0; 59 : : } 60 : : 61 : : /** 62 : : * @brief Convert radians to degrees. 63 : : * @param[in] rad Radians. 64 : : * @return Degrees. 65 : : */ 66 : 126194 : inline double radians2degree(double radians) 67 : : { 68 : 126194 : return radians * 180.0 / M_PI; 69 : : } 70 : : 71 : : /** 72 : : * @brief Convert Latitude to radians. 73 : : * @param[in] latitude latitude 74 : : * @return latitude in radians. 75 : : */ 76 : 485505 : inline double toRadians(Latitude const &latitude) 77 : : { 78 : 485505 : return degree2radians(static_cast<double>(latitude)); 79 : : } 80 : : 81 : : /** 82 : : * @brief Convert Longitude to radians. 83 : : * @param[in] longitude longitude 84 : : * @return longitude in radians. 85 : : */ 86 : 485205 : inline double toRadians(Longitude const &longitude) 87 : : { 88 : 485205 : return degree2radians(static_cast<double>(longitude)); 89 : : } 90 : : 91 : : /** 92 : : * @brief create a GeoPoint 93 : : * 94 : : * @param[in] longitude longitude of the point 95 : : * @param[in] latitude latitude of the point 96 : : * @param[in] altitude altitude of the point 97 : : */ 98 : 489787 : inline GeoPoint createGeoPoint(Longitude const longitude, Latitude const latitude, Altitude const altitude) 99 : : { 100 : 489787 : GeoPoint result; 101 : 489787 : result.longitude = longitude; 102 : 489787 : result.latitude = latitude; 103 : 489787 : result.altitude = altitude; 104 : 489787 : return result; 105 : : } 106 : : 107 : : /** 108 : : * @brief Computes distance between geo points. 109 : : * @returns Distance between two points in meters. 110 : : */ 111 : : physics::Distance distance(GeoPoint const &point, GeoPoint const &other); 112 : : 113 : : /** 114 : : * @returns New point with same longitude and latitude, but zero altitude. 115 : : */ 116 : : GeoPoint zeroAltitude(GeoPoint const &point); 117 : : 118 : : /** 119 : : * @brief Calculated distance between points not taking in account altitude. 120 : : * @param[in] other Other object. Must be IsValid()! 121 : : * @returns Distance between this and other point not taking in account altitude. 122 : : */ 123 : : physics::Distance flatDistance(GeoPoint const &point, const GeoPoint &other); 124 : : 125 : : /** 126 : : * @brief Approximates altitude of the point based on other points. 127 : : * @param[in] pts Set of other points that will be used in approximation. 128 : : * @returns New point with same longitude and latitude, but approximated altitude. 129 : : */ 130 : : GeoPoint approxAltitude(GeoPoint const &point, const GeoEdge &pts); 131 : : 132 : : /** 133 : : * @brief Checks if point is on the left side of the line defined by two points. 134 : : * @param[in] pt0 First point defining the line. 135 : : * @param[in] pt1 Second point defining the line. 136 : : * @returns true if this point is on the left of the line defined by pt0, pt1. 137 : : * \note Altitude is not taken in the account! 138 : : */ 139 : : bool isOnTheLeft(GeoPoint const &point, const GeoPoint &pt0, const GeoPoint &pt1); 140 : : 141 : : /** 142 : : * @brief Checks if two GeoEdge have same orientation by taking 143 : : * in account distances between first and last points. 144 : : * @param[in] pts0 First GeoEdge 145 : : * @param[in] pts1 Second GeoEdge 146 : : * @returns true if d(pt0[0], pt1[0]) <= d(pt0[0], pt1[last]) 147 : : */ 148 : : bool haveSameOrientation(const GeoEdge &pts0, const GeoEdge &pts1); 149 : : 150 : : /** 151 : : * @brief Checks if one polyline is on the left side of another polyline. 152 : : * @param[in] pts0 First GeoEdge 153 : : * @param[in] pts1 Second GeoEdge 154 : : * @returns true if pts0 is left of pts1. 155 : : * \note Altitude is not taken in the account! 156 : : */ 157 : : bool isOnTheLeft(const GeoEdge &pts0, const GeoEdge &pts1); 158 : : 159 : : /** @brief calculate the length of the provided border as distance value 160 : : */ 161 : : physics::Distance calcLength(GeoEdge const &edge); 162 : : 163 : : /** @brief specialization of vectorExtrapolate for GeoPoint 164 : : */ 165 : 2 : template <> inline GeoPoint vectorExtrapolate(GeoPoint const &a, GeoPoint const &b, double const &scalar) 166 : : { 167 : 2 : GeoPoint result; 168 [ + - + - ]: 2 : result.longitude = (1 - scalar) * a.longitude + scalar * b.longitude; 169 [ + - + - ]: 2 : result.latitude = (1 - scalar) * a.latitude + scalar * b.latitude; 170 [ + - + - ]: 2 : result.altitude = (1 - scalar) * a.altitude + scalar * b.altitude; 171 : 2 : return result; 172 : : } 173 : : 174 : : } // namespace point 175 : : } // namespace map 176 : : } // namespace ad