Skip to content

Commit

Permalink
Move some more common geometry methods to headers to allow compiler i…
Browse files Browse the repository at this point in the history
…nlining
  • Loading branch information
nyalldawson committed Jun 19, 2018
1 parent 3ea8a41 commit 4059c9b
Show file tree
Hide file tree
Showing 17 changed files with 410 additions and 525 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_generated/geometry/qgscurvepolygon.sip.in
Expand Up @@ -71,7 +71,9 @@ Curve polygon geometry type


int numInteriorRings() const;

const QgsCurve *exteriorRing() const;

const QgsCurve *interiorRing( int i ) const;

virtual QgsPolygon *toPolygon( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const /Factory/;
Expand Down
1 change: 0 additions & 1 deletion python/core/auto_generated/geometry/qgspoint.sip.in
Expand Up @@ -92,7 +92,6 @@ Construct a QgsPoint from a QPointF

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


double x() const;
%Docstring
Returns the point's x-coordinate.
Expand Down
5 changes: 4 additions & 1 deletion python/core/auto_generated/geometry/qgsrectangle.sip.in
Expand Up @@ -33,14 +33,17 @@ Examples are storing a layer extent or the current view extent of a map
%Docstring
Constructor
%End

QgsRectangle( const QgsPointXY &p1, const QgsPointXY &p2 );
%Docstring
Construct a rectangle from two points. The rectangle is normalized after construction.
%End

QgsRectangle( const QRectF &qRectF );
%Docstring
Construct a rectangle from a QRectF. The rectangle is normalized after construction.
%End

QgsRectangle( const QgsRectangle &other );
%Docstring
Copy constructor
Expand Down Expand Up @@ -70,7 +73,7 @@ Sets the rectangle from two :py:class:`QgsPoints`. The rectangle is
normalised after construction.
%End

void set( double mXmin, double mYmin, double mXmax, double mYmax );
void set( double xMin, double yMin, double xMax, double yMax );
%Docstring
Sets the rectangle from four points. The rectangle is
normalised after construction.
Expand Down
11 changes: 0 additions & 11 deletions src/core/geometry/qgsabstractgeometry.cpp
Expand Up @@ -38,17 +38,6 @@ QgsAbstractGeometry &QgsAbstractGeometry::operator=( const QgsAbstractGeometry &
return *this;
}

bool QgsAbstractGeometry::is3D() const
{
return QgsWkbTypes::hasZ( mWkbType );
}

bool QgsAbstractGeometry::isMeasure() const
{
return QgsWkbTypes::hasM( mWkbType );
}


void QgsAbstractGeometry::setZMTypeFromSubGeometry( const QgsAbstractGeometry *subgeom, QgsWkbTypes::Type baseGeomType )
{
if ( !subgeom )
Expand Down
10 changes: 8 additions & 2 deletions src/core/geometry/qgsabstractgeometry.h
Expand Up @@ -181,13 +181,19 @@ class CORE_EXPORT QgsAbstractGeometry
* Returns true if the geometry is 3D and contains a z-value.
* \see isMeasure
*/
bool is3D() const;
bool is3D() const
{
return QgsWkbTypes::hasZ( mWkbType );
}

/**
* Returns true if the geometry contains m values.
* \see is3D
*/
bool isMeasure() const;
bool isMeasure() const
{
return QgsWkbTypes::hasM( mWkbType );
}

/**
* Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the geometry).
Expand Down
19 changes: 0 additions & 19 deletions src/core/geometry/qgscurvepolygon.cpp
Expand Up @@ -588,25 +588,6 @@ QgsPolygon *QgsCurvePolygon::toPolygon( double tolerance, SegmentationToleranceT
return poly.release();
}

int QgsCurvePolygon::numInteriorRings() const
{
return mInteriorRings.size();
}

const QgsCurve *QgsCurvePolygon::exteriorRing() const
{
return mExteriorRing.get();
}

const QgsCurve *QgsCurvePolygon::interiorRing( int i ) const
{
if ( i < 0 || i >= mInteriorRings.size() )
{
return nullptr;
}
return mInteriorRings.at( i );
}

void QgsCurvePolygon::setExteriorRing( QgsCurve *ring )
{
if ( !ring )
Expand Down
21 changes: 18 additions & 3 deletions src/core/geometry/qgscurvepolygon.h
Expand Up @@ -66,9 +66,24 @@ class CORE_EXPORT QgsCurvePolygon: public QgsSurface
bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;

//curve polygon interface
int numInteriorRings() const;
const QgsCurve *exteriorRing() const;
const QgsCurve *interiorRing( int i ) const;
int numInteriorRings() const
{
return mInteriorRings.size();
}

const QgsCurve *exteriorRing() const
{
return mExteriorRing.get();
}

const QgsCurve *interiorRing( int i ) const
{
if ( i < 0 || i >= mInteriorRings.size() )
{
return nullptr;
}
return mInteriorRings.at( i );
}

/**
* Returns a new polygon geometry corresponding to a segmentized approximation
Expand Down
10 changes: 0 additions & 10 deletions src/core/geometry/qgsgeometrycollection.cpp
Expand Up @@ -181,16 +181,6 @@ int QgsGeometryCollection::vertexNumberFromVertexId( QgsVertexId id ) const
return -1; // should not happen
}

int QgsGeometryCollection::numGeometries() const
{
return mGeometries.size();
}

const QgsAbstractGeometry *QgsGeometryCollection::geometryN( int n ) const
{
return mGeometries.value( n );
}

QgsAbstractGeometry *QgsGeometryCollection::geometryN( int n )
{
clearCache();
Expand Down
10 changes: 8 additions & 2 deletions src/core/geometry/qgsgeometrycollection.h
Expand Up @@ -47,14 +47,20 @@ class CORE_EXPORT QgsGeometryCollection: public QgsAbstractGeometry
/**
* Returns the number of geometries within the collection.
*/
int numGeometries() const;
int numGeometries() const
{
return mGeometries.size();
}

/**
* Returns a const reference to a geometry from within the collection.
* \param n index of geometry to return
* \note not available in Python bindings
*/
const QgsAbstractGeometry *geometryN( int n ) const SIP_SKIP;
const QgsAbstractGeometry *geometryN( int n ) const SIP_SKIP
{
return mGeometries.value( n );
}

/**
* Returns a geometry from within the collection.
Expand Down
60 changes: 0 additions & 60 deletions src/core/geometry/qgslinestring.cpp
Expand Up @@ -306,12 +306,6 @@ bool QgsLineString::fromWkb( QgsConstWkbPtr &wkbPtr )
return true;
}

void QgsLineString::fromWkbPoints( QgsWkbTypes::Type type, const QgsConstWkbPtr &wkb )
{
mWkbType = type;
importVerticesFromWkb( wkb );
}

QgsRectangle QgsLineString::calculateBoundingBox() const
{
double xmin = std::numeric_limits<double>::max();
Expand Down Expand Up @@ -550,48 +544,6 @@ double QgsLineString::yAt( int index ) const
return 0.0;
}

const double *QgsLineString::xData() const
{
return mX.constData();
}

const double *QgsLineString::yData() const
{
return mY.constData();
}

const double *QgsLineString::zData() const
{
if ( mZ.empty() )
return nullptr;
else
return mZ.constData();
}

const double *QgsLineString::mData() const
{
if ( mM.empty() )
return nullptr;
else
return mM.constData();
}

double QgsLineString::zAt( int index ) const
{
if ( index >= 0 && index < mZ.size() )
return mZ.at( index );
else
return std::numeric_limits<double>::quiet_NaN();
}

double QgsLineString::mAt( int index ) const
{
if ( index >= 0 && index < mM.size() )
return mM.at( index );
else
return std::numeric_limits<double>::quiet_NaN();
}

void QgsLineString::setXAt( int index, double x )
{
if ( index >= 0 && index < mX.size() )
Expand All @@ -606,18 +558,6 @@ void QgsLineString::setYAt( int index, double y )
clearCache();
}

void QgsLineString::setZAt( int index, double z )
{
if ( index >= 0 && index < mZ.size() )
mZ[ index ] = z;
}

void QgsLineString::setMAt( int index, double m )
{
if ( index >= 0 && index < mM.size() )
mM[ index ] = m;
}

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests.
Expand Down
60 changes: 51 additions & 9 deletions src/core/geometry/qgslinestring.h
Expand Up @@ -102,15 +102,21 @@ class CORE_EXPORT QgsLineString: public QgsCurve
* \see yData()
* \since QGIS 3.2
*/
const double *xData() const SIP_SKIP;
const double *xData() const SIP_SKIP
{
return mX.constData();
}

/**
* Returns a const pointer to the y vertex data.
* \note Not available in Python bindings
* \see xData()
* \since QGIS 3.2
*/
const double *yData() const SIP_SKIP;
const double *yData() const SIP_SKIP
{
return mY.constData();
}

/**
* Returns a const pointer to the z vertex data, or a nullptr if the linestring does
Expand All @@ -120,7 +126,13 @@ class CORE_EXPORT QgsLineString: public QgsCurve
* \see yData()
* \since QGIS 3.2
*/
const double *zData() const SIP_SKIP;
const double *zData() const SIP_SKIP
{
if ( mZ.empty() )
return nullptr;
else
return mZ.constData();
}

/**
* Returns a const pointer to the m vertex data, or a nullptr if the linestring does
Expand All @@ -130,7 +142,13 @@ class CORE_EXPORT QgsLineString: public QgsCurve
* \see yData()
* \since QGIS 3.2
*/
const double *mData() const SIP_SKIP;
const double *mData() const SIP_SKIP
{
if ( mM.empty() )
return nullptr;
else
return mM.constData();
}

/**
* Returns the z-coordinate of the specified node in the line string.
Expand All @@ -139,7 +157,13 @@ class CORE_EXPORT QgsLineString: public QgsCurve
* does not have a z dimension
* \see setZAt()
*/
double zAt( int index ) const;
double zAt( int index ) const
{
if ( index >= 0 && index < mZ.size() )
return mZ.at( index );
else
return std::numeric_limits<double>::quiet_NaN();
}

/**
* Returns the m value of the specified node in the line string.
Expand All @@ -148,7 +172,13 @@ class CORE_EXPORT QgsLineString: public QgsCurve
* does not have m values
* \see setMAt()
*/
double mAt( int index ) const;
double mAt( int index ) const
{
if ( index >= 0 && index < mM.size() )
return mM.at( index );
else
return std::numeric_limits<double>::quiet_NaN();
}

/**
* Sets the x-coordinate of the specified node in the line string.
Expand All @@ -175,7 +205,11 @@ class CORE_EXPORT QgsLineString: public QgsCurve
* \param z z-coordinate of node
* \see zAt()
*/
void setZAt( int index, double z );
void setZAt( int index, double z )
{
if ( index >= 0 && index < mZ.size() )
mZ[ index ] = z;
}

/**
* Sets the m value of the specified node in the line string.
Expand All @@ -184,7 +218,11 @@ class CORE_EXPORT QgsLineString: public QgsCurve
* \param m m value of node
* \see mAt()
*/
void setMAt( int index, double m );
void setMAt( int index, double m )
{
if ( index >= 0 && index < mM.size() )
mM[ index ] = m;
}

/**
* Resets the line string to match the specified list of points. The line string will
Expand Down Expand Up @@ -325,7 +363,11 @@ class CORE_EXPORT QgsLineString: public QgsCurve
* \param type WKB type
* \param wkb WKB representation of line geometry
*/
void fromWkbPoints( QgsWkbTypes::Type type, const QgsConstWkbPtr &wkb );
void fromWkbPoints( QgsWkbTypes::Type type, const QgsConstWkbPtr &wkb )
{
mWkbType = type;
importVerticesFromWkb( wkb );
}

friend class QgsPolygon;
friend class QgsTriangle;
Expand Down

0 comments on commit 4059c9b

Please sign in to comment.