File indexing completed on 2024-05-05 04:22:10

0001 // SPDX-FileCopyrightText: 2018-2019 The KPhotoAlbum Development Team
0002 // SPDX-FileCopyrightText: 2021 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0003 //
0004 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 
0006 #include "GeoCoordinates.h"
0007 
0008 #include <marble/GeoDataLatLonAltBox.h>
0009 
0010 bool Map::GeoCoordinates::hasCoordinates() const
0011 {
0012     return m_hasCoordinates;
0013 }
0014 
0015 double Map::GeoCoordinates::lon() const
0016 {
0017     return m_lon;
0018 }
0019 
0020 double Map::GeoCoordinates::lat() const
0021 {
0022     return m_lat;
0023 }
0024 
0025 double Map::GeoCoordinates::alt() const
0026 {
0027     return m_alt;
0028 }
0029 
0030 bool Map::GeoCoordinates::hasAltitude() const
0031 {
0032     return m_hasAlt;
0033 }
0034 
0035 void Map::GeoCoordinates::setLatLon(const double lat, const double lon)
0036 {
0037     m_lat = lat;
0038     m_lon = lon;
0039     m_hasCoordinates = true;
0040 }
0041 
0042 void Map::GeoCoordinates::setAlt(const double alt)
0043 {
0044     m_alt = alt;
0045     m_hasAlt = true;
0046 }
0047 
0048 Map::GeoCoordinates::operator QString() const
0049 {
0050     return QStringLiteral("(%1, %2)").arg(m_lon).arg(m_lat);
0051 }
0052 
0053 Map::GeoCoordinates::LatLonBox::LatLonBox(double north, double south, double east, double west)
0054     : north(north)
0055     , south(south)
0056     , east(east)
0057     , west(west)
0058 {
0059 }
0060 
0061 Map::GeoCoordinates::LatLonBox::LatLonBox(const Marble::GeoDataLatLonBox &box)
0062     : north(box.north(Marble::GeoDataCoordinates::Degree))
0063     , south(box.south(Marble::GeoDataCoordinates::Degree))
0064     , east(box.east(Marble::GeoDataCoordinates::Degree))
0065     , west(box.west(Marble::GeoDataCoordinates::Degree))
0066 {
0067 }
0068 
0069 bool Map::GeoCoordinates::LatLonBox::isNull() const
0070 {
0071     return north == 0 && south == 0 && east == 0 && west == 0;
0072 }
0073 
0074 bool Map::GeoCoordinates::LatLonBox::contains(const Map::GeoCoordinates &point) const
0075 {
0076     // increase size by delta in all directions for the check
0077     // this fixes numerical issues with those images that lie directly on the border
0078     const double delta = 0.000001;
0079     const double lat = point.lat();
0080     if (lat < south - delta || lat > north + delta) {
0081         return false;
0082     }
0083     const double lon = point.lon();
0084     if (((lon < west - delta || lon > east + delta)
0085          && (west < east))
0086         || ((lon < west - delta && lon > east + delta)
0087             && (east < west))) {
0088         return false;
0089     }
0090     return true;
0091 }
0092 Map::GeoCoordinates::LatLonBox::operator QString() const
0093 {
0094     return QStringLiteral("(N%1, S%2, E%3, W%4)").arg(north).arg(south).arg(east).arg(west);
0095 }
0096 
0097 // vi:expandtab:tabstop=4 shiftwidth=4: