Skip to content

Commit

Permalink
Split QgsVertexId out to own file, promote type to enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 12, 2021
1 parent 8cc230d commit e733b51
Show file tree
Hide file tree
Showing 42 changed files with 316 additions and 231 deletions.
11 changes: 11 additions & 0 deletions python/core/auto_additions/qgis.py
Expand Up @@ -897,3 +897,14 @@
Qgis.RenderSubcomponentProperty.__doc__ = 'Rendering subcomponent properties.\n\n.. versionadded:: 3.22\n\n' + '* ``Generic``: ' + Qgis.RenderSubcomponentProperty.Generic.__doc__ + '\n' + '* ``ShadowOffset``: ' + Qgis.RenderSubcomponentProperty.ShadowOffset.__doc__ + '\n' + '* ``BlurSize``: ' + Qgis.RenderSubcomponentProperty.BlurSize.__doc__ + '\n' + '* ``GlowSpread``: ' + Qgis.RenderSubcomponentProperty.GlowSpread.__doc__
# --
Qgis.RenderSubcomponentProperty.baseClass = Qgis
QgsVertexId.VertexType = Qgis.VertexType
# monkey patching scoped based enum
QgsVertexId.SegmentVertex = Qgis.VertexType.Segment
QgsVertexId.SegmentVertex.is_monkey_patched = True
QgsVertexId.SegmentVertex.__doc__ = "The actual start or end point of a segment"
QgsVertexId.CurveVertex = Qgis.VertexType.Curve
QgsVertexId.CurveVertex.is_monkey_patched = True
QgsVertexId.CurveVertex.__doc__ = "An intermediate point on a segment defining the curvature of the segment"
Qgis.VertexType.__doc__ = 'Types of vertex.\n\n.. versionadded:: 3.22\n\n' + '* ``SegmentVertex``: ' + Qgis.VertexType.Segment.__doc__ + '\n' + '* ``CurveVertex``: ' + Qgis.VertexType.Curve.__doc__
# --
Qgis.VertexType.baseClass = Qgis
60 changes: 0 additions & 60 deletions python/core/auto_generated/geometry/qgsabstractgeometry.sip.in
Expand Up @@ -938,66 +938,6 @@ Clears any cached parameters associated with the geometry, e.g., bounding boxes
};


struct QgsVertexId
{

enum VertexType
{
SegmentVertex,
CurveVertex,
};

explicit QgsVertexId( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex ) /HoldGIL/;
%Docstring
Constructor for :py:class:`QgsVertexId`.
%End

bool isValid() const /HoldGIL/;
%Docstring
Returns ``True`` if the vertex id is valid
%End

bool operator==( QgsVertexId other ) const /HoldGIL/;
bool operator!=( QgsVertexId other ) const /HoldGIL/;

bool partEqual( QgsVertexId o ) const /HoldGIL/;
%Docstring
Returns ``True`` if this vertex ID belongs to the same part as another vertex ID.
%End

bool ringEqual( QgsVertexId o ) const /HoldGIL/;
%Docstring
Returns ``True`` if this vertex ID belongs to the same ring as another vertex ID (i.e. the part
and ring number are equal).
%End

bool vertexEqual( QgsVertexId o ) const /HoldGIL/;
%Docstring
Returns ``True`` if this vertex ID corresponds to the same vertex as another vertex ID (i.e. the part,
ring number and vertex number are equal).
%End

bool isValid( const QgsAbstractGeometry *geom ) const /HoldGIL/;
%Docstring
Returns ``True`` if this vertex ID is valid for the specified ``geom``.
%End

int part;

int ring;

int vertex;

VertexType type;

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsVertexId: %1,%2,%3%4>" ).arg( sipCpp->part ).arg( sipCpp->ring ).arg( sipCpp->vertex ).arg( sipCpp->type == QgsVertexId::CurveVertex ? QStringLiteral( " CurveVertex" ) : QString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End

};



class QgsVertexIterator
Expand Down
Expand Up @@ -170,7 +170,7 @@ Appends the contents of another circular ``string`` to the end of this circular

virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, int *leftOf /Out/ = 0, double epsilon = 4 * DBL_EPSILON ) const;

virtual bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const;
virtual bool pointAt( int node, QgsPoint &point, Qgis::VertexType &type ) const;

virtual void sumUpArea( double &sum /Out/ ) const;

Expand Down
Expand Up @@ -158,7 +158,7 @@ Converts the vertex at the given position from/to circular

virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, int *leftOf /Out/ = 0, double epsilon = 4 * DBL_EPSILON ) const;

virtual bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const;
virtual bool pointAt( int node, QgsPoint &point, Qgis::VertexType &type ) const;

virtual void sumUpArea( double &sum /Out/ ) const;

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgscurve.sip.in
Expand Up @@ -144,7 +144,7 @@ Sums up the area of the curve by iterating over the vertices (shoelace formula).
virtual int vertexNumberFromVertexId( QgsVertexId id ) const;


virtual bool pointAt( int node, QgsPoint &point /Out/, QgsVertexId::VertexType &type /Out/ ) const = 0;
virtual bool pointAt( int node, QgsPoint &point /Out/, Qgis::VertexType &type /Out/ ) const = 0;
%Docstring
Returns the point and vertex id of a point within the curve.

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/geometry/qgslinestring.sip.in
Expand Up @@ -692,7 +692,7 @@ of the curve.

virtual double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt /Out/, QgsVertexId &vertexAfter /Out/, int *leftOf /Out/ = 0, double epsilon = 4 * DBL_EPSILON ) const;

virtual bool pointAt( int node, QgsPoint &point, QgsVertexId::VertexType &type ) const;
virtual bool pointAt( int node, QgsPoint &point, Qgis::VertexType &type ) const;


virtual QgsPoint centroid() const;
Expand Down
72 changes: 72 additions & 0 deletions python/core/auto_generated/geometry/qgsvertexid.sip.in
@@ -0,0 +1,72 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/geometry/qgsvertexid.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




struct QgsVertexId
{

explicit QgsVertexId( int _part = -1, int _ring = -1, int _vertex = -1, Qgis::VertexType _type = Qgis::VertexType::Segment ) /HoldGIL/;
%Docstring
Constructor for :py:class:`QgsVertexId`.
%End

bool isValid() const /HoldGIL/;
%Docstring
Returns ``True`` if the vertex id is valid
%End

bool operator==( QgsVertexId other ) const /HoldGIL/;
bool operator!=( QgsVertexId other ) const /HoldGIL/;

bool partEqual( QgsVertexId o ) const /HoldGIL/;
%Docstring
Returns ``True`` if this vertex ID belongs to the same part as another vertex ID.
%End

bool ringEqual( QgsVertexId o ) const /HoldGIL/;
%Docstring
Returns ``True`` if this vertex ID belongs to the same ring as another vertex ID (i.e. the part
and ring number are equal).
%End

bool vertexEqual( QgsVertexId o ) const /HoldGIL/;
%Docstring
Returns ``True`` if this vertex ID corresponds to the same vertex as another vertex ID (i.e. the part,
ring number and vertex number are equal).
%End

bool isValid( const QgsAbstractGeometry *geom ) const /HoldGIL/;
%Docstring
Returns ``True`` if this vertex ID is valid for the specified ``geom``.
%End

int part;

int ring;

int vertex;

Qgis::VertexType type;

SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsVertexId: %1,%2,%3%4>" ).arg( sipCpp->part ).arg( sipCpp->ring ).arg( sipCpp->vertex ).arg( qgsEnumValueToKey( sipCpp->type ) );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/geometry/qgsvertexid.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
6 changes: 6 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -609,6 +609,12 @@ The development version
GlowSpread,
};

enum class VertexType
{
Segment,
Curve,
};

static const double DEFAULT_SEARCH_RADIUS_MM;

static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
Expand Down
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -324,6 +324,7 @@
%Include auto_generated/geometry/qgsregularpolygon.sip
%Include auto_generated/geometry/qgssurface.sip
%Include auto_generated/geometry/qgstriangle.sip
%Include auto_generated/geometry/qgsvertexid.sip
%Include auto_generated/geometry/qgswkbptr.sip
%Include auto_generated/geometry/qgswkbtypes.sip
%Include auto_generated/geometry/qgsray3d.sip
Expand Down
2 changes: 1 addition & 1 deletion src/app/vertextool/qgsvertexeditor.cpp
Expand Up @@ -295,7 +295,7 @@ bool QgsVertexEditorModel::calcR( int row, double &r, double &minRadius ) const

const QgsVertexEntry *entry = mLockedFeature->vertexMap().at( row );

const bool curvePoint = ( entry->vertexId().type == QgsVertexId::CurveVertex );
const bool curvePoint = ( entry->vertexId().type == Qgis::VertexType::Curve );
if ( !curvePoint )
return false;

Expand Down
1 change: 1 addition & 0 deletions src/app/vertextool/qgsvertexeditor.h
Expand Up @@ -27,6 +27,7 @@
#include "qgsdockwidget.h"
#include "qgspoint.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsvertexid.h"

class QLabel;
class QTableView;
Expand Down
2 changes: 1 addition & 1 deletion src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -122,7 +122,7 @@ int adjacentVertexIndexToEndpoint( const QgsGeometry &geom, int vertexIndex )
static bool isCircularVertex( const QgsGeometry &geom, int vertexIndex )
{
QgsVertexId vid;
return geom.vertexIdFromVertexNr( vertexIndex, vid ) && vid.type == QgsVertexId::CurveVertex;
return geom.vertexIdFromVertexNr( vertexIndex, vid ) && vid.type == Qgis::VertexType::Curve;
}


Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -765,6 +765,7 @@ set(QGIS_CORE_SRCS
geometry/qgsregularpolygon.cpp
geometry/qgssurface.cpp
geometry/qgstriangle.cpp
geometry/qgsvertexid.cpp
geometry/qgswkbptr.cpp
geometry/qgswkbtypes.cpp
geometry/qgsray3d.cpp
Expand Down Expand Up @@ -1300,6 +1301,7 @@ set(QGIS_CORE_HDRS
geometry/qgsregularpolygon.h
geometry/qgssurface.h
geometry/qgstriangle.h
geometry/qgsvertexid.h
geometry/qgswkbptr.h
geometry/qgswkbtypes.h
geometry/qgsray3d.h
Expand Down
2 changes: 1 addition & 1 deletion src/core/annotations/qgsannotationitemeditoperation.h
Expand Up @@ -21,7 +21,7 @@
#include "qgis_sip.h"
#include "qgis.h"
#include "qgspointxy.h"
#include "qgsabstractgeometry.h"
#include "qgsvertexid.h"
#include "qgsgeometry.h"

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/annotations/qgsannotationitemnode.h
Expand Up @@ -20,7 +20,7 @@
#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgspointxy.h"
#include "qgsabstractgeometry.h"
#include "qgsvertexid.h"
#include "qgis.h"

/**
Expand Down
3 changes: 2 additions & 1 deletion src/core/geometry/qgsabstractgeometry.cpp
Expand Up @@ -20,6 +20,7 @@ email : marco.hugentobler at sourcepole dot com
#include "qgsmaptopixel.h"
#include "qgspoint.h"
#include "qgsgeometrycollection.h"
#include "qgsvertexid.h"

#include <nlohmann/json.hpp>
#include <limits>
Expand Down Expand Up @@ -469,7 +470,7 @@ QgsVertexId QgsAbstractGeometry::vertex_iterator::vertexId() const
}

// get the vertex type: find out from the leaf geometry
QgsVertexId::VertexType vertexType = QgsVertexId::SegmentVertex;
Qgis::VertexType vertexType = Qgis::VertexType::Segment;
if ( const QgsCurve *curve = dynamic_cast<const QgsCurve *>( levels[depth].g ) )
{
QgsPoint p;
Expand Down
100 changes: 0 additions & 100 deletions src/core/geometry/qgsabstractgeometry.h
Expand Up @@ -1138,106 +1138,6 @@ class CORE_EXPORT QgsAbstractGeometry
};


/**
* \ingroup core
* \class QgsVertexId
* \brief Utility class for identifying a unique vertex within a geometry.
* \since QGIS 2.10
*/
struct CORE_EXPORT QgsVertexId
{

/**
* Type of vertex
*/
enum VertexType
{
SegmentVertex = 1, //!< The actual start or end point of a segment
CurveVertex, //!< An intermediate point on a segment defining the curvature of the segment
};

/**
* Constructor for QgsVertexId.
*/
explicit QgsVertexId( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex ) SIP_HOLDGIL
: part( _part )
, ring( _ring )
, vertex( _vertex )
, type( _type )
{}

/**
* Returns TRUE if the vertex id is valid
*/
bool isValid() const SIP_HOLDGIL { return part >= 0 && ring >= 0 && vertex >= 0; }

bool operator==( QgsVertexId other ) const SIP_HOLDGIL
{
return part == other.part && ring == other.ring && vertex == other.vertex;
}
bool operator!=( QgsVertexId other ) const SIP_HOLDGIL
{
return part != other.part || ring != other.ring || vertex != other.vertex;
}

/**
* Returns TRUE if this vertex ID belongs to the same part as another vertex ID.
*/
bool partEqual( QgsVertexId o ) const SIP_HOLDGIL
{
return part >= 0 && o.part == part;
}

/**
* Returns TRUE if this vertex ID belongs to the same ring as another vertex ID (i.e. the part
* and ring number are equal).
*/
bool ringEqual( QgsVertexId o ) const SIP_HOLDGIL
{
return partEqual( o ) && ( ring >= 0 && o.ring == ring );
}

/**
* Returns TRUE if this vertex ID corresponds to the same vertex as another vertex ID (i.e. the part,
* ring number and vertex number are equal).
*/
bool vertexEqual( QgsVertexId o ) const SIP_HOLDGIL
{
return ringEqual( o ) && ( vertex >= 0 && o.ring == ring );
}

/**
* Returns TRUE if this vertex ID is valid for the specified \a geom.
*/
bool isValid( const QgsAbstractGeometry *geom ) const SIP_HOLDGIL
{
return ( part >= 0 && part < geom->partCount() ) &&
( ring < geom->ringCount( part ) ) &&
( vertex < 0 || vertex < geom->vertexCount( part, ring ) );
}

//! Part number
int part = -1;

//! Ring number
int ring = -1;

//! Vertex number
int vertex = -1;

//! Vertex type
VertexType type = SegmentVertex;

#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsVertexId: %1,%2,%3%4>" ).arg( sipCpp->part ).arg( sipCpp->ring ).arg( sipCpp->vertex ).arg( sipCpp->type == QgsVertexId::CurveVertex ? QStringLiteral( " CurveVertex" ) : QString() );
sipRes = PyUnicode_FromString( str.toUtf8().data() );
% End
#endif

};

#ifndef SIP_RUN

template <class T>
Expand Down

0 comments on commit e733b51

Please sign in to comment.