Marble

GeoDataLinearRing.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2008 Torsten Rahn <rahn@kde.org>
4//
5
6#include "GeoDataLinearRing.h"
7#include "GeoDataLinearRing_p.h"
8
9#include "GeoDataTypes.h"
10#include "MarbleDebug.h"
11
12namespace Marble
13{
14
16 : GeoDataLineString(new GeoDataLinearRingPrivate(f))
17{
18}
19
24
26
27const char *GeoDataLinearRing::nodeType() const
28{
29 return GeoDataTypes::GeoDataLinearRingType;
30}
31
32EnumGeometryId GeoDataLinearRing::geometryId() const
33{
34 return GeoDataLinearRingId;
35}
36
37GeoDataGeometry *GeoDataLinearRing::copy() const
38{
39 return new GeoDataLinearRing(*this);
40}
41
43{
44 return isClosed() == other.isClosed() && GeoDataLineString::operator==(other);
45}
46
47bool GeoDataLinearRing::operator!=(const GeoDataLinearRing &other) const
48{
49 return !this->operator==(other);
50}
51
53{
54 return true;
55}
56
57qreal GeoDataLinearRing::length(qreal planetRadius, int offset) const
58{
59 qreal length = GeoDataLineString::length(planetRadius, offset);
60
61 return length + planetRadius * last().sphericalDistanceTo(first());
62}
63
64bool GeoDataLinearRing::contains(const GeoDataCoordinates &coordinates) const
65{
66 // Quick bounding box check
67 if (!latLonAltBox().contains(coordinates)) {
68 return false;
69 }
70
71 int const points = size();
72 bool inside = false; // also true for points = 0
73 int j = points - 1;
74
75 for (int i = 0; i < points; ++i) {
76 GeoDataCoordinates const &one = operator[](i);
77 GeoDataCoordinates const &two = operator[](j);
78
79 if ((one.longitude() < coordinates.longitude() && two.longitude() >= coordinates.longitude())
80 || (two.longitude() < coordinates.longitude() && one.longitude() >= coordinates.longitude())) {
81 if (one.latitude() + (coordinates.longitude() - one.longitude()) / (two.longitude() - one.longitude()) * (two.latitude() - one.latitude())
82 < coordinates.latitude()) {
83 inside = !inside;
84 }
85 }
86
87 j = i;
88 }
89
90 return inside;
91}
92
94{
95 int const n = size();
96 qreal area = 0;
97 for (int i = 1; i < n; ++i) {
98 area += (operator[](i).longitude() - operator[](i - 1).longitude()) * (operator[](i).latitude() + operator[](i - 1).latitude());
99 }
100 area += (operator[](0).longitude() - operator[](n - 1).longitude()) * (operator[](0).latitude() + operator[](n - 1).latitude());
101
102 return area > 0;
103}
104
105}
A 3d point representation.
qreal sphericalDistanceTo(const GeoDataCoordinates &other) const
This method calculates the shortest distance between two points on a sphere.
A base class for all geodata features.
A LineString that allows to store a contiguous set of line segments.
GeoDataCoordinates & first()
Returns a reference to the first node in the LineString. This method detaches the returned coordinate...
int size() const
Returns the number of nodes in a LineString.
const GeoDataLatLonAltBox & latLonAltBox() const override
Returns the smallest latLonAltBox that contains the LineString.
bool operator==(const GeoDataLineString &other) const
Returns true/false depending on whether this and other are/are not equal.
GeoDataCoordinates & operator[](int pos)
Returns a reference to the coordinates of a node at a given position. This method detaches the return...
virtual qreal length(qreal planetRadius, int offset=0) const
Returns the length of LineString across a sphere starting from a coordinate in LineString This method...
GeoDataCoordinates & last()
Returns a reference to the last node in the LineString. This method detaches the returned coordinate ...
A LinearRing that allows to store a closed, contiguous set of line segments.
~GeoDataLinearRing() override
Destroys a LinearRing.
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
bool isClosed() const override
Returns whether a LinearRing is a closed polygon.
virtual bool isClockwise() const
Returns whether the orientaion of ring is coloskwise or not.
virtual bool contains(const GeoDataCoordinates &coordinates) const
Returns whether the given coordinates lie within the polygon.
bool operator==(const GeoDataLinearRing &other) const
Returns true/false depending on whether this and other are/are not equal.
GeoDataLinearRing(TessellationFlags f=NoTessellation)
Creates a new LinearRing.
qreal length(qreal planetRadius, int offset=0) const override
Returns the length of the LinearRing across a sphere.
Binds a QML item to a specific geodetic location in screen coordinates.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.