23 #include <QTextStream> 42 return QPointF( mX, mY );
50 QTextStream ot( &rep );
51 ot.setRealNumberPrecision( 12 );
52 ot << mX <<
", " << mY;
57 QString
x = std::isfinite( mX ) ? QString::number( mX,
'f', precision ) : QObject::tr(
"infinite" );
58 QString
y = std::isfinite( mY ) ? QString::number( mY,
'f', precision ) : QObject::tr(
"infinite" );
59 return QStringLiteral(
"%1,%2" ).arg( x, y );
70 return ( mX - x ) * ( mX -
x ) + ( mY - y ) * ( mY -
y );
80 return std::sqrt(
sqrDist( x, y ) );
85 return std::sqrt(
sqrDist( other ) );
90 double dx = other.
x() - mX;
91 double dy = other.
y() - mY;
92 return ( std::atan2( dx, dy ) * 180.0 / M_PI );
97 double rads = bearing * M_PI / 180.0;
98 double dx = distance * std::sin( rads );
99 double dy = distance * std::cos( rads );
121 if ( &other !=
this )
144 t = ( mX * ny - mY * nx - x1 * ny + y1 * nx ) / ( ( x2 - x1 ) * ny - ( y2 - y1 ) * nx );
148 minDistPoint.
setX( x1 );
149 minDistPoint.
setY( y1 );
153 minDistPoint.
setX( x2 );
154 minDistPoint.
setY( y2 );
158 minDistPoint.
setX( x1 + t * ( x2 - x1 ) );
159 minDistPoint.
setY( y1 + t * ( y2 - y1 ) );
162 double dist =
sqrDist( minDistPoint );
166 minDistPoint.
setX( mX );
167 minDistPoint.
setY( mY );
A class to represent a 2D point.
bool operator==(const QgsPointXY &other)
equality operator
QString toString(int precision=-1) const
Returns a string representation of the point (x, y) with a preset precision.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
double azimuth(const QgsPointXY &other) const
Calculates azimuth between this point and other one (clockwise in degree, starting from north) ...
double sqrDist(double x, double y) const
Returns the squared distance between this point a specified x, y coordinate.
bool compare(const QgsPointXY &other, double epsilon=4 *DBL_EPSILON) const
Compares this point with another point with a fuzzy tolerance.
QgsPointXY & operator=(const QgsPointXY &other)
Assignment.
bool operator!=(const QgsPointXY &other) const
Inequality operator.
QPointF toQPointF() const
Converts a point to a QPointF.
double sqrDistToSegment(double x1, double y1, double x2, double y2, QgsPointXY &minDistPoint, double epsilon=DEFAULT_SEGMENT_EPSILON) const
Returns the minimum distance between this point and a segment.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
void setY(double y)
Sets the y value of the point.
double x() const
Get the x value of the point.
void multiply(double scalar)
Multiply x and y by the given value.
QgsPointXY project(double distance, double bearing) const
Returns a new point which corresponds to this point projected by a specified distance in a specified ...
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
Point geometry type, with support for z-dimension and m-values.
void setX(double x)
Sets the x value of the point.
QgsPointXY()=default
Default constructor.
double y() const
Get the y value of the point.
QString asWkt() const
Return the well known text representation for the point (e.g.