1 /***************************************************************************
2                         qgsvertexid.h
3   -------------------------------------------------------------------
4 Date                 : 04 Sept 2014
5 Copyright            : (C) 2014 by Marco Hugentobler
6 email                : marco.hugentobler at sourcepole dot com
7  ***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 
16 #ifndef QGSVERTEXID_H
17 #define QGSVERTEXID_H
18 
19 #include "qgis_core.h"
20 #include "qgis.h"
21 
22 class QgsAbstractGeometry;
23 
24 /**
25  * \ingroup core
26  * \class QgsVertexId
27  * \brief Utility class for identifying a unique vertex within a geometry.
28  * \since QGIS 2.10
29  */
30 struct CORE_EXPORT QgsVertexId
31 {
32 
33   /**
34    * Constructor for QgsVertexId.
35    */
36   explicit QgsVertexId( int _part = -1, int _ring = -1, int _vertex = -1, Qgis::VertexType _type = Qgis::VertexType::Segment ) SIP_HOLDGIL
partQgsVertexId37 : part( _part )
38   , ring( _ring )
39   , vertex( _vertex )
40   , type( _type )
41   {}
42 
43   /**
44    * Returns TRUE if the vertex id is valid
45    */
isValidQgsVertexId46   bool isValid() const  SIP_HOLDGIL { return part >= 0 && ring >= 0 && vertex >= 0; }
47 
48   bool operator==( QgsVertexId other ) const SIP_HOLDGIL
49   {
50     return part == other.part && ring == other.ring && vertex == other.vertex;
51   }
52   bool operator!=( QgsVertexId other ) const SIP_HOLDGIL
53   {
54     return part != other.part || ring != other.ring || vertex != other.vertex;
55   }
56 
57   /**
58    * Returns TRUE if this vertex ID belongs to the same part as another vertex ID.
59    */
partEqualQgsVertexId60   bool partEqual( QgsVertexId o ) const SIP_HOLDGIL
61   {
62     return part >= 0 && o.part == part;
63   }
64 
65   /**
66    * Returns TRUE if this vertex ID belongs to the same ring as another vertex ID (i.e. the part
67    * and ring number are equal).
68    */
ringEqualQgsVertexId69   bool ringEqual( QgsVertexId o ) const SIP_HOLDGIL
70   {
71     return partEqual( o ) && ( ring >= 0 && o.ring == ring );
72   }
73 
74   /**
75    * Returns TRUE if this vertex ID corresponds to the same vertex as another vertex ID (i.e. the part,
76    * ring number and vertex number are equal).
77    */
vertexEqualQgsVertexId78   bool vertexEqual( QgsVertexId o ) const SIP_HOLDGIL
79   {
80     return ringEqual( o ) && ( vertex >= 0 && o.ring == ring );
81   }
82 
83   /**
84    * Returns TRUE if this vertex ID is valid for the specified \a geom.
85    */
86   bool isValid( const QgsAbstractGeometry *geom ) const SIP_HOLDGIL;
87 
88   //! Part number
89   int part = -1;
90 
91   //! Ring number
92   int ring = -1;
93 
94   //! Vertex number
95   int vertex = -1;
96 
97   //! Vertex type
98   Qgis::VertexType type = Qgis::VertexType::Segment;
99 
100 #ifdef SIP_RUN
101   SIP_PYOBJECT __repr__();
102   % MethodCode
103   QString str = QStringLiteral( "<QgsVertexId: %1,%2,%3 %4>" ).arg( sipCpp->part ).arg( sipCpp->ring ).arg( sipCpp->vertex ).arg( qgsEnumValueToKey( sipCpp->type ) );
104   sipRes = PyUnicode_FromString( str.toUtf8().data() );
105   % End
106 #endif
107 
108 };
109 
110 #endif //QGSVERTEXID_H
111