QGIS API Documentation  3.6.0-Noosa (5873452)
qgsquadrilateral.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsquadrilateral.h
3  -------------------
4  begin : November 2018
5  copyright : (C) 2018 by Loïc Bartoletti
6  email : loic dot bartoletti at oslandia dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSQUADRILATERAL_H
19 #define QGSQUADRILATERAL_H
20 
21 
22 #include "qgis_core.h"
23 #include "qgspoint.h"
24 #include "qgspolygon.h"
25 #include "qgslinestring.h"
26 
35 class CORE_EXPORT QgsQuadrilateral
36 {
37  public:
39 
48  QgsQuadrilateral( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, const QgsPoint &p4 );
49 
58  explicit QgsQuadrilateral( const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3, const QgsPointXY &p4 );
59 
60 
66  {
67  Distance, //<! Second distance is equal to the distance between 2nd and 3rd point
68  Projected, //<! Second distance is equal to the distance of the perpendicualr projection of the 3rd point on the segment or its extension.
69  };
70 
84  static QgsQuadrilateral rectangleFrom3Points( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, ConstructionOption mode );
85 
93  static QgsQuadrilateral rectangleFromExtent( const QgsPoint &p1, const QgsPoint &p2 );
94 
95 #ifndef SIP_RUN
96 
100  static constexpr auto &rectangleFromDiagonal = rectangleFromExtent;
101 #endif
102 
109  static QgsQuadrilateral squareFromDiagonal( const QgsPoint &p1, const QgsPoint &p2 );
110 
118  static QgsQuadrilateral rectangleFromCenterPoint( const QgsPoint &center, const QgsPoint &point );
119 
124  static QgsQuadrilateral fromRectangle( const QgsRectangle &rectangle );
125 
126  // TODO:
127  // Rhombus
128 
134  bool equals( const QgsQuadrilateral &other, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const;
135  bool operator==( const QgsQuadrilateral &other ) const;
136  bool operator!=( const QgsQuadrilateral &other ) const;
137 
143  bool isValid() const;
144 
148  enum Point
149  {
154  };
155 
161  bool setPoint( const QgsPoint &newPoint, Point index );
162 
171  bool setPoints( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, const QgsPoint &p4 );
172 
176  QgsPointSequence points() const;
177 
181  QgsPolygon *toPolygon( bool force2D = false ) const SIP_FACTORY;
182 
186  QgsLineString *toLineString( bool force2D = false ) const SIP_FACTORY;
187 
192  QString toString( int pointPrecision = 17 ) const;
193 
197  double area() const;
198 
202  double perimeter() const;
203 #ifdef SIP_RUN
204  SIP_PYOBJECT __repr__();
205  % MethodCode
206  QString str = QStringLiteral( "<QgsQuadrilateral: %1>" ).arg( sipCpp->toString() );
207  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
208  % End
209 #endif
210  private:
211  QgsPoint mPoint1, mPoint2, mPoint3, mPoint4;
212 };
213 
214 #endif // QGSQUADRILATERAL_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
A class to represent a 2D point.
Definition: qgspointxy.h:43
Quadrilateral geometry type.
CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry, caller is responsible for delete.
ConstructionOption
A quadrilateral can be constructed from 3 points where the second distance can be determined by the t...
#define SIP_FACTORY
Definition: qgis_sip.h:69
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
QVector< QgsPoint > QgsPointSequence
Point
Simple enumeration to ensure indices in setPoint.
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:43
Polygon geometry type.
Definition: qgspolygon.h:31