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

marble

  • sources
  • kde-4.12
  • 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::isClosed() const
36 {
37  return true;
38 }
39 
40 qreal GeoDataLinearRing::length( qreal planetRadius, int offset ) const
41 {
42  qreal length = GeoDataLineString::length( planetRadius, offset );
43 
44  return length + planetRadius * distanceSphere( last(), first() );
45 }
46 
47 bool GeoDataLinearRing::contains( const GeoDataCoordinates &coordinates ) const
48 {
49  // Quick bounding box check
50  if ( !latLonAltBox().contains( coordinates ) ) {
51  return false;
52  }
53 
54  int const points = size();
55  bool inside = false; // also true for points = 0
56  int j = points - 1;
57 
58  for ( int i=0; i<points; ++i ) {
59  GeoDataCoordinates const & one = at( i );
60  GeoDataCoordinates const & two = at( j );
61 
62  if ( ( one.longitude() < coordinates.longitude() && two.longitude() >= coordinates.longitude() ) ||
63  ( two.longitude() < coordinates.longitude() && one.longitude() >= coordinates.longitude() ) ) {
64  if ( one.latitude() + ( coordinates.longitude() - one.longitude()) / ( two.longitude() - one.longitude()) * ( two.latitude()-one.latitude() ) < coordinates.latitude() ) {
65  inside = !inside;
66  }
67  }
68 
69  j = i;
70  }
71 
72  return inside;
73 }
74 
75 }
Marble::GeoDataLinearRingPrivate
Definition: GeoDataLinearRing_p.h:21
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:559
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:165
MarbleMath.h
Marble::GeoDataLinearRing::contains
virtual bool contains(const GeoDataCoordinates &coordinates) const
Returns whether the given coordinates lie within the polygon.
Definition: GeoDataLinearRing.cpp:47
Marble::GeoDataLineString::size
int size() const
Returns the number of nodes in a LineString.
Definition: GeoDataLineString.cpp:134
Marble::GeoDataGeometry
A base class for all geodata features.
Definition: GeoDataGeometry.h:47
Marble::GeoDataLinearRing::isClosed
virtual bool isClosed() const
Returns whether a LinearRing is a closed polygon.
Definition: GeoDataLinearRing.cpp:35
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:173
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:139
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::length
virtual qreal length(qreal planetRadius, int offset=0) const
Returns the length of the LinearRing across a sphere.
Definition: GeoDataLinearRing.cpp:40
Marble::GeoDataLineString::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Returns the smallest latLonAltBox that contains the LineString.
Definition: GeoDataLineString.cpp:545
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:49 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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