16 #ifndef QGSGEOMETRYUTILS_H 17 #define QGSGEOMETRYUTILS_H 54 static double sqrDistToLine(
double ptX,
double ptY,
double x1,
double y1,
double x2,
double y2,
double& minDistX,
double& minDistY,
double epsilon );
88 double nx = s2.
y() - s1.
y();
89 double ny = -( s2.
x() - s1.
x() );
90 double t = ( p.
x() * ny - p.
y() * nx - s1.
x() * ny + s1.
y() * nx ) / (( s2.
x() - s1.
x() ) * ny - ( s2.
y() - s1.
y() ) * nx );
91 return t < 0. ? s1 : t > 1. ? s2 :
QgsPointV2( s1.
x() + ( s2.
x() - s1.
x() ) * t, s1.
y() + ( s2.
y() - s1.
y() ) * t );
113 static double leftOfLine(
double x,
double y,
double x1,
double y1,
double x2,
double y2 );
120 static double ccwAngle(
double dy,
double dx );
124 double& centerX,
double& centerY );
127 static bool circleClockwise(
double angle1,
double angle2,
double angle3 );
130 static bool circleAngleBetween(
double angle,
double angle1,
double angle2,
bool clockwise );
135 static bool angleOnCircle(
double angle,
double angle1,
double angle2,
double angle3 );
138 static double circleLength(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
141 static double sweepAngle(
double centerX,
double centerY,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
167 static double normalizedAngle(
double angle );
176 static double lineAngle(
double x1,
double y1,
double x2,
double y2 );
186 static double linePerpendicularAngle(
double x1,
double y1,
double x2,
double y2 );
189 static double averageAngle(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3 );
196 static double averageAngle(
double a1,
double a2 );
219 double minDistSegmentX = 0.0, minDistSegmentY = 0.0;
221 bool minDistLeftOf =
false;
222 double sqrDist = 0.0;
223 int vertexOffset = 0;
227 for (
int i = 0; i < container.size(); ++i )
229 sqrDist = container.at( i )->closestSegment( pt, segmentPt, vertexAfter, leftOf, epsilon );
230 if ( sqrDist < minDist )
233 minDistSegmentX = segmentPt.
x();
234 minDistSegmentY = segmentPt.
y();
235 minDistVertexAfter = vertexAfter;
236 minDistVertexAfter.
vertex = vertexAfter.
vertex + vertexOffset;
237 minDistVertexAfter.
part = vertexAfter.
part + partOffset;
238 minDistVertexAfter.
ring = vertexAfter.
ring + ringOffset;
245 if ( ctype == VERTEX )
248 vertexOffset += container.at( i )->nCoordinates() - 1;
250 else if ( ctype == RING )
254 else if ( ctype == PART )
260 segmentPt.
setX( minDistSegmentX );
261 segmentPt.
setY( minDistSegmentY );
262 vertexAfter = minDistVertexAfter;
265 *leftOf = minDistLeftOf;
271 #endif // QGSGEOMETRYUTILS_H
double x() const
Returns the point's x-coordinate.
Abstract base class for all geometries.
void setX(double x)
Sets the point's x-coordinate.
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.
void setY(double y)
Sets the point's y-coordinate.
double y() const
Returns the point's y-coordinate.
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.
Line string geometry type, with support for z-dimension and m-values.
Point geometry type, with support for z-dimension and m-values.
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'.