16 #ifndef QGSGEOMETRYUTILS_H
17 #define QGSGEOMETRYUTILS_H
46 static double sqrDistToLine(
double ptX,
double ptY,
double x1,
double y1,
double x2,
double y2,
double& minDistX,
double& minDistY,
double epsilon );
80 double nx = s2.
y() - s1.
y();
81 double ny = -( s2.
x() - s1.
x() );
82 double t = ( p.
x() * ny - p.
y() * nx - s1.
x() * ny + s1.
y() * nx ) / (( s2.
x() - s1.
x() ) * ny - ( s2.
y() - s1.
y() ) * nx );
83 return t < 0. ? s1 : t > 1. ? s2 :
QgsPointV2( s1.
x() + ( s2.
x() - s1.
x() ) * t, s1.
y() + ( s2.
y() - s1.
y() ) * t );
105 static double leftOfLine(
double x,
double y,
double x1,
double y1,
double x2,
double y2 );
112 static double ccwAngle(
double dy,
double dx );
116 double& centerX,
double& centerY );
119 static bool circleClockwise(
double angle1,
double angle2,
double angle3 );
122 static bool circleAngleBetween(
double angle,
double angle1,
double angle2,
bool clockwise );
127 static bool angleOnCircle(
double angle,
double angle1,
double angle2,
double angle3 );
130 static double circleLength(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
133 static double sweepAngle(
double centerX,
double centerY,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
155 static double lineAngle(
double x1,
double y1,
double x2,
double y2 );
157 static double linePerpendicularAngle(
double x1,
double y1,
double x2,
double y2 );
159 static double averageAngle(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
161 static double averageAngle(
double a1,
double a2 );
185 double minDistSegmentX = 0.0, minDistSegmentY = 0.0;
187 bool minDistLeftOf =
false;
188 double sqrDist = 0.0;
189 int vertexOffset = 0;
193 for (
int i = 0; i < container.size(); ++i )
195 sqrDist = container.at( i )->closestSegment( pt, segmentPt, vertexAfter, leftOf, epsilon );
196 if ( sqrDist < minDist )
199 minDistSegmentX = segmentPt.
x();
200 minDistSegmentY = segmentPt.
y();
201 minDistVertexAfter = vertexAfter;
202 minDistVertexAfter.
vertex = vertexAfter.
vertex + vertexOffset;
203 minDistVertexAfter.
part = vertexAfter.
part + partOffset;
204 minDistVertexAfter.
ring = vertexAfter.
ring + ringOffset;
211 if ( ctype == VERTEX )
214 vertexOffset += container.at( i )->nCoordinates() - 1;
216 else if ( ctype == RING )
220 else if ( ctype == PART )
226 segmentPt.
setX( minDistSegmentX );
227 segmentPt.
setY( minDistSegmentY );
228 vertexAfter = minDistVertexAfter;
231 *leftOf = minDistLeftOf;
237 #endif // QGSGEOMETRYUTILS_H
Abstract base class for all geometries.
static double closestSegmentFromComponents(T &container, componentType ctype, const QgsPointV2 &pt, QgsPointV2 &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon)
static QgsPointV2 projPointOnSegment(const QgsPointV2 &p, const QgsPointV2 &s1, const QgsPointV2 &s2)
Project the point on a segment.
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
Contains various geometry utility functions.
Utility class for identifying a unique vertex within a geometry.
bool ANALYSIS_EXPORT lineIntersection(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Returns true, if line1 (p1 to p2) and line2 (p3 to p4) intersect.
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
A class to represent a vector.
double ANALYSIS_EXPORT leftOf(Point3D *thepoint, Point3D *p1, Point3D *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'.