• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • geodata
  • data
GeoDataLinearRing.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2008 Torsten Rahn <rahn@kde.org>
9 //
10 
11 
12 #include "GeoDataLinearRing.h"
13 #include "GeoDataLinearRing_p.h"
14 
15 #include "MarbleMath.h"
16 #include "MarbleDebug.h"
17 
18 namespace Marble
19 {
20 
21 GeoDataLinearRing::GeoDataLinearRing( TessellationFlags f )
22  : GeoDataLineString( new GeoDataLinearRingPrivate( f ) )
23 {
24 }
25 
26 GeoDataLinearRing::GeoDataLinearRing( const GeoDataGeometry & other )
27  : GeoDataLineString( other )
28 {
29 }
30 
31 GeoDataLinearRing::~GeoDataLinearRing()
32 {
33 }
34 
35 bool GeoDataLinearRing::operator==( const GeoDataLinearRing &other ) const
36 {
37  return isClosed() == other.isClosed() &&
38  GeoDataLineString::operator==( other );
39 }
40 
41 bool GeoDataLinearRing::operator!=( const GeoDataLinearRing &other ) const
42 {
43  return !this->operator==(other);
44 }
45 
46 bool GeoDataLinearRing::isClosed() const
47 {
48  return true;
49 }
50 
51 qreal GeoDataLinearRing::length( qreal planetRadius, int offset ) const
52 {
53  qreal length = GeoDataLineString::length( planetRadius, offset );
54 
55  return length + planetRadius * distanceSphere( last(), first() );
56 }
57 
58 bool GeoDataLinearRing::contains( const GeoDataCoordinates &coordinates ) const
59 {
60  // Quick bounding box check
61  if ( !latLonAltBox().contains( coordinates ) ) {
62  return false;
63  }
64 
65  int const points = size();
66  bool inside = false; // also true for points = 0
67  int j = points - 1;
68 
69  for ( int i=0; i<points; ++i ) {
70  GeoDataCoordinates const & one = at( i );
71  GeoDataCoordinates const & two = at( j );
72 
73  if ( ( one.longitude() < coordinates.longitude() && two.longitude() >= coordinates.longitude() ) ||
74  ( two.longitude() < coordinates.longitude() && one.longitude() >= coordinates.longitude() ) ) {
75  if ( one.latitude() + ( coordinates.longitude() - one.longitude()) / ( two.longitude() - one.longitude()) * ( two.latitude()-one.latitude() ) < coordinates.latitude() ) {
76  inside = !inside;
77  }
78  }
79 
80  j = i;
81  }
82 
83  return inside;
84 }
85 
86 bool GeoDataLinearRing::isClockwise() const
87 {
88  int n = size();
89  qreal area = 0;
90  for ( int i = 1; i < n - 1; ++i ){
91  area += ( at( i ).longitude() - at( i - 1 ).longitude() ) * ( at( i ).latitude() + at( i - 1 ).latitude() );
92  }
93  area += ( at( 0 ).longitude() - at( n - 2 ).longitude() ) * ( at ( 0 ).latitude() + at( n - 2 ).latitude() );
94 
95  return area > 0;
96 }
97 
98 }
Marble::GeoDataLinearRingPrivate
Definition: GeoDataLinearRing_p.h:21
Marble::GeoDataLinearRing::operator!=
bool operator!=(const GeoDataLinearRing &other) const
Definition: GeoDataLinearRing.cpp:41
Marble::GeoDataLineString::length
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...
Definition: GeoDataLineString.cpp:594
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataLineString::last
GeoDataCoordinates & last()
Returns a reference to the last node in the LineString. This method detaches the returned coordinate ...
Definition: GeoDataLineString.cpp:169
Marble::GeoDataLinearRing
A LinearRing that allows to store a closed, contiguous set of line segments.
Definition: GeoDataLinearRing.h:68
MarbleMath.h
Marble::GeoDataLinearRing::contains
virtual bool contains(const GeoDataCoordinates &coordinates) const
Returns whether the given coordinates lie within the polygon.
Definition: GeoDataLinearRing.cpp:58
Marble::GeoDataLineString::size
int size() const
Returns the number of nodes in a LineString.
Definition: GeoDataLineString.cpp:138
Marble::GeoDataGeometry
A base class for all geodata features.
Definition: GeoDataGeometry.h:47
Marble::GeoDataLineString::operator==
bool operator==(const GeoDataLineString &other) const
Returns true/false depending on whether this and other are/are not equal.
Definition: GeoDataLineString.cpp:267
Marble::GeoDataLinearRing::isClosed
virtual bool isClosed() const
Returns whether a LinearRing is a closed polygon.
Definition: GeoDataLinearRing.cpp:46
Marble::distanceSphere
qreal distanceSphere(qreal lon1, qreal lat1, qreal lon2, qreal lat2)
This method calculates the shortest distance between two points on a sphere.
Definition: MarbleMath.h:52
GeoDataLinearRing_p.h
Marble::GeoDataCoordinates::latitude
qreal latitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
Definition: GeoDataCoordinates.cpp:751
MarbleDebug.h
Marble::GeoDataLinearRing::GeoDataLinearRing
GeoDataLinearRing(TessellationFlags f=NoTessellation)
Creates a new LinearRing.
Definition: GeoDataLinearRing.cpp:21
Marble::GeoDataLinearRing::~GeoDataLinearRing
virtual ~GeoDataLinearRing()
Destroys a LinearRing.
Definition: GeoDataLinearRing.cpp:31
Marble::GeoDataLineString::first
GeoDataCoordinates & first()
Returns a reference to the first node in the LineString. This method detaches the returned coordinate...
Definition: GeoDataLineString.cpp:177
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
Marble::GeoDataLineString::at
GeoDataCoordinates & at(int pos)
Returns a reference to the coordinates of a node at a given position. This method detaches the return...
Definition: GeoDataLineString.cpp:143
Marble::GeoDataCoordinates::longitude
qreal longitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
Definition: GeoDataCoordinates.cpp:739
GeoDataLinearRing.h
Marble::GeoDataLinearRing::operator==
bool operator==(const GeoDataLinearRing &other) const
Returns true/false depending on whether this and other are/are not equal.
Definition: GeoDataLinearRing.cpp:35
Marble::GeoDataLinearRing::length
virtual qreal length(qreal planetRadius, int offset=0) const
Returns the length of the LinearRing across a sphere.
Definition: GeoDataLinearRing.cpp:51
Marble::GeoDataLinearRing::isClockwise
virtual bool isClockwise() const
Returns whether the orientaion of ring is coloskwise or not.
Definition: GeoDataLinearRing.cpp:86
Marble::GeoDataLineString::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Returns the smallest latLonAltBox that contains the LineString.
Definition: GeoDataLineString.cpp:580
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal