/
qgscurve.cpp
131 lines (112 loc) · 3.27 KB
/
qgscurve.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/***************************************************************************
qgscurve.cpp
--------------
begin : November 2014
copyright : (C) 2014 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgscurve.h"
#include "qgslinestring.h"
#include "qgspointv2.h"
#include "qgsmultipoint.h"
QgsCurve::QgsCurve(): QgsAbstractGeometry()
{}
QgsCurve::~QgsCurve()
{}
bool QgsCurve::isClosed() const
{
if ( numPoints() == 0 )
return false;
//don't consider M-coordinates when testing closedness
QgsPointV2 start = startPoint();
QgsPointV2 end = endPoint();
return ( qgsDoubleNear( start.x(), end.x(), 1E-8 ) &&
qgsDoubleNear( start.y(), end.y(), 1E-8 ) &&
qgsDoubleNear( start.z(), end.z(), 1E-8 ) );
}
bool QgsCurve::isRing() const
{
return ( isClosed() && numPoints() >= 4 );
}
QgsCoordinateSequence QgsCurve::coordinateSequence() const
{
if ( !mCoordinateSequence.isEmpty() )
return mCoordinateSequence;
mCoordinateSequence.append( QgsRingSequence() );
mCoordinateSequence.back().append( QgsPointSequence() );
points( mCoordinateSequence.back().back() );
return mCoordinateSequence;
}
bool QgsCurve::nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const
{
if ( id.vertex < 0 )
{
id.vertex = 0;
if ( id.part < 0 )
{
id.part = 0;
}
if ( id.ring < 0 )
{
id.ring = 0;
}
}
else
{
if ( id.vertex + 1 >= numPoints() )
{
return false;
}
++id.vertex;
}
return pointAt( id.vertex, vertex, id.type );
}
QgsAbstractGeometry* QgsCurve::boundary() const
{
if ( isEmpty() )
return nullptr;
if ( isClosed() )
return nullptr;
QgsMultiPointV2* multiPoint = new QgsMultiPointV2();
multiPoint->addGeometry( new QgsPointV2( startPoint() ) );
multiPoint->addGeometry( new QgsPointV2( endPoint() ) );
return multiPoint;
}
QgsCurve* QgsCurve::segmentize( double tolerance, SegmentationToleranceType toleranceType ) const
{
return curveToLine( tolerance, toleranceType );
}
QgsPointV2 QgsCurve::vertexAt( QgsVertexId id ) const
{
QgsPointV2 v;
QgsVertexId::VertexType type;
pointAt( id.vertex, v, type );
return v;
}
QgsRectangle QgsCurve::boundingBox() const
{
if ( mBoundingBox.isNull() )
{
mBoundingBox = calculateBoundingBox();
}
return mBoundingBox;
}
QPolygonF QgsCurve::asQPolygonF() const
{
const int nb = numPoints();
QPolygonF points;
points.reserve( nb );
for ( int i = 0; i < nb; ++i )
{
points << QPointF( xAt( i ), yAt( i ) );
}
return points;
}