22 #include <QTextStream> 46 return QgsVector( m_x * scalar, m_y * scalar );
51 return *
this * ( 1.0 / scalar );
56 return m_x * v.m_x + m_y * v.m_y;
61 return sqrt( m_x * m_x + m_y * m_y );
82 double ang = atan2( m_y, m_x );
83 return ang < 0.0 ? ang + 2.0 *
M_PI : ang;
93 double ang = atan2( m_y, m_x ) + rot;
95 return QgsVector( len * cos( ang ), len * sin( ang ) );
104 throw QgsException(
"normal vector of null vector undefined" );
131 ot << m_x <<
", " << m_y;
145 double myWrappedX = fmod( m_x, 360.0 );
147 if ( myWrappedX > 180.0 )
149 myWrappedX = myWrappedX - 360.0;
151 else if ( myWrappedX < -180.0 )
153 myWrappedX = myWrappedX + 360.0;
157 double myWrappedY = fmod( m_y, 180.0 );
159 if ( myWrappedY > 90.0 )
161 myWrappedY = myWrappedY - 180.0;
163 else if ( myWrappedY < -90.0 )
165 myWrappedY = myWrappedY + 180.0;
168 int myDegreesX = int( qAbs( myWrappedX ) );
169 double myFloatMinutesX = double(( qAbs( myWrappedX ) - myDegreesX ) * 60 );
170 int myIntMinutesX = int( myFloatMinutesX );
171 double mySecondsX = double( myFloatMinutesX - myIntMinutesX ) * 60;
173 int myDegreesY = int( qAbs( myWrappedY ) );
174 double myFloatMinutesY = double(( qAbs( myWrappedY ) - myDegreesY ) * 60 );
175 int myIntMinutesY = int( myFloatMinutesY );
176 double mySecondsY = double( myFloatMinutesY - myIntMinutesY ) * 60;
179 if ( qRound( mySecondsX * pow( 10.0, thePrecision ) ) >= 60 * pow( 10.0, thePrecision ) )
181 mySecondsX = qMax( mySecondsX - 60, 0.0 );
183 if ( myIntMinutesX >= 60 )
189 if ( qRound( mySecondsY * pow( 10.0, thePrecision ) ) >= 60 * pow( 10.0, thePrecision ) )
191 mySecondsY = qMax( mySecondsY - 60, 0.0 );
193 if ( myIntMinutesY >= 60 )
211 if ( myWrappedX < 0 )
215 if ( myWrappedY < 0 )
222 if ( myDegreesX == 0 && myIntMinutesX == 0 && qRound( mySecondsX * pow( 10.0, thePrecision ) ) == 0 )
227 if ( myDegreesY == 0 && myIntMinutesY == 0 && qRound( mySecondsY * pow( 10.0, thePrecision ) ) == 0 )
233 if ( myDegreesX == 180 && myIntMinutesX == 0 && qRound( mySecondsX * pow( 10.0, thePrecision ) ) == 0 )
241 int digits = 2 + ( thePrecision == 0 ? 0 : 1 + thePrecision );
246 myMinutesX +
QChar( 0x2032 ) +
247 myStrSecondsX +
QChar( 0x2033 ) +
248 myXHemisphere +
',' +
250 myMinutesY +
QChar( 0x2032 ) +
251 myStrSecondsY +
QChar( 0x2033 ) +
259 double myWrappedX = fmod( m_x, 360.0 );
261 if ( myWrappedX > 180.0 )
263 myWrappedX = myWrappedX - 360.0;
265 else if ( myWrappedX < -180.0 )
267 myWrappedX = myWrappedX + 360.0;
270 int myDegreesX = int( qAbs( myWrappedX ) );
271 double myFloatMinutesX = double(( qAbs( myWrappedX ) - myDegreesX ) * 60 );
273 int myDegreesY = int( qAbs( m_y ) );
274 double myFloatMinutesY = double(( qAbs( m_y ) - myDegreesY ) * 60 );
277 if ( qRound( myFloatMinutesX * pow( 10.0, thePrecision ) ) >= 60 * pow( 10.0, thePrecision ) )
279 myFloatMinutesX = qMax( myFloatMinutesX - 60, 0.0 );
282 if ( qRound( myFloatMinutesY * pow( 10.0, thePrecision ) ) >= 60 * pow( 10.0, thePrecision ) )
284 myFloatMinutesY = qMax( myFloatMinutesY - 60, 0.0 );
299 if ( myWrappedX < 0 )
310 if ( myDegreesX == 0 && qRound( myFloatMinutesX * pow( 10.0, thePrecision ) ) == 0 )
315 if ( myDegreesY == 0 && qRound( myFloatMinutesY * pow( 10.0, thePrecision ) ) == 0 )
321 if ( myDegreesX == 180 && qRound( myFloatMinutesX * pow( 10.0, thePrecision ) ) == 0 )
327 int digits = 2 + ( thePrecision == 0 ? 0 : 1 + thePrecision );
332 myStrMinutesX +
QChar( 0x2032 ) +
333 myXHemisphere +
',' +
335 myStrMinutesY +
QChar( 0x2032 ) +
347 return ( m_x - x ) * ( m_x -
x ) + ( m_y - y ) * ( m_y -
y );
352 return sqrDist( other.
x(), other.
y() );
357 double dx = other.
x() - m_x;
358 double dy = other.
y() - m_y;
359 return ( atan2( dx, dy ) * 180.0 /
M_PI );
386 if ( &other !=
this )
405 qAbs(( b.
y() - a.
y() ) *( m_x - a.
x() ) - ( m_y - a.
y() ) *( b.
x() - a.
x() ) )
406 >= qMax( qAbs( b.
x() - a.
x() ), qAbs( b.
y() - a.
y() ) )
411 if (( b.
x() < a.
x() && a.
x() < m_x ) || ( b.
y() < a.
y() && a.
y() < m_y ) )
415 if (( m_x < a.
x() && a.
x() < b.
x() ) || ( m_y < a.
y() && a.
y() < b.
y() ) )
419 if (( a.
x() < b.
x() && b.
x() < m_x ) || ( a.
y() < b.
y() && b.
y() < m_y ) )
423 if (( m_x < b.
x() && b.
x() < a.
x() ) || ( m_y < b.
y() && b.
y() < a.
y() ) )
439 t = ( m_x * ny - m_y * nx - x1 * ny + y1 * nx ) / (( x2 - x1 ) * ny - ( y2 - y1 ) * nx );
443 minDistPoint.
setX( x1 );
444 minDistPoint.
setY( y1 );
448 minDistPoint.
setX( x2 );
449 minDistPoint.
setY( y2 );
453 minDistPoint.
setX( x1 + t *( x2 - x1 ) );
454 minDistPoint.
setY( y1 + t *( y2 - y1 ) );
457 double dist = sqrDist( minDistPoint );
461 minDistPoint.
setX( m_x );
462 minDistPoint.
setY( m_y );
QPointF toQPointF() const
Converts a point to a QPointF.
void setRealNumberPrecision(int precision)
void multiply(double scalar)
Multiply x and y by the given value.
double azimuth(const QgsPoint &other) const
Calculates azimuth between this point and other one (clockwise in degree, starting from north) ...
QgsPoint & operator=(const QgsPoint &other)
Assignment.
QString toDegreesMinutes(int thePrecision, const bool useSuffix=true, const bool padded=false) const
Return a string representation as degrees minutes.
QString tr(const char *sourceText, const char *disambiguation, int n)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
double y() const
Get the y value of the point.
QgsPoint()
Default constructor.
QString number(int n, int base)
double sqrDistToSegment(double x1, double y1, double x2, double y2, QgsPoint &minDistPoint, double epsilon=DEFAULT_SEGMENT_EPSILON) const
Returns the minimum distance between this point and a segment.
bool compare(const QgsPoint &other, double epsilon=4 *DBL_EPSILON) const
Compares this point with another point with a fuzzy tolerance.
QString qgsDoubleToString(double a, int precision=17)
bool operator==(const QgsPoint &other)
equality operator
QString toDegreesMinutesSeconds(int thePrecision, const bool useSuffix=true, const bool padded=false) const
Return a string representation as degrees minutes seconds.
A class to represent a point.
QgsVector operator/(double scalar) const
QString toString() const
String representation of the point (x,y)
A class to represent a vector.
void setX(double x)
Sets the x value of the point.
void setY(double y)
Sets the y value of the point.
QString wellKnownText() const
Return the well known text representation for the point.
QgsVector perpVector() const
QgsVector operator-(void) const
QgsVector operator*(double scalar) const
double sqrDist(double x, double y) const
Returns the squared distance between this point and x,y.
QgsVector rotateBy(double rot) const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Defines a qgis exception class.
double x() const
Get the x value of the point.
bool operator!=(const QgsPoint &other) const
Inequality operator.
int onSegment(const QgsPoint &a, const QgsPoint &b) const
Test if this point is on the segment defined by points a, b.