Skip to content

Commit

Permalink
Use pointers and not references to QgsAbstractGeometry
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
m-kuhn committed Aug 13, 2017
1 parent 4c6c74c commit 581b89e
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 142 deletions.
30 changes: 15 additions & 15 deletions python/core/geometry/qgsgeometryengine.sip
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ class QgsGeometryEngine
virtual void geometryChanged() = 0;
virtual void prepareGeometry() = 0;

virtual QgsAbstractGeometry *intersection( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0 /Factory/;
virtual QgsAbstractGeometry *intersection( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0 /Factory/;
%Docstring
:rtype: QgsAbstractGeometry
%End
virtual QgsAbstractGeometry *difference( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0 /Factory/;
virtual QgsAbstractGeometry *difference( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0 /Factory/;
%Docstring
:rtype: QgsAbstractGeometry
%End
virtual QgsAbstractGeometry *combine( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0 /Factory/;
virtual QgsAbstractGeometry *combine( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0 /Factory/;
%Docstring
:rtype: QgsAbstractGeometry
%End
virtual QgsAbstractGeometry *combine( const QList< QgsAbstractGeometry * > &, QString *errorMsg = 0 ) const = 0 /Factory/;
%Docstring
:rtype: QgsAbstractGeometry
%End
virtual QgsAbstractGeometry *symDifference( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0 /Factory/;
virtual QgsAbstractGeometry *symDifference( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0 /Factory/;
%Docstring
:rtype: QgsAbstractGeometry
%End
Expand Down Expand Up @@ -78,40 +78,40 @@ class QgsGeometryEngine
%Docstring
:rtype: QgsAbstractGeometry
%End
virtual double distance( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
virtual double distance( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
%Docstring
:rtype: float
%End
virtual bool intersects( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
virtual bool intersects( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
%Docstring
:rtype: bool
%End
virtual bool touches( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
virtual bool touches( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
%Docstring
:rtype: bool
%End
virtual bool crosses( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
virtual bool crosses( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
%Docstring
:rtype: bool
%End
virtual bool within( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
virtual bool within( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
%Docstring
:rtype: bool
%End
virtual bool overlaps( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
virtual bool overlaps( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
%Docstring
:rtype: bool
%End
virtual bool contains( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
virtual bool contains( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
%Docstring
:rtype: bool
%End
virtual bool disjoint( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
virtual bool disjoint( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
%Docstring
:rtype: bool
%End

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

virtual bool relatePattern( const QgsAbstractGeometry &geom, const QString &pattern, QString *errorMsg = 0 ) const = 0;
virtual bool relatePattern( const QgsAbstractGeometry *geom, const QString &pattern, QString *errorMsg = 0 ) const = 0;
%Docstring
Tests whether two geometries are related by a specified Dimensional Extended 9 Intersection Model (DE-9IM)
pattern.
Expand All @@ -146,7 +146,7 @@ class QgsGeometryEngine
%Docstring
:rtype: bool
%End
virtual bool isEqual( const QgsAbstractGeometry &geom, QString *errorMsg = 0 ) const = 0;
virtual bool isEqual( const QgsAbstractGeometry *geom, QString *errorMsg = 0 ) const = 0;
%Docstring
:rtype: bool
%End
Expand Down
4 changes: 2 additions & 2 deletions src/core/expression/qgsexpressionfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2373,14 +2373,14 @@ static QVariant fcnRelate( const QVariantList &values, const QgsExpressionContex
if ( values.length() == 2 )
{
//two geometry arguments, return relation
QString result = engine->relate( *sGeom.geometry() );
QString result = engine->relate( sGeom.geometry() );
return QVariant::fromValue( result );
}
else
{
//three arguments, test pattern
QString pattern = QgsExpressionUtils::getStringValue( values.at( 2 ), parent );
bool result = engine->relatePattern( *sGeom.geometry(), pattern );
bool result = engine->relatePattern( sGeom.geometry(), pattern );
return QVariant::fromValue( result );
}
}
Expand Down
42 changes: 19 additions & 23 deletions src/core/geometry/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ int QgsGeometry::makeDifferenceInPlace( const QgsGeometry &other )

QgsGeos geos( d->geometry );

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

QgsGeos geos( d->geometry );

QgsAbstractGeometry *diffGeom = geos.intersection( *other.geometry() );
QgsAbstractGeometry *diffGeom = geos.intersection( other.geometry() );
if ( !diffGeom )
{
return QgsGeometry();
Expand Down Expand Up @@ -965,7 +965,7 @@ bool QgsGeometry::intersects( const QgsGeometry &geometry ) const
}

QgsGeos geos( d->geometry );
return geos.intersects( *geometry.d->geometry );
return geos.intersects( geometry.d->geometry );
}

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

QgsPoint pt( p->x(), p->y() );
QgsGeos geos( d->geometry );
return geos.contains( pt );
return geos.contains( &pt );
}

bool QgsGeometry::contains( const QgsGeometry &geometry ) const
Expand All @@ -988,7 +988,7 @@ bool QgsGeometry::contains( const QgsGeometry &geometry ) const
}

QgsGeos geos( d->geometry );
return geos.contains( *( geometry.d->geometry ) );
return geos.contains( geometry.d->geometry );
}

bool QgsGeometry::disjoint( const QgsGeometry &geometry ) const
Expand All @@ -999,7 +999,7 @@ bool QgsGeometry::disjoint( const QgsGeometry &geometry ) const
}

QgsGeos geos( d->geometry );
return geos.disjoint( *( geometry.d->geometry ) );
return geos.disjoint( geometry.d->geometry );
}

bool QgsGeometry::equals( const QgsGeometry &geometry ) const
Expand All @@ -1010,7 +1010,7 @@ bool QgsGeometry::equals( const QgsGeometry &geometry ) const
}

QgsGeos geos( d->geometry );
return geos.isEqual( *( geometry.d->geometry ) );
return geos.isEqual( geometry.d->geometry );
}

bool QgsGeometry::touches( const QgsGeometry &geometry ) const
Expand All @@ -1021,7 +1021,7 @@ bool QgsGeometry::touches( const QgsGeometry &geometry ) const
}

QgsGeos geos( d->geometry );
return geos.touches( *( geometry.d->geometry ) );
return geos.touches( geometry.d->geometry );
}

bool QgsGeometry::overlaps( const QgsGeometry &geometry ) const
Expand All @@ -1032,7 +1032,7 @@ bool QgsGeometry::overlaps( const QgsGeometry &geometry ) const
}

QgsGeos geos( d->geometry );
return geos.overlaps( *( geometry.d->geometry ) );
return geos.overlaps( geometry.d->geometry );
}

bool QgsGeometry::within( const QgsGeometry &geometry ) const
Expand All @@ -1043,7 +1043,7 @@ bool QgsGeometry::within( const QgsGeometry &geometry ) const
}

QgsGeos geos( d->geometry );
return geos.within( *( geometry.d->geometry ) );
return geos.within( geometry.d->geometry );
}

bool QgsGeometry::crosses( const QgsGeometry &geometry ) const
Expand All @@ -1054,7 +1054,7 @@ bool QgsGeometry::crosses( const QgsGeometry &geometry ) const
}

QgsGeos geos( d->geometry );
return geos.crosses( *( geometry.d->geometry ) );
return geos.crosses( geometry.d->geometry );
}

QString QgsGeometry::exportToWkt( int precision ) const
Expand Down Expand Up @@ -1394,7 +1394,7 @@ double QgsGeometry::distance( const QgsGeometry &geom ) const
}

QgsGeos g( d->geometry );
return g.distance( *( geom.d->geometry ) );
return g.distance( geom.d->geometry );
}

QgsGeometry QgsGeometry::buffer( double distance, int segments ) const
Expand All @@ -1405,12 +1405,8 @@ QgsGeometry QgsGeometry::buffer( double distance, int segments ) const
}

QgsGeos g( d->geometry );
QgsAbstractGeometry *geom = g.buffer( distance, segments );
if ( !geom )
{
return QgsGeometry();
}
return QgsGeometry( geom );
std::unique_ptr<QgsAbstractGeometry> geom( g.buffer( distance, segments ) );
return QgsGeometry( geom.release() );
}

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

QString error;
QgsAbstractGeometry *resultGeom = geos.intersection( *( geometry.d->geometry ), &error );
QgsAbstractGeometry *resultGeom = geos.intersection( geometry.d->geometry, &error );

if ( !resultGeom )
{
Expand All @@ -1819,7 +1815,7 @@ QgsGeometry QgsGeometry::combine( const QgsGeometry &geometry ) const
QgsGeos geos( d->geometry );
QString error;

QgsAbstractGeometry *resultGeom = geos.combine( *( geometry.d->geometry ), &error );
QgsAbstractGeometry *resultGeom = geos.combine( geometry.d->geometry, &error );
if ( !resultGeom )
{
QgsGeometry geom;
Expand Down Expand Up @@ -1856,7 +1852,7 @@ QgsGeometry QgsGeometry::difference( const QgsGeometry &geometry ) const
QgsGeos geos( d->geometry );

QString error;
QgsAbstractGeometry *resultGeom = geos.difference( *( geometry.d->geometry ), &error );
QgsAbstractGeometry *resultGeom = geos.difference( geometry.d->geometry, &error );
if ( !resultGeom )
{
QgsGeometry geom;
Expand All @@ -1877,7 +1873,7 @@ QgsGeometry QgsGeometry::symDifference( const QgsGeometry &geometry ) const

QString error;

QgsAbstractGeometry *resultGeom = geos.symDifference( *( geometry.d->geometry ), &error );
QgsAbstractGeometry *resultGeom = geos.symDifference( geometry.d->geometry, &error );
if ( !resultGeom )
{
QgsGeometry geom;
Expand Down Expand Up @@ -2051,7 +2047,7 @@ bool QgsGeometry::isGeosEqual( const QgsGeometry &g ) const
}

QgsGeos geos( d->geometry );
return geos.isEqual( *( g.d->geometry ) );
return geos.isEqual( g.d->geometry );
}

QgsGeometry QgsGeometry::unaryUnion( const QList<QgsGeometry> &geometries )
Expand Down
10 changes: 5 additions & 5 deletions src/core/geometry/qgsgeometryeditutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ int QgsGeometryEditUtils::addRing( QgsAbstractGeometry *geom, QgsCurve *ring )
ringGeom->prepareGeometry();

//for each polygon, test if inside outer ring and no intersection with other interior ring
QList< QgsCurvePolygon * >::iterator polyIter = polygonList.begin();
for ( ; polyIter != polygonList.end(); ++polyIter )
QList< QgsCurvePolygon * >::const_iterator polyIter = polygonList.constBegin();
for ( ; polyIter != polygonList.constEnd(); ++polyIter )
{
if ( ringGeom->within( **polyIter ) )
if ( ringGeom->within( *polyIter ) )
{
//check if disjoint with other interior rings
int nInnerRings = ( *polyIter )->numInteriorRings();
for ( int i = 0; i < nInnerRings; ++i )
{
if ( !ringGeom->disjoint( *( *polyIter )->interiorRing( i ) ) )
if ( !ringGeom->disjoint( ( *polyIter )->interiorRing( i ) ) )
{
delete ring;
return 4;
Expand Down Expand Up @@ -284,7 +284,7 @@ QgsAbstractGeometry *QgsGeometryEditUtils::avoidIntersections( const QgsAbstract
return nullptr;
}

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

delete combinedGeometries;
return diffGeom;
Expand Down
30 changes: 15 additions & 15 deletions src/core/geometry/qgsgeometryengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class CORE_EXPORT QgsGeometryEngine
virtual void geometryChanged() = 0;
virtual void prepareGeometry() = 0;

virtual QgsAbstractGeometry *intersection( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
virtual QgsAbstractGeometry *difference( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
virtual QgsAbstractGeometry *combine( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
virtual QgsAbstractGeometry *intersection( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
virtual QgsAbstractGeometry *difference( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
virtual QgsAbstractGeometry *combine( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
virtual QgsAbstractGeometry *combine( const QList< QgsAbstractGeometry * > &, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
virtual QgsAbstractGeometry *symDifference( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
virtual QgsAbstractGeometry *symDifference( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
virtual QgsAbstractGeometry *buffer( double distance, int segments, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
virtual QgsAbstractGeometry *buffer( double distance, int segments, int endCapStyle, int joinStyle, double miterLimit, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
virtual QgsAbstractGeometry *simplify( double tolerance, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
Expand All @@ -49,14 +49,14 @@ class CORE_EXPORT QgsGeometryEngine
virtual bool centroid( QgsPoint &pt, QString *errorMsg = nullptr ) const = 0;
virtual bool pointOnSurface( QgsPoint &pt, QString *errorMsg = nullptr ) const = 0;
virtual QgsAbstractGeometry *convexHull( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
virtual double distance( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
virtual bool intersects( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
virtual bool touches( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
virtual bool crosses( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
virtual bool within( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
virtual bool overlaps( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
virtual bool contains( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
virtual bool disjoint( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
virtual double distance( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
virtual bool intersects( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
virtual bool touches( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
virtual bool crosses( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
virtual bool within( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
virtual bool overlaps( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
virtual bool contains( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
virtual bool disjoint( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;

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

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

virtual double area( QString *errorMsg = nullptr ) const = 0;
virtual double length( QString *errorMsg = nullptr ) const = 0;
virtual bool isValid( QString *errorMsg = nullptr ) const = 0;
virtual bool isEqual( const QgsAbstractGeometry &geom, QString *errorMsg = nullptr ) const = 0;
virtual bool isEqual( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
virtual bool isEmpty( QString *errorMsg ) const = 0;

/** Determines whether the geometry is simple (according to OGC definition).
Expand Down
Loading

0 comments on commit 581b89e

Please sign in to comment.