Skip to content

Commit 4059c9b

Browse files
committed
Move some more common geometry methods to headers to allow compiler inlining
1 parent 3ea8a41 commit 4059c9b

17 files changed

+410
-525
lines changed

python/core/auto_generated/geometry/qgscurvepolygon.sip.in

+2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ Curve polygon geometry type
7171

7272

7373
int numInteriorRings() const;
74+
7475
const QgsCurve *exteriorRing() const;
76+
7577
const QgsCurve *interiorRing( int i ) const;
7678

7779
virtual QgsPolygon *toPolygon( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const /Factory/;

python/core/auto_generated/geometry/qgspoint.sip.in

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ Construct a QgsPoint from a QPointF
9292

9393
virtual bool operator!=( const QgsAbstractGeometry &other ) const;
9494

95-
9695
double x() const;
9796
%Docstring
9897
Returns the point's x-coordinate.

python/core/auto_generated/geometry/qgsrectangle.sip.in

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ Examples are storing a layer extent or the current view extent of a map
3333
%Docstring
3434
Constructor
3535
%End
36+
3637
QgsRectangle( const QgsPointXY &p1, const QgsPointXY &p2 );
3738
%Docstring
3839
Construct a rectangle from two points. The rectangle is normalized after construction.
3940
%End
41+
4042
QgsRectangle( const QRectF &qRectF );
4143
%Docstring
4244
Construct a rectangle from a QRectF. The rectangle is normalized after construction.
4345
%End
46+
4447
QgsRectangle( const QgsRectangle &other );
4548
%Docstring
4649
Copy constructor
@@ -70,7 +73,7 @@ Sets the rectangle from two :py:class:`QgsPoints`. The rectangle is
7073
normalised after construction.
7174
%End
7275

73-
void set( double mXmin, double mYmin, double mXmax, double mYmax );
76+
void set( double xMin, double yMin, double xMax, double yMax );
7477
%Docstring
7578
Sets the rectangle from four points. The rectangle is
7679
normalised after construction.

src/core/geometry/qgsabstractgeometry.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,6 @@ QgsAbstractGeometry &QgsAbstractGeometry::operator=( const QgsAbstractGeometry &
3838
return *this;
3939
}
4040

41-
bool QgsAbstractGeometry::is3D() const
42-
{
43-
return QgsWkbTypes::hasZ( mWkbType );
44-
}
45-
46-
bool QgsAbstractGeometry::isMeasure() const
47-
{
48-
return QgsWkbTypes::hasM( mWkbType );
49-
}
50-
51-
5241
void QgsAbstractGeometry::setZMTypeFromSubGeometry( const QgsAbstractGeometry *subgeom, QgsWkbTypes::Type baseGeomType )
5342
{
5443
if ( !subgeom )

src/core/geometry/qgsabstractgeometry.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,19 @@ class CORE_EXPORT QgsAbstractGeometry
181181
* Returns true if the geometry is 3D and contains a z-value.
182182
* \see isMeasure
183183
*/
184-
bool is3D() const;
184+
bool is3D() const
185+
{
186+
return QgsWkbTypes::hasZ( mWkbType );
187+
}
185188

186189
/**
187190
* Returns true if the geometry contains m values.
188191
* \see is3D
189192
*/
190-
bool isMeasure() const;
193+
bool isMeasure() const
194+
{
195+
return QgsWkbTypes::hasM( mWkbType );
196+
}
191197

192198
/**
193199
* Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the geometry).

src/core/geometry/qgscurvepolygon.cpp

-19
Original file line numberDiff line numberDiff line change
@@ -588,25 +588,6 @@ QgsPolygon *QgsCurvePolygon::toPolygon( double tolerance, SegmentationToleranceT
588588
return poly.release();
589589
}
590590

591-
int QgsCurvePolygon::numInteriorRings() const
592-
{
593-
return mInteriorRings.size();
594-
}
595-
596-
const QgsCurve *QgsCurvePolygon::exteriorRing() const
597-
{
598-
return mExteriorRing.get();
599-
}
600-
601-
const QgsCurve *QgsCurvePolygon::interiorRing( int i ) const
602-
{
603-
if ( i < 0 || i >= mInteriorRings.size() )
604-
{
605-
return nullptr;
606-
}
607-
return mInteriorRings.at( i );
608-
}
609-
610591
void QgsCurvePolygon::setExteriorRing( QgsCurve *ring )
611592
{
612593
if ( !ring )

src/core/geometry/qgscurvepolygon.h

+18-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,24 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
6666
bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
6767

6868
//curve polygon interface
69-
int numInteriorRings() const;
70-
const QgsCurve *exteriorRing() const;
71-
const QgsCurve *interiorRing( int i ) const;
69+
int numInteriorRings() const
70+
{
71+
return mInteriorRings.size();
72+
}
73+
74+
const QgsCurve *exteriorRing() const
75+
{
76+
return mExteriorRing.get();
77+
}
78+
79+
const QgsCurve *interiorRing( int i ) const
80+
{
81+
if ( i < 0 || i >= mInteriorRings.size() )
82+
{
83+
return nullptr;
84+
}
85+
return mInteriorRings.at( i );
86+
}
7287

7388
/**
7489
* Returns a new polygon geometry corresponding to a segmentized approximation

src/core/geometry/qgsgeometrycollection.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,6 @@ int QgsGeometryCollection::vertexNumberFromVertexId( QgsVertexId id ) const
181181
return -1; // should not happen
182182
}
183183

184-
int QgsGeometryCollection::numGeometries() const
185-
{
186-
return mGeometries.size();
187-
}
188-
189-
const QgsAbstractGeometry *QgsGeometryCollection::geometryN( int n ) const
190-
{
191-
return mGeometries.value( n );
192-
}
193-
194184
QgsAbstractGeometry *QgsGeometryCollection::geometryN( int n )
195185
{
196186
clearCache();

src/core/geometry/qgsgeometrycollection.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,20 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
4747
/**
4848
* Returns the number of geometries within the collection.
4949
*/
50-
int numGeometries() const;
50+
int numGeometries() const
51+
{
52+
return mGeometries.size();
53+
}
5154

5255
/**
5356
* Returns a const reference to a geometry from within the collection.
5457
* \param n index of geometry to return
5558
* \note not available in Python bindings
5659
*/
57-
const QgsAbstractGeometry *geometryN( int n ) const SIP_SKIP;
60+
const QgsAbstractGeometry *geometryN( int n ) const SIP_SKIP
61+
{
62+
return mGeometries.value( n );
63+
}
5864

5965
/**
6066
* Returns a geometry from within the collection.

src/core/geometry/qgslinestring.cpp

-60
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,6 @@ bool QgsLineString::fromWkb( QgsConstWkbPtr &wkbPtr )
306306
return true;
307307
}
308308

309-
void QgsLineString::fromWkbPoints( QgsWkbTypes::Type type, const QgsConstWkbPtr &wkb )
310-
{
311-
mWkbType = type;
312-
importVerticesFromWkb( wkb );
313-
}
314-
315309
QgsRectangle QgsLineString::calculateBoundingBox() const
316310
{
317311
double xmin = std::numeric_limits<double>::max();
@@ -550,48 +544,6 @@ double QgsLineString::yAt( int index ) const
550544
return 0.0;
551545
}
552546

553-
const double *QgsLineString::xData() const
554-
{
555-
return mX.constData();
556-
}
557-
558-
const double *QgsLineString::yData() const
559-
{
560-
return mY.constData();
561-
}
562-
563-
const double *QgsLineString::zData() const
564-
{
565-
if ( mZ.empty() )
566-
return nullptr;
567-
else
568-
return mZ.constData();
569-
}
570-
571-
const double *QgsLineString::mData() const
572-
{
573-
if ( mM.empty() )
574-
return nullptr;
575-
else
576-
return mM.constData();
577-
}
578-
579-
double QgsLineString::zAt( int index ) const
580-
{
581-
if ( index >= 0 && index < mZ.size() )
582-
return mZ.at( index );
583-
else
584-
return std::numeric_limits<double>::quiet_NaN();
585-
}
586-
587-
double QgsLineString::mAt( int index ) const
588-
{
589-
if ( index >= 0 && index < mM.size() )
590-
return mM.at( index );
591-
else
592-
return std::numeric_limits<double>::quiet_NaN();
593-
}
594-
595547
void QgsLineString::setXAt( int index, double x )
596548
{
597549
if ( index >= 0 && index < mX.size() )
@@ -606,18 +558,6 @@ void QgsLineString::setYAt( int index, double y )
606558
clearCache();
607559
}
608560

609-
void QgsLineString::setZAt( int index, double z )
610-
{
611-
if ( index >= 0 && index < mZ.size() )
612-
mZ[ index ] = z;
613-
}
614-
615-
void QgsLineString::setMAt( int index, double m )
616-
{
617-
if ( index >= 0 && index < mM.size() )
618-
mM[ index ] = m;
619-
}
620-
621561
/***************************************************************************
622562
* This class is considered CRITICAL and any change MUST be accompanied with
623563
* full unit tests.

src/core/geometry/qgslinestring.h

+51-9
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,21 @@ class CORE_EXPORT QgsLineString: public QgsCurve
102102
* \see yData()
103103
* \since QGIS 3.2
104104
*/
105-
const double *xData() const SIP_SKIP;
105+
const double *xData() const SIP_SKIP
106+
{
107+
return mX.constData();
108+
}
106109

107110
/**
108111
* Returns a const pointer to the y vertex data.
109112
* \note Not available in Python bindings
110113
* \see xData()
111114
* \since QGIS 3.2
112115
*/
113-
const double *yData() const SIP_SKIP;
116+
const double *yData() const SIP_SKIP
117+
{
118+
return mY.constData();
119+
}
114120

115121
/**
116122
* Returns a const pointer to the z vertex data, or a nullptr if the linestring does
@@ -120,7 +126,13 @@ class CORE_EXPORT QgsLineString: public QgsCurve
120126
* \see yData()
121127
* \since QGIS 3.2
122128
*/
123-
const double *zData() const SIP_SKIP;
129+
const double *zData() const SIP_SKIP
130+
{
131+
if ( mZ.empty() )
132+
return nullptr;
133+
else
134+
return mZ.constData();
135+
}
124136

125137
/**
126138
* Returns a const pointer to the m vertex data, or a nullptr if the linestring does
@@ -130,7 +142,13 @@ class CORE_EXPORT QgsLineString: public QgsCurve
130142
* \see yData()
131143
* \since QGIS 3.2
132144
*/
133-
const double *mData() const SIP_SKIP;
145+
const double *mData() const SIP_SKIP
146+
{
147+
if ( mM.empty() )
148+
return nullptr;
149+
else
150+
return mM.constData();
151+
}
134152

135153
/**
136154
* Returns the z-coordinate of the specified node in the line string.
@@ -139,7 +157,13 @@ class CORE_EXPORT QgsLineString: public QgsCurve
139157
* does not have a z dimension
140158
* \see setZAt()
141159
*/
142-
double zAt( int index ) const;
160+
double zAt( int index ) const
161+
{
162+
if ( index >= 0 && index < mZ.size() )
163+
return mZ.at( index );
164+
else
165+
return std::numeric_limits<double>::quiet_NaN();
166+
}
143167

144168
/**
145169
* Returns the m value of the specified node in the line string.
@@ -148,7 +172,13 @@ class CORE_EXPORT QgsLineString: public QgsCurve
148172
* does not have m values
149173
* \see setMAt()
150174
*/
151-
double mAt( int index ) const;
175+
double mAt( int index ) const
176+
{
177+
if ( index >= 0 && index < mM.size() )
178+
return mM.at( index );
179+
else
180+
return std::numeric_limits<double>::quiet_NaN();
181+
}
152182

153183
/**
154184
* Sets the x-coordinate of the specified node in the line string.
@@ -175,7 +205,11 @@ class CORE_EXPORT QgsLineString: public QgsCurve
175205
* \param z z-coordinate of node
176206
* \see zAt()
177207
*/
178-
void setZAt( int index, double z );
208+
void setZAt( int index, double z )
209+
{
210+
if ( index >= 0 && index < mZ.size() )
211+
mZ[ index ] = z;
212+
}
179213

180214
/**
181215
* Sets the m value of the specified node in the line string.
@@ -184,7 +218,11 @@ class CORE_EXPORT QgsLineString: public QgsCurve
184218
* \param m m value of node
185219
* \see mAt()
186220
*/
187-
void setMAt( int index, double m );
221+
void setMAt( int index, double m )
222+
{
223+
if ( index >= 0 && index < mM.size() )
224+
mM[ index ] = m;
225+
}
188226

189227
/**
190228
* Resets the line string to match the specified list of points. The line string will
@@ -325,7 +363,11 @@ class CORE_EXPORT QgsLineString: public QgsCurve
325363
* \param type WKB type
326364
* \param wkb WKB representation of line geometry
327365
*/
328-
void fromWkbPoints( QgsWkbTypes::Type type, const QgsConstWkbPtr &wkb );
366+
void fromWkbPoints( QgsWkbTypes::Type type, const QgsConstWkbPtr &wkb )
367+
{
368+
mWkbType = type;
369+
importVerticesFromWkb( wkb );
370+
}
329371

330372
friend class QgsPolygon;
331373
friend class QgsTriangle;

0 commit comments

Comments
 (0)