File indexing completed on 2024-05-12 04:42:18
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef OSM_GEOMATH_H 0008 #define OSM_GEOMATH_H 0009 0010 #include "kosm_export.h" 0011 0012 #include "datatypes.h" 0013 0014 #include <cmath> 0015 0016 namespace OSM { 0017 0018 /** Degree to radian conversion. */ 0019 [[nodiscard]] constexpr inline double degToRad(double deg) 0020 { 0021 return deg / 180.0 * M_PI; 0022 } 0023 /** Radian to degree conversion. */ 0024 [[nodiscard]] constexpr inline double radToDeg(double rad) 0025 { 0026 return rad / M_PI * 180.0; 0027 } 0028 0029 /** Distance between two coordinates. */ 0030 [[nodiscard]] KOSM_EXPORT double distance(double lat1, double lon1, double lat2, double lon2); 0031 0032 /** Distance between @p coord1 and @p coord2 in meter. */ 0033 [[nodiscard]] KOSM_EXPORT double distance(Coordinate coord1, Coordinate coord2); 0034 0035 /** Distance in meters between a line segment defined by @p l1 and @p l2 to a point @p p. */ 0036 [[nodiscard]] double distance(Coordinate l1, Coordinate l2, Coordinate p); 0037 0038 /** Distance between the given polygon and coordinate, in meter. */ 0039 [[nodiscard]] KOSM_EXPORT double distance(const std::vector<const OSM::Node*> &path, Coordinate coord); 0040 0041 } 0042 0043 #endif // OSM_GEOMATH_H