Skip to content

Commit 581b89e

Browse files
committed
Use pointers and not references to QgsAbstractGeometry
because using this more consistently throughout the codebase makes it easier to maintain code. We also do not want to call the copy constructor on them, using pointers just makes this more obvious. Further, casting is also something that's commonly done on pointers and not references. And if you want a value or a reference, just use QgsGeometry, it's meant to be handled like this.
1 parent 4c6c74c commit 581b89e

21 files changed

+140
-142
lines changed

python/core/geometry/qgsgeometryengine.sip

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ class QgsGeometryEngine
2626
virtual void geometryChanged() = 0;
2727
virtual void prepareGeometry() = 0;
2828

29-
virtual QgsAbstractGeometry *intersection( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0 /Factory/;
29+
virtual QgsAbstractGeometry *intersection( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0 /Factory/;
3030
%Docstring
3131
:rtype: QgsAbstractGeometry
3232
%End
33-
virtual QgsAbstractGeometry *difference( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0 /Factory/;
33+
virtual QgsAbstractGeometry *difference( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0 /Factory/;
3434
%Docstring
3535
:rtype: QgsAbstractGeometry
3636
%End
37-
virtual QgsAbstractGeometry *combine( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0 /Factory/;
37+
virtual QgsAbstractGeometry *combine( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0 /Factory/;
3838
%Docstring
3939
:rtype: QgsAbstractGeometry
4040
%End
4141
virtual QgsAbstractGeometry *combine( const QList< QgsAbstractGeometry * > &, QString *errorMsg = 0 ) const = 0 /Factory/;
4242
%Docstring
4343
:rtype: QgsAbstractGeometry
4444
%End
45-
virtual QgsAbstractGeometry *symDifference( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0 /Factory/;
45+
virtual QgsAbstractGeometry *symDifference( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0 /Factory/;
4646
%Docstring
4747
:rtype: QgsAbstractGeometry
4848
%End
@@ -78,40 +78,40 @@ class QgsGeometryEngine
7878
%Docstring
7979
:rtype: QgsAbstractGeometry
8080
%End
81-
virtual double distance( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
81+
virtual double distance( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
8282
%Docstring
8383
:rtype: float
8484
%End
85-
virtual bool intersects( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
85+
virtual bool intersects( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
8686
%Docstring
8787
:rtype: bool
8888
%End
89-
virtual bool touches( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
89+
virtual bool touches( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
9090
%Docstring
9191
:rtype: bool
9292
%End
93-
virtual bool crosses( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
93+
virtual bool crosses( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
9494
%Docstring
9595
:rtype: bool
9696
%End
97-
virtual bool within( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
97+
virtual bool within( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
9898
%Docstring
9999
:rtype: bool
100100
%End
101-
virtual bool overlaps( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
101+
virtual bool overlaps( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
102102
%Docstring
103103
:rtype: bool
104104
%End
105-
virtual bool contains( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
105+
virtual bool contains( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
106106
%Docstring
107107
:rtype: bool
108108
%End
109-
virtual bool disjoint( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
109+
virtual bool disjoint( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
110110
%Docstring
111111
:rtype: bool
112112
%End
113113

114-
virtual QString relate( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
114+
virtual QString relate( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
115115
%Docstring
116116
Returns the Dimensional Extended 9 Intersection Model (DE-9IM) representation of the
117117
relationship between the geometries.
@@ -122,7 +122,7 @@ class QgsGeometryEngine
122122
:rtype: str
123123
%End
124124

125-
virtual bool relatePattern( const QgsAbstractGeometry &geom, const QString &pattern, QString *errorMsg = 0 ) const = 0;
125+
virtual bool relatePattern( const QgsAbstractGeometry *geom, const QString &pattern, QString *errorMsg = 0 ) const = 0;
126126
%Docstring
127127
Tests whether two geometries are related by a specified Dimensional Extended 9 Intersection Model (DE-9IM)
128128
pattern.
@@ -146,7 +146,7 @@ class QgsGeometryEngine
146146
%Docstring
147147
:rtype: bool
148148
%End
149-
virtual bool isEqual( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
149+
virtual bool isEqual( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
150150
%Docstring
151151
:rtype: bool
152152
%End

src/core/expression/qgsexpressionfunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,14 +2373,14 @@ static QVariant fcnRelate( const QVariantList &values, const QgsExpressionContex
23732373
if ( values.length() == 2 )
23742374
{
23752375
//two geometry arguments, return relation
2376-
QString result = engine->relate( *sGeom.geometry() );
2376+
QString result = engine->relate( sGeom.geometry() );
23772377
return QVariant::fromValue( result );
23782378
}
23792379
else
23802380
{
23812381
//three arguments, test pattern
23822382
QString pattern = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
2383-
bool result = engine->relatePattern( *sGeom.geometry(), pattern );
2383+
bool result = engine->relatePattern( sGeom.geometry(), pattern );
23842384
return QVariant::fromValue( result );
23852385
}
23862386
}

src/core/geometry/qgsgeometry.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ int QgsGeometry::makeDifferenceInPlace( const QgsGeometry &other )
845845

846846
QgsGeos geos( d->geometry );
847847

848-
QgsAbstractGeometry *diffGeom = geos.intersection( *other.geometry() );
848+
QgsAbstractGeometry *diffGeom = geos.intersection( other.geometry() );
849849
if ( !diffGeom )
850850
{
851851
return 1;
@@ -867,7 +867,7 @@ QgsGeometry QgsGeometry::makeDifference( const QgsGeometry &other ) const
867867

868868
QgsGeos geos( d->geometry );
869869

870-
QgsAbstractGeometry *diffGeom = geos.intersection( *other.geometry() );
870+
QgsAbstractGeometry *diffGeom = geos.intersection( other.geometry() );
871871
if ( !diffGeom )
872872
{
873873
return QgsGeometry();
@@ -965,7 +965,7 @@ bool QgsGeometry::intersects( const QgsGeometry &geometry ) const
965965
}
966966

967967
QgsGeos geos( d->geometry );
968-
return geos.intersects( *geometry.d->geometry );
968+
return geos.intersects( geometry.d->geometry );
969969
}
970970

971971
bool QgsGeometry::contains( const QgsPointXY *p ) const
@@ -977,7 +977,7 @@ bool QgsGeometry::contains( const QgsPointXY *p ) const
977977

978978
QgsPoint pt( p->x(), p->y() );
979979
QgsGeos geos( d->geometry );
980-
return geos.contains( pt );
980+
return geos.contains( &pt );
981981
}
982982

983983
bool QgsGeometry::contains( const QgsGeometry &geometry ) const
@@ -988,7 +988,7 @@ bool QgsGeometry::contains( const QgsGeometry &geometry ) const
988988
}
989989

990990
QgsGeos geos( d->geometry );
991-
return geos.contains( *( geometry.d->geometry ) );
991+
return geos.contains( geometry.d->geometry );
992992
}
993993

994994
bool QgsGeometry::disjoint( const QgsGeometry &geometry ) const
@@ -999,7 +999,7 @@ bool QgsGeometry::disjoint( const QgsGeometry &geometry ) const
999999
}
10001000

10011001
QgsGeos geos( d->geometry );
1002-
return geos.disjoint( *( geometry.d->geometry ) );
1002+
return geos.disjoint( geometry.d->geometry );
10031003
}
10041004

10051005
bool QgsGeometry::equals( const QgsGeometry &geometry ) const
@@ -1010,7 +1010,7 @@ bool QgsGeometry::equals( const QgsGeometry &geometry ) const
10101010
}
10111011

10121012
QgsGeos geos( d->geometry );
1013-
return geos.isEqual( *( geometry.d->geometry ) );
1013+
return geos.isEqual( geometry.d->geometry );
10141014
}
10151015

10161016
bool QgsGeometry::touches( const QgsGeometry &geometry ) const
@@ -1021,7 +1021,7 @@ bool QgsGeometry::touches( const QgsGeometry &geometry ) const
10211021
}
10221022

10231023
QgsGeos geos( d->geometry );
1024-
return geos.touches( *( geometry.d->geometry ) );
1024+
return geos.touches( geometry.d->geometry );
10251025
}
10261026

10271027
bool QgsGeometry::overlaps( const QgsGeometry &geometry ) const
@@ -1032,7 +1032,7 @@ bool QgsGeometry::overlaps( const QgsGeometry &geometry ) const
10321032
}
10331033

10341034
QgsGeos geos( d->geometry );
1035-
return geos.overlaps( *( geometry.d->geometry ) );
1035+
return geos.overlaps( geometry.d->geometry );
10361036
}
10371037

10381038
bool QgsGeometry::within( const QgsGeometry &geometry ) const
@@ -1043,7 +1043,7 @@ bool QgsGeometry::within( const QgsGeometry &geometry ) const
10431043
}
10441044

10451045
QgsGeos geos( d->geometry );
1046-
return geos.within( *( geometry.d->geometry ) );
1046+
return geos.within( geometry.d->geometry );
10471047
}
10481048

10491049
bool QgsGeometry::crosses( const QgsGeometry &geometry ) const
@@ -1054,7 +1054,7 @@ bool QgsGeometry::crosses( const QgsGeometry &geometry ) const
10541054
}
10551055

10561056
QgsGeos geos( d->geometry );
1057-
return geos.crosses( *( geometry.d->geometry ) );
1057+
return geos.crosses( geometry.d->geometry );
10581058
}
10591059

10601060
QString QgsGeometry::exportToWkt( int precision ) const
@@ -1394,7 +1394,7 @@ double QgsGeometry::distance( const QgsGeometry &geom ) const
13941394
}
13951395

13961396
QgsGeos g( d->geometry );
1397-
return g.distance( *( geom.d->geometry ) );
1397+
return g.distance( geom.d->geometry );
13981398
}
13991399

14001400
QgsGeometry QgsGeometry::buffer( double distance, int segments ) const
@@ -1405,12 +1405,8 @@ QgsGeometry QgsGeometry::buffer( double distance, int segments ) const
14051405
}
14061406

14071407
QgsGeos g( d->geometry );
1408-
QgsAbstractGeometry *geom = g.buffer( distance, segments );
1409-
if ( !geom )
1410-
{
1411-
return QgsGeometry();
1412-
}
1413-
return QgsGeometry( geom );
1408+
std::unique_ptr<QgsAbstractGeometry> geom( g.buffer( distance, segments ) );
1409+
return QgsGeometry( geom.release() );
14141410
}
14151411

14161412
QgsGeometry QgsGeometry::buffer( double distance, int segments, EndCapStyle endCapStyle, JoinStyle joinStyle, double miterLimit ) const
@@ -1797,7 +1793,7 @@ QgsGeometry QgsGeometry::intersection( const QgsGeometry &geometry ) const
17971793
QgsGeos geos( d->geometry );
17981794

17991795
QString error;
1800-
QgsAbstractGeometry *resultGeom = geos.intersection( *( geometry.d->geometry ), &error );
1796+
QgsAbstractGeometry *resultGeom = geos.intersection( geometry.d->geometry, &error );
18011797

18021798
if ( !resultGeom )
18031799
{
@@ -1819,7 +1815,7 @@ QgsGeometry QgsGeometry::combine( const QgsGeometry &geometry ) const
18191815
QgsGeos geos( d->geometry );
18201816
QString error;
18211817

1822-
QgsAbstractGeometry *resultGeom = geos.combine( *( geometry.d->geometry ), &error );
1818+
QgsAbstractGeometry *resultGeom = geos.combine( geometry.d->geometry, &error );
18231819
if ( !resultGeom )
18241820
{
18251821
QgsGeometry geom;
@@ -1856,7 +1852,7 @@ QgsGeometry QgsGeometry::difference( const QgsGeometry &geometry ) const
18561852
QgsGeos geos( d->geometry );
18571853

18581854
QString error;
1859-
QgsAbstractGeometry *resultGeom = geos.difference( *( geometry.d->geometry ), &error );
1855+
QgsAbstractGeometry *resultGeom = geos.difference( geometry.d->geometry, &error );
18601856
if ( !resultGeom )
18611857
{
18621858
QgsGeometry geom;
@@ -1877,7 +1873,7 @@ QgsGeometry QgsGeometry::symDifference( const QgsGeometry &geometry ) const
18771873

18781874
QString error;
18791875

1880-
QgsAbstractGeometry *resultGeom = geos.symDifference( *( geometry.d->geometry ), &error );
1876+
QgsAbstractGeometry *resultGeom = geos.symDifference( geometry.d->geometry, &error );
18811877
if ( !resultGeom )
18821878
{
18831879
QgsGeometry geom;
@@ -2051,7 +2047,7 @@ bool QgsGeometry::isGeosEqual( const QgsGeometry &g ) const
20512047
}
20522048

20532049
QgsGeos geos( d->geometry );
2054-
return geos.isEqual( *( g.d->geometry ) );
2050+
return geos.isEqual( g.d->geometry );
20552051
}
20562052

20572053
QgsGeometry QgsGeometry::unaryUnion( const QList<QgsGeometry> &geometries )

src/core/geometry/qgsgeometryeditutils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ int QgsGeometryEditUtils::addRing( QgsAbstractGeometry *geom, QgsCurve *ring )
7070
ringGeom->prepareGeometry();
7171

7272
//for each polygon, test if inside outer ring and no intersection with other interior ring
73-
QList< QgsCurvePolygon * >::iterator polyIter = polygonList.begin();
74-
for ( ; polyIter != polygonList.end(); ++polyIter )
73+
QList< QgsCurvePolygon * >::const_iterator polyIter = polygonList.constBegin();
74+
for ( ; polyIter != polygonList.constEnd(); ++polyIter )
7575
{
76-
if ( ringGeom->within( **polyIter ) )
76+
if ( ringGeom->within( *polyIter ) )
7777
{
7878
//check if disjoint with other interior rings
7979
int nInnerRings = ( *polyIter )->numInteriorRings();
8080
for ( int i = 0; i < nInnerRings; ++i )
8181
{
82-
if ( !ringGeom->disjoint( *( *polyIter )->interiorRing( i ) ) )
82+
if ( !ringGeom->disjoint( ( *polyIter )->interiorRing( i ) ) )
8383
{
8484
delete ring;
8585
return 4;
@@ -284,7 +284,7 @@ QgsAbstractGeometry *QgsGeometryEditUtils::avoidIntersections( const QgsAbstract
284284
return nullptr;
285285
}
286286

287-
QgsAbstractGeometry *diffGeom = geomEngine->difference( *combinedGeometries );
287+
QgsAbstractGeometry *diffGeom = geomEngine->difference( combinedGeometries );
288288

289289
delete combinedGeometries;
290290
return diffGeom;

src/core/geometry/qgsgeometryengine.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ class CORE_EXPORT QgsGeometryEngine
3636
virtual void geometryChanged() = 0;
3737
virtual void prepareGeometry() = 0;
3838

39-
virtual QgsAbstractGeometry *intersection( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
40-
virtual QgsAbstractGeometry *difference( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
41-
virtual QgsAbstractGeometry *combine( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
39+
virtual QgsAbstractGeometry *intersection( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
40+
virtual QgsAbstractGeometry *difference( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
41+
virtual QgsAbstractGeometry *combine( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
4242
virtual QgsAbstractGeometry *combine( const QList< QgsAbstractGeometry * > &, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
43-
virtual QgsAbstractGeometry *symDifference( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
43+
virtual QgsAbstractGeometry *symDifference( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
4444
virtual QgsAbstractGeometry *buffer( double distance, int segments, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
4545
virtual QgsAbstractGeometry *buffer( double distance, int segments, int endCapStyle, int joinStyle, double miterLimit, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
4646
virtual QgsAbstractGeometry *simplify( double tolerance, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
@@ -49,14 +49,14 @@ class CORE_EXPORT QgsGeometryEngine
4949
virtual bool centroid( QgsPoint &pt, QString *errorMsg = nullptr ) const = 0;
5050
virtual bool pointOnSurface( QgsPoint &pt, QString *errorMsg = nullptr ) const = 0;
5151
virtual QgsAbstractGeometry *convexHull( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
52-
virtual double distance( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
53-
virtual bool intersects( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
54-
virtual bool touches( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
55-
virtual bool crosses( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
56-
virtual bool within( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
57-
virtual bool overlaps( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
58-
virtual bool contains( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
59-
virtual bool disjoint( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
52+
virtual double distance( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
53+
virtual bool intersects( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
54+
virtual bool touches( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
55+
virtual bool crosses( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
56+
virtual bool within( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
57+
virtual bool overlaps( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
58+
virtual bool contains( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
59+
virtual bool disjoint( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
6060

6161
/** Returns the Dimensional Extended 9 Intersection Model (DE-9IM) representation of the
6262
* relationship between the geometries.
@@ -65,7 +65,7 @@ class CORE_EXPORT QgsGeometryEngine
6565
* \returns DE-9IM string for relationship, or an empty string if an error occurred
6666
* \since QGIS 2.12
6767
*/
68-
virtual QString relate( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
68+
virtual QString relate( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
6969

7070
/** Tests whether two geometries are related by a specified Dimensional Extended 9 Intersection Model (DE-9IM)
7171
* pattern.
@@ -75,12 +75,12 @@ class CORE_EXPORT QgsGeometryEngine
7575
* \returns true if geometry relationship matches with pattern
7676
* \since QGIS 2.14
7777
*/
78-
virtual bool relatePattern( const QgsAbstractGeometry &geom, const QString &pattern, QString *errorMsg = nullptr ) const = 0;
78+
virtual bool relatePattern( const QgsAbstractGeometry *geom, const QString &pattern, QString *errorMsg = nullptr ) const = 0;
7979

8080
virtual double area( QString *errorMsg = nullptr ) const = 0;
8181
virtual double length( QString *errorMsg = nullptr ) const = 0;
8282
virtual bool isValid( QString *errorMsg = nullptr ) const = 0;
83-
virtual bool isEqual( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
83+
virtual bool isEqual( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
8484
virtual bool isEmpty( QString *errorMsg ) const = 0;
8585

8686
/** Determines whether the geometry is simple (according to OGC definition).

0 commit comments

Comments
 (0)