37 double z = std::numeric_limits< double >::quiet_NaN();
41 if ( p2.
is3D() && std::isnan( z ) )
43 if ( p3.
is3D() && std::isnan( z ) )
45 if ( !std::isnan( z ) )
56 QgsPoint point1( pType, p1.
x(), p1.
y(), std::isnan( p1.
z() ) ? z : p1.
z() );
57 QgsPoint point2( pType, p2.
x(), p2.
y(), std::isnan( p2.
z() ) ? z : p2.
z() );
58 QgsPoint point3( pType, p3.
x(), p3.
y(), std::isnan( p3.
z() ) ? z : p3.
z() );
61 double inclination = 90.0;
63 double azimuth = point1.azimuth( point2 ) + 90.0 *
QgsGeometryUtils::leftOfLine( point3.x(), point3.y(), point1.x(), point1.y(), point2.x(), point2.y() );
68 if ( point2.is3D() && point3.is3D() )
70 inclination = point2.inclination( point3 );
71 distance = point2.distance3D( point3 );
75 distance = point2.distance( point3 );
78 rect.setPoints( point1, point2, point2.project( distance, azimuth, inclination ), point1.project( distance, azimuth, inclination ) );
84 QgsVector3D( point2.x(), point2.y(), std::isnan( point2.z() ) ? z : point2.z() ),
85 QgsVector3D( point3.x(), point3.y(), std::isnan( point3.z() ) ? z : point3.z() ) );
108 rect.setPoints( fp1, fp2, fp3, fp4 );
125 double xMin = 0, xMax = 0, yMin = 0, yMax = 0;
127 if ( p1.
x() < p2.
x() )
139 if ( p1.
y() < p2.
y() )
168 double azimuth = p1.
azimuth( point3 ) + 90.0;
169 double distance = p1.
distance( point3 ) / 2.0;
172 point2 = midPoint.
project( -distance, azimuth );
173 point4 = midPoint.
project( distance, azimuth );
179 point2 =
QgsPoint( point2.
x(), point2.
y(), z );
180 point3 =
QgsPoint( point3.
x(), point3.
y(), z );
181 point4 =
QgsPoint( point4.
x(), point4.
y(), z );
184 quad.
setPoints( p1, point2, point3, point4 );
193 double xOffset = std::fabs( point.
x() - center.
x() );
194 double yOffset = std::fabs( point.
y() - center.
y() );
197 QgsPoint( center.
x() - xOffset, center.
y() + yOffset, center.
z() ),
198 QgsPoint( center.
x() + xOffset, center.
y() + yOffset, center.
z() ),
199 QgsPoint( center.
x() + xOffset, center.
y() - yOffset, center.
z() ) );
216 static bool equalPoint(
const QgsPoint &p1,
const QgsPoint &p2,
double epsilon )
222 equal &=
qgsDoubleNear( p1.
z(), p2.
z(), epsilon ) || ( std::isnan( p1.
z() ) && std::isnan( p2.
z() ) );
224 equal &=
qgsDoubleNear( p1.
m(), p2.
m(), epsilon ) || ( std::isnan( p1.
m() ) && std::isnan( p2.
m() ) );
239 return ( ( equalPoint( mPoint1, other.mPoint1, epsilon ) ) &&
240 ( equalPoint( mPoint2, other.mPoint2, epsilon ) ) &&
241 ( equalPoint( mPoint3, other.mPoint3, epsilon ) ) &&
242 ( equalPoint( mPoint4, other.mPoint4, epsilon ) ) );
271 return !( isIntersection1234 || isIntersection2341 );
292 ( p1 == p2 ) || ( p1 == p3 ) || ( p1 == p4 ) || ( p2 == p3 ) || ( p2 == p4 ) || ( p3 == p4 ) );
294 return !doublePoints;
306 haveSameType( p1, p2, p3, p4 ) &&
307 notHaveDoublePoints( p1, p2, p3, p4 ) &&
308 isNotAntiParallelogram( p1, p2, p3, p4 ) &&
309 isNotCollinear( p1, p2, p3, p4 )
315 return validate( mPoint1, mPoint2, mPoint3, mPoint4 );
323 if ( validate( newPoint, mPoint2, mPoint3, mPoint4 ) ==
false )
328 if ( validate( mPoint1, newPoint, mPoint3, mPoint4 ) ==
false )
333 if ( validate( mPoint1, mPoint2, newPoint, mPoint4 ) ==
false )
338 if ( validate( mPoint1, mPoint2, mPoint3, newPoint ) ==
false )
349 if ( validate( p1, p2, p3, p4 ) ==
false )
364 pts << mPoint1 << mPoint2 << mPoint3 << mPoint4 << mPoint1;
371 std::unique_ptr<QgsPolygon> polygon = qgis::make_unique< QgsPolygon >();
374 return polygon.release();
379 return polygon.release();
384 std::unique_ptr<QgsLineString> ext = qgis::make_unique< QgsLineString>();
387 return ext.release();
393 ext->setPoints( pts );
398 return ext.release();
405 rep = QStringLiteral(
"Empty" );
407 rep = QStringLiteral(
"Quadrilateral (Point 1: %1, Point 2: %2, Point 3: %3, Point 4: %4)" )
408 .arg( mPoint1.
asWkt( pointPrecision ), 0,
's' )
409 .arg( mPoint2.
asWkt( pointPrecision ), 0,
's' )
410 .arg( mPoint3.
asWkt( pointPrecision ), 0,
's' )
411 .arg( mPoint4.
asWkt( pointPrecision ), 0,
's' );
bool isMeasure() const
Returns true if the geometry contains m values.
static QgsQuadrilateral squareFromDiagonal(const QgsPoint &p1, const QgsPoint &p2)
Construct a QgsQuadrilateral as a square from a diagonal.
3 Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double preci...
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...
A rectangle specified with double values.
double area() const
Returns the area of the quadrilateral, or 0 if the quadrilateral is empty.
static bool segmentIntersection(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint, bool &isIntersection, double tolerance=1e-8, bool acceptImproperIntersection=false)
Compute the intersection between two segments.
static int segmentSide(const QgsPoint &pt1, const QgsPoint &pt3, const QgsPoint &pt2)
For line defined by points pt1 and pt3, find out on which side of the line is point pt3...
bool isValid() const
Convenient method to determine if a QgsQuadrilateral is valid.
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
double azimuth(const QgsPoint &other) const
Calculates azimuth between this point and other one (clockwise in degree, starting from north) ...
A class to represent a 2D point.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Quadrilateral geometry type.
double y() const
Returns Y coordinate.
double inclination(const QgsPoint &other) const
Calculates inclination between this point and other one (starting from zenith = 0 to nadir = 180...
double area() const override
Returns the area of the geometry.
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
bool setPoints(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, const QgsPoint &p4)
Set all points Returns false if the QgsQuadrilateral is not valid:
double z() const
Returns Z coordinate.
static QgsQuadrilateral fromRectangle(const QgsRectangle &rectangle)
Construct a QgsQuadrilateral as a rectangle from a QgsRectangle.
Type
The WKB type describes the number of dimensions a geometry has.
static int leftOfLine(const double x, const double y, const double x1, const double y1, const double x2, const double y2)
Returns a value < 0 if the point (x, y) is left of the line from (x1, y1) -> ( x2, y2).
static QgsPoint midpoint(const QgsPoint &pt1, const QgsPoint &pt2)
Returns a middle point between points pt1 and pt2.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
static QgsVector3D perpendicularPoint(const QgsVector3D &v1, const QgsVector3D &v2, const QgsVector3D &vp)
Returns the perpendicular point of vector vp from [v1 - v2].
static QgsQuadrilateral rectangleFrom3Points(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3, ConstructionOption mode)
Construct a QgsQuadrilateral as a Rectangle from 3 points.
double perimeter() const override
Returns the perimeter of the geometry.
ConstructionOption
A quadrilateral can be constructed from 3 points where the second distance can be determined by the t...
bool operator!=(const QgsQuadrilateral &other) const
QgsPolygon * toPolygon(bool force2D=false) const
Returns the quadrilateral as a new polygon.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
QgsPoint project(double distance, double azimuth, double inclination=90.0) const
Returns a new point which correspond to this point projected by a specified distance with specified a...
Point geometry type, with support for z-dimension and m-values.
static QgsQuadrilateral rectangleFromExtent(const QgsPoint &p1, const QgsPoint &p2)
Construct a QgsQuadrilateral as a rectangle from an extent, defined by two opposite corner points...
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
QVector< QgsPoint > QgsPointSequence
Point
Simple enumeration to ensure indices in setPoint.
void setExteriorRing(QgsCurve *ring) override
Sets the exterior ring of the polygon.
Line string geometry type, with support for z-dimension and m-values.
bool setPoint(const QgsPoint &newPoint, Point index)
Sets the point newPoint at the index.
QgsPointSequence points() const
Returns a list including the vertices of the quadrilateral.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QString toString(int pointPrecision=17) const
Returns a string representation of the quadrilateral.
QgsLineString * toLineString(bool force2D=false) const
Returns the quadrilateral as a new linestring.
static QgsQuadrilateral rectangleFromCenterPoint(const QgsPoint ¢er, const QgsPoint &point)
Construct a QgsQuadrilateral as a rectangle from center point center and another point point...
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
bool operator==(const QgsQuadrilateral &other) const
double distance3D(double x, double y, double z) const
Returns the 3D distance between this point and a specified x, y, z coordinate.
double x() const
Returns X coordinate.
double perimeter() const
Returns the perimeter of the quadrilateral, or 0 if the quadrilateral is empty.