QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
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 "qgslinestring.h"
24#include "qgspoint.h"
25#include "qgspolygon.h"
26
27#include <QString>
28
29using namespace Qt::StringLiterals;
30
40class CORE_EXPORT QgsQuadrilateral
41{
42 public:
43 // clang-format off
48 // clang-format on
49
58 QgsQuadrilateral( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, const QgsPoint &p4 ) SIP_HOLDGIL;
59
68 explicit QgsQuadrilateral( const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3, const QgsPointXY &p4 ) SIP_HOLDGIL;
69
70
80
95 static QgsQuadrilateral rectangleFrom3Points( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, ConstructionOption mode ) SIP_HOLDGIL;
96
105 static QgsQuadrilateral rectangleFromExtent( const QgsPoint &p1, const QgsPoint &p2 ) SIP_HOLDGIL;
106
107#ifndef SIP_RUN
108
113#endif
114
122 static QgsQuadrilateral squareFromDiagonal( const QgsPoint &p1, const QgsPoint &p2 ) SIP_HOLDGIL;
123
132 static QgsQuadrilateral rectangleFromCenterPoint( const QgsPoint &center, const QgsPoint &point ) SIP_HOLDGIL;
133
138 static QgsQuadrilateral fromRectangle( const QgsRectangle &rectangle ) SIP_HOLDGIL;
139
140 // TODO:
141 // Rhombus
142
148 bool equals( const QgsQuadrilateral &other, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const SIP_HOLDGIL;
149 bool operator==( const QgsQuadrilateral &other ) const SIP_HOLDGIL;
150 bool operator!=( const QgsQuadrilateral &other ) const SIP_HOLDGIL;
151
157 bool isValid() const SIP_HOLDGIL;
158
169
175 bool setPoint( const QgsPoint &newPoint, Point index ) SIP_HOLDGIL;
176
186 bool setPoints( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, const QgsPoint &p4 ) SIP_HOLDGIL;
187
191 QgsPointSequence points() const;
192
196 QgsPolygon *toPolygon( bool force2D = false ) const SIP_FACTORY;
197
201 QgsLineString *toLineString( bool force2D = false ) const SIP_FACTORY;
202
207 QString toString( int pointPrecision = 17 ) const;
208
212 double area() const SIP_HOLDGIL;
213
217 double perimeter() const SIP_HOLDGIL;
218#ifdef SIP_RUN
219// clang-format off
220 SIP_PYOBJECT __repr__();
221 % MethodCode
222 QString str = u"<QgsQuadrilateral: %1>"_s.arg( sipCpp->toString() );
223 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
224 % End
225// clang-format on
226#endif
227 private:
228 QgsPoint mPoint1, mPoint2, mPoint3, mPoint4;
229};
230
231#endif // QGSQUADRILATERAL_H
Line string geometry type, with support for z-dimension and m-values.
Represents a 2D point.
Definition qgspointxy.h:62
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
Polygon geometry type.
Definition qgspolygon.h:37
Quadrilateral geometry type.
static QgsQuadrilateral fromRectangle(const QgsRectangle &rectangle)
Construct a QgsQuadrilateral as a rectangle from a QgsRectangle.
static QgsQuadrilateral rectangleFromCenterPoint(const QgsPoint &center, const QgsPoint &point)
Construct a QgsQuadrilateral as a rectangle from center point center and another point point.
static QgsQuadrilateral rectangleFromExtent(const QgsPoint &p1, const QgsPoint &p2)
Construct a QgsQuadrilateral as a rectangle from an extent, defined by two opposite corner points.
static constexpr auto & rectangleFromDiagonal
Alias for rectangleFromDiagonal.
Point
Simple enumeration to ensure indices in setPoint.
bool isValid() const
Convenient method to determine if a QgsQuadrilateral is valid.
static QgsQuadrilateral squareFromDiagonal(const QgsPoint &p1, const QgsPoint &p2)
Construct a QgsQuadrilateral as a square from a diagonal.
QgsQuadrilateral()
Constructor for an empty quadrilateral geometry.
bool equals(const QgsQuadrilateral &other, double epsilon=4 *std::numeric_limits< double >::epsilon()) const
Compares two QgsQuadrilateral, allowing specification of the maximum allowable difference between poi...
ConstructionOption
A quadrilateral can be constructed from 3 points where the second distance can be determined by the t...
@ Distance
Second distance is equal to the distance between 2nd and 3rd point.
@ Projected
Second distance is equal to the distance of the perpendicular projection of the 3rd point on the segm...
A rectangle specified with double values.
#define SIP_HOLDGIL
Definition qgis_sip.h:178
#define SIP_FACTORY
Definition qgis_sip.h:83
QVector< QgsPoint > QgsPointSequence