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
7#include "GeoDataLinearRing.h"
8#include "GeoDataLinearRing_p.h"
9
10#include "GeoDataTypes.h"
11#include "MarbleDebug.h"
12
13namespace Marble
14{
15
17 : GeoDataLineString( new GeoDataLinearRingPrivate( f ) )
18{
19}
20
25
29
30const char *GeoDataLinearRing::nodeType() const
31{
32 return GeoDataTypes::GeoDataLinearRingType;
33}
34
35EnumGeometryId GeoDataLinearRing::geometryId() const
36{
37 return GeoDataLinearRingId;
38}
39
40GeoDataGeometry *GeoDataLinearRing::copy() const
41{
42 return new GeoDataLinearRing(*this);
43}
44
46{
47 return isClosed() == other.isClosed() &&
49}
50
51bool GeoDataLinearRing::operator!=( const GeoDataLinearRing &other ) const
52{
53 return !this->operator==(other);
54}
55
57{
58 return true;
59}
60
61qreal GeoDataLinearRing::length( qreal planetRadius, int offset ) const
62{
63 qreal length = GeoDataLineString::length( planetRadius, offset );
64
65 return length + planetRadius * last().sphericalDistanceTo(first());
66}
67
68bool GeoDataLinearRing::contains( const GeoDataCoordinates &coordinates ) const
69{
70 // Quick bounding box check
71 if ( !latLonAltBox().contains( coordinates ) ) {
72 return false;
73 }
74
75 int const points = size();
76 bool inside = false; // also true for points = 0
77 int j = points - 1;
78
79 for ( int i=0; i<points; ++i ) {
80 GeoDataCoordinates const & one = operator[]( i );
81 GeoDataCoordinates const & two = operator[]( j );
82
83 if ( ( one.longitude() < coordinates.longitude() && two.longitude() >= coordinates.longitude() ) ||
84 ( two.longitude() < coordinates.longitude() && one.longitude() >= coordinates.longitude() ) ) {
85 if ( one.latitude() + ( coordinates.longitude() - one.longitude()) / ( two.longitude() - one.longitude()) * ( two.latitude()-one.latitude() ) < coordinates.latitude() ) {
86 inside = !inside;
87 }
88 }
89
90 j = i;
91 }
92
93 return inside;
94}
95
97{
98 int const n = size();
99 qreal area = 0;
100 for ( int i = 1; i < n; ++i ){
101 area += ( operator[]( i ).longitude() - operator[]( i - 1 ).longitude() ) * ( operator[]( i ).latitude() + operator[]( i - 1 ).latitude() );
102 }
103 area += ( operator[]( 0 ).longitude() - operator[]( n - 1 ).longitude() ) * ( operator[] ( 0 ).latitude() + operator[]( n - 1 ).latitude() );
104
105 return area > 0;
106}
107
108}
A 3d point representation.
qreal longitude(GeoDataCoordinates::Unit unit) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
qreal latitude(GeoDataCoordinates::Unit unit) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
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 Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.