Marble

GeoDataLinearRing.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2008 Torsten Rahn <[email protected]>
4 //
5 
6 
7 #include "GeoDataLinearRing.h"
8 #include "GeoDataLinearRing_p.h"
9 
10 #include "GeoDataTypes.h"
11 #include "MarbleDebug.h"
12 
13 namespace Marble
14 {
15 
17  : GeoDataLineString( new GeoDataLinearRingPrivate( f ) )
18 {
19 }
20 
22  : GeoDataLineString( other )
23 {
24 }
25 
27 {
28 }
29 
30 const char *GeoDataLinearRing::nodeType() const
31 {
32  return GeoDataTypes::GeoDataLinearRingType;
33 }
34 
35 EnumGeometryId GeoDataLinearRing::geometryId() const
36 {
37  return GeoDataLinearRingId;
38 }
39 
40 GeoDataGeometry *GeoDataLinearRing::copy() const
41 {
42  return new GeoDataLinearRing(*this);
43 }
44 
46 {
47  return isClosed() == other.isClosed() &&
49 }
50 
51 bool GeoDataLinearRing::operator!=( const GeoDataLinearRing &other ) const
52 {
53  return !this->operator==(other);
54 }
55 
57 {
58  return true;
59 }
60 
61 qreal 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 
68 bool 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.
~GeoDataLinearRing() override
Destroys a LinearRing.
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
bool operator==(const GeoDataLinearRing &other) const
Returns true/false depending on whether this and other are/are not equal.
A base class for all geodata features.
qreal longitude(GeoDataCoordinates::Unit unit) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
qreal length(qreal planetRadius, int offset=0) const override
Returns the length of the LinearRing across a sphere.
GeoDataCoordinates & last()
Returns a reference to the last node in the LineString. This method detaches the returned coordinate ...
A LineString that allows to store a contiguous set of line segments.
const GeoDataLatLonAltBox & latLonAltBox() const override
Returns the smallest latLonAltBox that contains the LineString.
virtual bool contains(const GeoDataCoordinates &coordinates) const
Returns whether the given coordinates lie within the polygon.
virtual bool isClockwise() const
Returns whether the orientaion of ring is coloskwise or not.
qreal latitude(GeoDataCoordinates::Unit unit) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
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...
Binds a QML item to a specific geodetic location in screen coordinates.
GeoDataCoordinates & first()
Returns a reference to the first node in the LineString. This method detaches the returned coordinate...
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...
GeoDataLinearRing(TessellationFlags f=NoTessellation)
Creates a new LinearRing.
bool isClosed() const override
Returns whether a LinearRing is a closed polygon.
qreal sphericalDistanceTo(const GeoDataCoordinates &other) const
This method calculates the shortest distance between two points on a sphere.
A LinearRing that allows to store a closed, contiguous set of line segments.
int size() const
Returns the number of nodes in a LineString.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Sep 25 2023 03:50:18 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.