24
24
#include " qgswkbptr.h"
25
25
#include < QPainter>
26
26
27
- QgsPointV2::QgsPointV2 ( double x, double y ): QgsAbstractGeometryV2(), mX( x ), mY( y ), mZ( 0.0 ), mM( 0.0 )
27
+ QgsPointV2::QgsPointV2 ( double x, double y )
28
+ : QgsAbstractGeometryV2()
29
+ , mX( x )
30
+ , mY( y )
31
+ , mZ( 0.0 )
32
+ , mM( 0.0 )
28
33
{
29
34
mWkbType = QgsWKBTypes::Point ;
30
35
}
31
36
32
- QgsPointV2::QgsPointV2 ( const QgsPoint& p ): QgsAbstractGeometryV2(), mX( p.x() ), mY( p.y() ), mZ( 0.0 ), mM( 0.0 )
37
+ QgsPointV2::QgsPointV2 ( const QgsPoint& p )
38
+ : QgsAbstractGeometryV2()
39
+ , mX( p.x() )
40
+ , mY( p.y() )
41
+ , mZ( 0.0 )
42
+ , mM( 0.0 )
33
43
{
34
44
mWkbType = QgsWKBTypes::Point ;
35
45
}
36
46
37
- QgsPointV2::QgsPointV2 ( const QPointF& p ): QgsAbstractGeometryV2(), mX( p.x() ), mY( p.y() ), mZ( 0.0 ), mM( 0.0 )
47
+ QgsPointV2::QgsPointV2 ( const QPointF& p )
48
+ : QgsAbstractGeometryV2()
49
+ , mX( p.x() )
50
+ , mY( p.y() )
51
+ , mZ( 0.0 )
52
+ , mM( 0.0 )
38
53
{
39
54
mWkbType = QgsWKBTypes::Point ;
40
55
}
41
56
42
- QgsPointV2::QgsPointV2 ( QgsWKBTypes::Type type, double x, double y, double z, double m ): mX( x ), mY( y ), mZ( z ), mM( m )
57
+ QgsPointV2::QgsPointV2 ( QgsWKBTypes::Type type, double x, double y, double z, double m )
58
+ : mX( x )
59
+ , mY( y )
60
+ , mZ( z )
61
+ , mM( m )
43
62
{
63
+ // protect against non-point WKB types
64
+ Q_ASSERT ( QgsWKBTypes::flatType ( type ) == QgsWKBTypes::Point );
44
65
mWkbType = type;
45
66
}
46
67
@@ -69,6 +90,7 @@ bool QgsPointV2::fromWkb( const unsigned char* wkb )
69
90
QgsWKBTypes::Type type = wkbPtr.readHeader ();
70
91
if ( QgsWKBTypes::flatType ( type ) != QgsWKBTypes::Point )
71
92
{
93
+ clear ();
72
94
return false ;
73
95
}
74
96
mWkbType = type;
@@ -80,7 +102,8 @@ bool QgsPointV2::fromWkb( const unsigned char* wkb )
80
102
if ( isMeasure () )
81
103
wkbPtr >> mM ;
82
104
83
- mBoundingBox = QgsRectangle (); // set bounding box invalid
105
+ mBoundingBox = QgsRectangle ();
106
+
84
107
return true ;
85
108
}
86
109
@@ -95,7 +118,7 @@ bool QgsPointV2::fromWkt( const QString& wkt )
95
118
mWkbType = parts.first ;
96
119
97
120
QStringList coordinates = parts.second .split ( ' ' , QString::SkipEmptyParts );
98
- if ( coordinates.size () < 2 + is3D () + isMeasure () )
121
+ if ( coordinates.size () < 2 )
99
122
{
100
123
clear ();
101
124
return false ;
@@ -117,9 +140,9 @@ bool QgsPointV2::fromWkt( const QString& wkt )
117
140
int idx = 0 ;
118
141
mX = coordinates[idx++].toDouble ();
119
142
mY = coordinates[idx++].toDouble ();
120
- if ( is3D () )
143
+ if ( is3D () && coordinates. length () > 2 )
121
144
mZ = coordinates[idx++].toDouble ();
122
- if ( isMeasure () )
145
+ if ( isMeasure () && coordinates. length () > 2 + is3D () )
123
146
mM = coordinates[idx++].toDouble ();
124
147
125
148
return true ;
@@ -203,13 +226,13 @@ void QgsPointV2::clear()
203
226
{
204
227
mWkbType = QgsWKBTypes::Unknown;
205
228
mX = mY = mZ = mM = 0 .;
206
- mBoundingBox = QgsRectangle (); // set bounding box invalid
229
+ mBoundingBox = QgsRectangle ();
207
230
}
208
231
209
232
void QgsPointV2::transform ( const QgsCoordinateTransform& ct, QgsCoordinateTransform::TransformDirection d )
210
233
{
234
+ mBoundingBox = QgsRectangle ();
211
235
ct.transformInPlace ( mX , mY , mZ , d );
212
- mBoundingBox = QgsRectangle (); // set bounding box invalid
213
236
}
214
237
215
238
void QgsPointV2::coordinateSequence ( QList< QList< QList< QgsPointV2 > > >& coord ) const
@@ -223,6 +246,7 @@ void QgsPointV2::coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coor
223
246
bool QgsPointV2::moveVertex ( const QgsVertexId& position, const QgsPointV2& newPos )
224
247
{
225
248
Q_UNUSED ( position );
249
+ mBoundingBox = QgsRectangle ();
226
250
mX = newPos.mX ;
227
251
mY = newPos.mY ;
228
252
if ( is3D () && newPos.is3D () )
@@ -233,13 +257,14 @@ bool QgsPointV2::moveVertex( const QgsVertexId& position, const QgsPointV2& newP
233
257
{
234
258
mM = newPos.mM ;
235
259
}
236
- mBoundingBox = QgsRectangle (); // set bounding box invalid
237
260
return true ;
238
261
}
239
262
240
263
double QgsPointV2::closestSegment ( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool * leftOf, double epsilon ) const
241
264
{
242
- Q_UNUSED ( segmentPt ); Q_UNUSED ( vertexAfter ); Q_UNUSED ( leftOf ); Q_UNUSED ( leftOf ); Q_UNUSED ( epsilon );
265
+ Q_UNUSED ( leftOf ); Q_UNUSED ( epsilon );
266
+ segmentPt = *this ;
267
+ vertexAfter = QgsVertexId ( 0 , 0 , 0 );
243
268
return QgsGeometryUtils::sqrDistance2D ( *this , pt );
244
269
}
245
270
@@ -287,8 +312,8 @@ bool QgsPointV2::addMValue( double mValue )
287
312
288
313
void QgsPointV2::transform ( const QTransform& t )
289
314
{
315
+ mBoundingBox = QgsRectangle ();
290
316
qreal x, y;
291
317
t.map ( mX , mY , &x, &y );
292
318
mX = x; mY = y;
293
- mBoundingBox = QgsRectangle (); // set bounding box invalid
294
319
}
0 commit comments