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" );
123 return QPointF( m_x, m_y );
129 QTextStream ot( &rep );
130 ot.setRealNumberPrecision( 12 );
131 ot << m_x <<
", " << m_y;
137 QString
x = qIsFinite( m_x ) ? QString::number( m_x,
'f', thePrecision ) :
QObject::tr(
"infinite" );
138 QString
y = qIsFinite( m_y ) ? QString::number( m_y,
'f', thePrecision ) :
QObject::tr(
"infinite" );
139 return QString(
"%1,%2" ).arg( x ).arg( 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 )
200 QString myXHemisphere;
201 QString myYHemisphere;
211 if ( myWrappedX < 0 )
215 if ( myWrappedY < 0 )
222 if ( myDegreesX == 0 && myIntMinutesX == 0 && qRound( mySecondsX * pow( 10.0, thePrecision ) ) == 0 )
225 myXHemisphere = QString();
227 if ( myDegreesY == 0 && myIntMinutesY == 0 && qRound( mySecondsY * pow( 10.0, thePrecision ) ) == 0 )
230 myYHemisphere = QString();
233 if ( myDegreesX == 180 && myIntMinutesX == 0 && qRound( mySecondsX * pow( 10.0, thePrecision ) ) == 0 )
235 myXHemisphere = QString();
238 QString myMinutesX = padded ? QString(
"%1" ).arg( myIntMinutesX, 2, 10, QChar(
'0' ) ) : QString::number( myIntMinutesX );
239 QString myMinutesY = padded ? QString(
"%1" ).arg( myIntMinutesY, 2, 10, QChar(
'0' ) ) : QString::number( myIntMinutesY );
241 int digits = 2 + ( thePrecision == 0 ? 0 : 1 + thePrecision );
242 QString myStrSecondsX = padded ? QString(
"%1" ).arg( mySecondsX, digits,
'f', thePrecision, QChar(
'0' ) ) : QString::number( mySecondsX,
'f', thePrecision );
243 QString myStrSecondsY = padded ? QString(
"%1" ).arg( mySecondsY, digits,
'f', thePrecision, QChar(
'0' ) ) : QString::number( mySecondsY,
'f', thePrecision );
245 QString rep = myXSign + QString::number( myDegreesX ) + QChar( 176 ) +
246 myMinutesX + QChar( 0x2032 ) +
247 myStrSecondsX + QChar( 0x2033 ) +
248 myXHemisphere + QString(
"," ) +
249 myYSign + QString::number( myDegreesY ) + QChar( 176 ) +
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 );
288 QString myXHemisphere;
289 QString myYHemisphere;
299 if ( myWrappedX < 0 )
310 if ( myDegreesX == 0 && qRound( myFloatMinutesX * pow( 10.0, thePrecision ) ) == 0 )
313 myXHemisphere = QString();
315 if ( myDegreesY == 0 && qRound( myFloatMinutesY * pow( 10.0, thePrecision ) ) == 0 )
318 myYHemisphere = QString();
321 if ( myDegreesX == 180 && qRound( myFloatMinutesX * pow( 10.0, thePrecision ) ) == 0 )
323 myXHemisphere = QString();
327 int digits = 2 + ( thePrecision == 0 ? 0 : 1 + thePrecision );
328 QString myStrMinutesX = padded ? QString(
"%1" ).arg( myFloatMinutesX, digits,
'f', thePrecision, QChar(
'0' ) ) : QString::number( myFloatMinutesX,
'f', thePrecision );
329 QString myStrMinutesY = padded ? QString(
"%1" ).arg( myFloatMinutesY, digits,
'f', thePrecision, QChar(
'0' ) ) : QString::number( myFloatMinutesY,
'f', thePrecision );
331 QString rep = myXSign + QString::number( myDegreesX ) + QChar( 176 ) +
332 myStrMinutesX + QChar( 0x2032 ) +
333 myXHemisphere + QString(
"," ) +
334 myYSign + QString::number( myDegreesY ) + QChar( 176 ) +
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 );
365 if (( m_x == other.
x() ) && ( m_y == other.
y() ) )
373 if (( m_x == other.
x() ) && ( m_y == other.
y() ) )
381 if ( &other !=
this )
400 qAbs(( b.
y() - a.
y() ) *( m_x - a.
x() ) - ( m_y - a.
y() ) *( b.
x() - a.
x() ) )
401 >= qMax( qAbs( b.
x() - a.
x() ), qAbs( b.
y() - a.
y() ) )
406 if (( b.
x() < a.
x() && a.
x() < m_x ) || ( b.
y() < a.
y() && a.
y() < m_y ) )
410 if (( m_x < a.
x() && a.
x() < b.
x() ) || ( m_y < a.
y() && a.
y() < b.
y() ) )
414 if (( a.
x() < b.
x() && b.
x() < m_x ) || ( a.
y() < b.
y() && b.
y() < m_y ) )
418 if (( m_x < b.
x() && b.
x() < a.
x() ) || ( m_y < b.
y() && b.
y() < a.
y() ) )
434 t = ( m_x * ny - m_y * nx - x1 * ny + y1 * nx ) / (( x2 - x1 ) * ny - ( y2 - y1 ) * nx );
438 minDistPoint.
setX( x1 );
439 minDistPoint.
setY( y1 );
443 minDistPoint.
setX( x2 );
444 minDistPoint.
setY( y2 );
448 minDistPoint.
setX( x1 + t *( x2 - x1 ) );
449 minDistPoint.
setY( y1 + t *( y2 - y1 ) );
452 double dist = sqrDist( minDistPoint );
456 minDistPoint.
setX( m_x );
457 minDistPoint.
setY( m_y );
QgsVector rotateBy(double rot) const
int onSegment(const QgsPoint &a, const QgsPoint &b) const
Test if this point is on the segment defined by points a, b.
QgsVector operator-(void) const
QgsPoint & operator=(const QgsPoint &other)
Assignment.
double sqrDist(double x, double y) const
Returns the squared distance between this point and x,y.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
bool operator!=(const QgsPoint &other) const
Inequality operator.
QgsPoint()
Default constructor.
QgsVector perpVector() const
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 operator==(const QgsPoint &other)
equality operator
QString toString() const
String representation of the point (x,y)
A class to represent a point.
double azimuth(const QgsPoint &other)
Calculates azimuth between this point and other one (clockwise in degree, starting from north) ...
A class to represent a vector.
QString qgsDoubleToString(const double &a, const int &precision=17)
QString toDegreesMinutes(int thePrecision, const bool useSuffix=true, const bool padded=false) const
Return a string representation as degrees minutes.
QgsVector operator*(double scalar) const
QString toDegreesMinutesSeconds(int thePrecision, const bool useSuffix=true, const bool padded=false) const
Return a string representation as degrees minutes seconds.
QgsVector operator/(double scalar) const
Defines a qgis exception class.
QString wellKnownText() const
void multiply(const double &scalar)
Multiply x and y by the given value.
QPointF toQPointF() const
Converts a point to a QPointF.