QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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:
38 
43 
52  QgsQuadrilateral( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, const QgsPoint &p4 ) SIP_HOLDGIL;
53 
62  explicit QgsQuadrilateral( const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3, const QgsPointXY &p4 ) SIP_HOLDGIL;
63 
64 
70  {
73  };
74 
88  static QgsQuadrilateral rectangleFrom3Points( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, ConstructionOption mode ) SIP_HOLDGIL;
89 
97  static QgsQuadrilateral rectangleFromExtent( const QgsPoint &p1, const QgsPoint &p2 ) SIP_HOLDGIL;
98 
99 #ifndef SIP_RUN
100 
104  static constexpr auto &rectangleFromDiagonal = rectangleFromExtent;
105 #endif
106 
113  static QgsQuadrilateral squareFromDiagonal( const QgsPoint &p1, const QgsPoint &p2 ) SIP_HOLDGIL;
114 
122  static QgsQuadrilateral rectangleFromCenterPoint( const QgsPoint &center, const QgsPoint &point ) SIP_HOLDGIL;
123 
128  static QgsQuadrilateral fromRectangle( const QgsRectangle &rectangle ) SIP_HOLDGIL;
129 
130  // TODO:
131  // Rhombus
132 
138  bool equals( const QgsQuadrilateral &other, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const SIP_HOLDGIL;
139  bool operator==( const QgsQuadrilateral &other ) const SIP_HOLDGIL;
140  bool operator!=( const QgsQuadrilateral &other ) const SIP_HOLDGIL;
141 
147  bool isValid() const SIP_HOLDGIL;
148 
152  enum Point
153  {
158  };
159 
165  bool setPoint( const QgsPoint &newPoint, Point index ) SIP_HOLDGIL;
166 
176  bool setPoints( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, const QgsPoint &p4 ) SIP_HOLDGIL;
177 
181  QgsPointSequence points() const;
182 
186  QgsPolygon *toPolygon( bool force2D = false ) const SIP_FACTORY;
187 
191  QgsLineString *toLineString( bool force2D = false ) const SIP_FACTORY;
192 
197  QString toString( int pointPrecision = 17 ) const;
198 
202  double area() const SIP_HOLDGIL;
203 
207  double perimeter() const SIP_HOLDGIL;
208 #ifdef SIP_RUN
209  SIP_PYOBJECT __repr__();
210  % MethodCode
211  QString str = QStringLiteral( "<QgsQuadrilateral: %1>" ).arg( sipCpp->toString() );
212  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
213  % End
214 #endif
215  private:
216  QgsPoint mPoint1, mPoint2, mPoint3, mPoint4;
217 };
218 
219 #endif // QGSQUADRILATERAL_H
qgspolygon.h
QgsQuadrilateral::Point
Point
Simple enumeration to ensure indices in setPoint.
Definition: qgsquadrilateral.h:153
QgsPolygon
Polygon geometry type.
Definition: qgspolygon.h:34
qgslinestring.h
QgsQuadrilateral
Quadrilateral geometry type.
Definition: qgsquadrilateral.h:36
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
QgsQuadrilateral::Point1
@ Point1
Definition: qgsquadrilateral.h:154
QgsQuadrilateral::ConstructionOption
ConstructionOption
A quadrilateral can be constructed from 3 points where the second distance can be determined by the t...
Definition: qgsquadrilateral.h:70
QgsQuadrilateral::Projected
@ Projected
Second distance is equal to the distance of the perpendicualr projection of the 3rd point on the segm...
Definition: qgsquadrilateral.h:72
qgspoint.h
QgsQuadrilateral::Point4
@ Point4
Definition: qgsquadrilateral.h:157
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsQuadrilateral::Distance
@ Distance
Second distance is equal to the distance between 2nd and 3rd point.
Definition: qgsquadrilateral.h:71
SIP_HOLDGIL
#define SIP_HOLDGIL
Definition: qgis_sip.h:157
QgsMeshUtils::toPolygon
CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry, caller is responsible for delete.
Definition: qgstriangularmesh.cpp:509
QgsQuadrilateral::Point2
@ Point2
Definition: qgsquadrilateral.h:155
QgsQuadrilateral::QgsQuadrilateral
QgsQuadrilateral() SIP_HOLDGIL
Constructor for an empty quadrilateral geometry.
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsPointSequence
QVector< QgsPoint > QgsPointSequence
Definition: qgsabstractgeometry.h:46
QgsQuadrilateral::Point3
@ Point3
Definition: qgsquadrilateral.h:156