16 #ifndef QGSGEOMETRYUTILS_H 17 #define QGSGEOMETRYUTILS_H 21 #include "qgis_core.h" 90 static double sqrDistToLine(
double ptX,
double ptY,
double x1,
double y1,
double x2,
double y2,
double &minDistX SIP_OUT,
double &minDistY SIP_OUT,
double epsilon );
139 static bool segmentIntersection(
const QgsPoint &p1,
const QgsPoint &p2,
const QgsPoint &q1,
const QgsPoint &q2,
QgsPoint &intersectionPoint SIP_OUT,
bool &isIntersection SIP_OUT,
const double tolerance = 1e-8,
bool acceptImproperIntersection =
false );
152 static bool lineCircleIntersection(
const QgsPointXY ¢er,
const double radius,
165 double nx = s2.
y() - s1.
y();
166 double ny = -( s2.
x() - s1.
x() );
167 double t = ( p.
x() * ny - p.
y() * nx - s1.
x() * ny + s1.
y() * nx ) / ( ( s2.
x() - s1.
x() ) * ny - ( s2.
y() - s1.
y() ) * nx );
168 return t < 0. ? s1 : t > 1. ? s2 :
QgsPoint( s1.
x() + ( s2.
x() - s1.
x() ) * t, s1.
y() + ( s2.
y() - s1.
y() ) * t );
189 static QVector<SelfIntersection> selfIntersections(
const QgsAbstractGeometry *geom,
int part,
int ring,
double tolerance )
SIP_SKIP;
198 static int leftOfLine(
double x,
double y,
double x1,
double y1,
double x2,
double y2 );
203 static QgsPoint pointOnLineWithDistance(
const QgsPoint &startPoint,
const QgsPoint &directionPoint,
double distance );
206 static double ccwAngle(
double dy,
double dx );
209 static void circleCenterRadius(
const QgsPoint &pt1,
const QgsPoint &pt2,
const QgsPoint &pt3,
double &radius SIP_OUT,
210 double ¢erX SIP_OUT,
double ¢erY SIP_OUT );
213 static bool circleClockwise(
double angle1,
double angle2,
double angle3 );
216 static bool circleAngleBetween(
double angle,
double angle1,
double angle2,
bool clockwise );
222 static bool angleOnCircle(
double angle,
double angle1,
double angle2,
double angle3 );
225 static double circleLength(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
228 static double sweepAngle(
double centerX,
double centerY,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
247 bool hasZ =
false,
bool hasM =
false );
260 static double interpolateArcValue(
double angle,
double a1,
double a2,
double a3,
double zm1,
double zm2,
double zm3 );
284 static QDomElement pointsToGML2(
const QgsPointSequence &points, QDomDocument &doc,
int precision,
const QString &ns )
SIP_SKIP;
290 static QDomElement pointsToGML3(
const QgsPointSequence &points, QDomDocument &doc,
int precision,
const QString &ns,
bool is3D )
SIP_SKIP;
303 static double normalizedAngle(
double angle );
313 static double lineAngle(
double x1,
double y1,
double x2,
double y2 );
326 static double angleBetweenThreePoints(
double x1,
double y1,
double x2,
double y2,
327 double x3,
double y3 );
338 static double linePerpendicularAngle(
double x1,
double y1,
double x2,
double y2 );
341 static double averageAngle(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
349 static double averageAngle(
double a1,
double a2 );
355 static QPair<QgsWkbTypes::Type, QString> wktReadBlock(
const QString &wkt )
SIP_SKIP;
364 static QStringList wktGetChildBlocks(
const QString &wkt,
const QString &defaultType = QString() ) SIP_SKIP;
402 static
QgsPointXY interpolatePointOnLine(
double x1,
double y1,
double x2,
double y2,
double fraction );
434 static
QgsPointXY interpolatePointOnLineByValue(
double x1,
double y1,
double v1,
double x2,
double y2,
double v2,
double value );
455 double &a SIP_OUT,
double &b SIP_OUT,
double &c SIP_OUT );
489 double minDist = std::numeric_limits<double>::max();
490 double minDistSegmentX = 0.0, minDistSegmentY = 0.0;
492 int minDistLeftOf = 0;
493 double sqrDist = 0.0;
494 int vertexOffset = 0;
498 for (
int i = 0; i < container.size(); ++i )
500 sqrDist = container.at( i )->closestSegment( pt, segmentPt, vertexAfter,
leftOf, epsilon );
501 if ( sqrDist >= 0 && sqrDist < minDist )
504 minDistSegmentX = segmentPt.x();
505 minDistSegmentY = segmentPt.y();
506 minDistVertexAfter = vertexAfter;
507 minDistVertexAfter.
vertex = vertexAfter.vertex + vertexOffset;
508 minDistVertexAfter.
part = vertexAfter.part + partOffset;
509 minDistVertexAfter.
ring = vertexAfter.ring + ringOffset;
516 if ( ctype == Vertex )
519 vertexOffset += container.at( i )->nCoordinates() - 1;
521 else if ( ctype == Ring )
525 else if ( ctype == Part )
531 if ( minDist == std::numeric_limits<double>::max() )
534 segmentPt.setX( minDistSegmentX );
535 segmentPt.setY( minDistSegmentY );
536 vertexAfter = minDistVertexAfter;
545 #endif // QGSGEOMETRYUTILS_H
Maximum angle between generating radii (lines from arc center to output vertices) ...
A class to represent a 2D point.
bool ANALYSIS_EXPORT lineIntersection(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Returns true, if line1 (p1 to p2) and line2 (p3 to p4) intersect. If the lines have an endpoint in co...
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Contains various geometry utility functions.
Utility class for identifying a unique vertex within a geometry.
Abstract base class for all geometries.
Point geometry type, with support for z-dimension and m-values.
A class to represent a vector.
QVector< QgsPoint > QgsPointSequence
Line string geometry type, with support for z-dimension and m-values.
static QgsPoint projectPointOnSegment(const QgsPoint &p, const QgsPoint &s1, const QgsPoint &s2)
Project the point on a segment.
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. Negativ values mean left a...
static double closestSegmentFromComponents(T &container, ComponentType ctype, const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf, double epsilon)
#define SIP_PYALTERNATIVETYPE(type)