Skip to content
Permalink
Browse files

Merge pull request #5247 from nyalldawson/geometry_coverage

Geometry unit test coverage
  • Loading branch information
nyalldawson committed Sep 25, 2017
2 parents 5f11793 + 57108f9 commit 386d52d87313670f9e75946150d921801f66c187
@@ -2005,6 +2005,7 @@ QgsRectangle {#qgis_api_break_3_0_QgsRectangle}

- The protected members were removed - QgsRectangle is not intended to be subclassed.
- unionRect was removed. Use combineExtentWith instead.
- buffer was renamed to buffered.

QgsRelation {#qgis_api_break_3_0_QgsRelation}
-----------
@@ -163,18 +163,20 @@ Copy constructor

void grow( double delta );
%Docstring
Grows the rectangle by the specified amount.
Grows the rectangle in place by the specified amount.
.. seealso:: buffered()
%End

void include( const QgsPointXY &p );
%Docstring
Updates the rectangle to include the specified point.
%End

QgsRectangle buffer( double width );
QgsRectangle buffered( double width ) const;
%Docstring
Get rectangle enlarged by buffer.
.. versionadded:: 2.1
.. seealso:: grow()
:rtype: QgsRectangle
%End

@@ -263,7 +263,7 @@ def run(item, action, mainwindow):
ext = node_extent
ext.combineExtentWith(edge_extent)
# Grow by 1/20 of largest side
ext = ext.buffer(max(ext.width(), ext.height()) / 20)
ext = ext.buffered(max(ext.width(), ext.height()) / 20)
canvas.setExtent(ext)

# restore canvas render flag
@@ -436,7 +436,7 @@ void QgsCompoundCurve::removeCurve( int i )

void QgsCompoundCurve::addVertex( const QgsPoint &pt )
{
if ( mWkbType == QgsWkbTypes::Unknown )
if ( mCurves.isEmpty() || mWkbType == QgsWkbTypes::Unknown )
{
setZMTypeFromSubGeometry( &pt, QgsWkbTypes::CompoundCurve );
}
@@ -606,15 +606,15 @@ bool QgsCompoundCurve::deleteVertex( QgsVertexId position )
if ( mCurves.at( curveIds.at( 0 ).first )->numPoints() == 0 &&
mCurves.at( curveIds.at( 1 ).first )->numPoints() != 0 )
{
removeCurve( curveIds.at( 0 ).first );
mCurves.at( curveIds.at( 1 ).first )->moveVertex( QgsVertexId( 0, 0, 0 ), startPoint );
removeCurve( curveIds.at( 0 ).first );
}
else if ( mCurves.at( curveIds.at( 0 ).first )->numPoints() != 0 &&
mCurves.at( curveIds.at( 1 ).first )->numPoints() == 0 )
{
removeCurve( curveIds.at( 1 ).first );
mCurves.at( curveIds.at( 0 ).first )->moveVertex(
QgsVertexId( 0, 0, mCurves.at( curveIds.at( 0 ).first )->numPoints() - 1 ), endPoint );
removeCurve( curveIds.at( 1 ).first );
}
else if ( mCurves.at( curveIds.at( 0 ).first )->numPoints() == 0 &&
mCurves.at( curveIds.at( 1 ).first )->numPoints() == 0 )
@@ -2669,7 +2669,7 @@ bool QgsGeometry::compare( const QgsMultiPolygon &p1, const QgsMultiPolygon &p2,

QgsGeometry QgsGeometry::smooth( const unsigned int iterations, const double offset, double minimumDistance, double maxAngle ) const
{
if ( d->geometry->isEmpty() )
if ( !d->geometry || d->geometry->isEmpty() )
return QgsGeometry();

QgsGeometry geom = *this;
@@ -128,6 +128,8 @@ bool QgsGeometryCollection::insertGeometry( QgsAbstractGeometry *g, int index )
return false;
}

index = std::min( mGeometries.count(), index );

mGeometries.insert( index, g );
clearCache(); //set bounding box invalid
return true;
@@ -183,17 +185,6 @@ void QgsGeometryCollection::transform( const QTransform &t )
clearCache(); //set bounding box invalid
}

#if 0
void QgsGeometryCollection::clip( const QgsRectangle &rect )
{
QVector< QgsAbstractGeometry * >::iterator it = mGeometries.begin();
for ( ; it != mGeometries.end(); ++it )
{
( *it )->clip( rect );
}
}
#endif

void QgsGeometryCollection::draw( QPainter &p ) const
{
QVector< QgsAbstractGeometry * >::const_iterator it = mGeometries.constBegin();
@@ -210,7 +201,11 @@ bool QgsGeometryCollection::fromWkb( QgsConstWkbPtr &wkbPtr )
return false;
}

mWkbType = wkbPtr.readHeader();
QgsWkbTypes::Type wkbType = wkbPtr.readHeader();
if ( QgsWkbTypes::flatType( wkbType ) != QgsWkbTypes::flatType( mWkbType ) )
return false;

mWkbType = wkbType;

int nGeometries = 0;
wkbPtr >> nGeometries;
@@ -419,6 +414,9 @@ bool QgsGeometryCollection::nextVertex( QgsVertexId &id, QgsPoint &vertex ) cons
return false;
}

if ( id.part >= mGeometries.count() )
return false;

QgsAbstractGeometry *geom = mGeometries.at( id.part );
if ( geom->nextVertex( id, vertex ) )
{
@@ -451,7 +449,7 @@ bool QgsGeometryCollection::insertVertex( QgsVertexId position, const QgsPoint &

bool QgsGeometryCollection::moveVertex( QgsVertexId position, const QgsPoint &newPos )
{
if ( position.part >= mGeometries.size() )
if ( position.part < 0 || position.part >= mGeometries.size() )
{
return false;
}
@@ -466,7 +464,7 @@ bool QgsGeometryCollection::moveVertex( QgsVertexId position, const QgsPoint &ne

bool QgsGeometryCollection::deleteVertex( QgsVertexId position )
{
if ( position.part >= mGeometries.size() )
if ( position.part < 0 || position.part >= mGeometries.size() )
{
return false;
}
@@ -615,7 +613,7 @@ QgsAbstractGeometry *QgsGeometryCollection::segmentize( double tolerance, Segmen

double QgsGeometryCollection::vertexAngle( QgsVertexId vertex ) const
{
if ( vertex.part >= mGeometries.size() )
if ( vertex.part < 0 || vertex.part >= mGeometries.size() )
{
return 0.0;
}
@@ -631,11 +629,21 @@ double QgsGeometryCollection::vertexAngle( QgsVertexId vertex ) const

int QgsGeometryCollection::vertexCount( int part, int ring ) const
{
if ( part < 0 || part >= mGeometries.size() )
{
return 0;
}

return mGeometries[part]->vertexCount( 0, ring );
}

int QgsGeometryCollection::ringCount( int part ) const
{
if ( part < 0 || part >= mGeometries.size() )
{
return 0;
}

return mGeometries[part]->ringCount();
}

@@ -682,7 +690,7 @@ bool QgsGeometryCollection::addMValue( double mValue )

bool QgsGeometryCollection::dropZValue()
{
if ( !is3D() )
if ( mWkbType != QgsWkbTypes::GeometryCollection && !is3D() )
return false;

mWkbType = QgsWkbTypes::dropZ( mWkbType );
@@ -696,7 +704,7 @@ bool QgsGeometryCollection::dropZValue()

bool QgsGeometryCollection::dropMValue()
{
if ( !isMeasure() )
if ( mWkbType != QgsWkbTypes::GeometryCollection && !isMeasure() )
return false;

mWkbType = QgsWkbTypes::dropM( mWkbType );
@@ -147,7 +147,7 @@ void QgsRectangle::include( const QgsPointXY &p )
setYMaximum( p.y() );
}

QgsRectangle QgsRectangle::buffer( double width )
QgsRectangle QgsRectangle::buffered( double width ) const
{
return QgsRectangle( mXmin - width, mYmin - width, mXmax + width, mYmax + width );
}
@@ -254,7 +254,7 @@ QgsRectangle &QgsRectangle::operator+=( const QgsVector v )

bool QgsRectangle::isEmpty() const
{
return mXmax <= mXmin || mYmax <= mYmin;
return mXmax < mXmin || mYmax < mYmin || qgsDoubleNear( mXmax, mXmin ) || qgsDoubleNear( mYmax, mYmin );
}

bool QgsRectangle::isNull() const
@@ -161,7 +161,8 @@ class CORE_EXPORT QgsRectangle
void scale( double scaleFactor, double centerX, double centerY );

/**
* Grows the rectangle by the specified amount.
* Grows the rectangle in place by the specified amount.
* \see buffered()
*/
void grow( double delta );

@@ -173,8 +174,9 @@ class CORE_EXPORT QgsRectangle
/**
* Get rectangle enlarged by buffer.
* \since QGIS 2.1
* \see grow()
*/
QgsRectangle buffer( double width );
QgsRectangle buffered( double width ) const;

/**
* Return the intersection with the given rectangle.
@@ -157,5 +157,5 @@ QgsRectangle QgsGeometryRubberBand::rubberBandRectangle() const
qreal scale = mMapCanvas->mapUnitsPerPixel();
qreal s = ( mIconSize - 1 ) / 2.0 * scale;
qreal p = mPen.width() * scale;
return mGeometry->boundingBox().buffer( s + p );
return mGeometry->boundingBox().buffered( s + p );
}

0 comments on commit 386d52d

Please sign in to comment.
You can’t perform that action at this time.