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;
156 int myDegreesX = int( qAbs( myWrappedX ) );
157 double myFloatMinutesX = double(( qAbs( myWrappedX ) - myDegreesX ) * 60 );
158 int myIntMinutesX = int( myFloatMinutesX );
159 double mySecondsX = double( myFloatMinutesX - myIntMinutesX ) * 60;
161 int myDegreesY = int( qAbs( m_y ) );
162 double myFloatMinutesY = double(( qAbs( m_y ) - myDegreesY ) * 60 );
163 int myIntMinutesY = int( myFloatMinutesY );
164 double mySecondsY = double( myFloatMinutesY - myIntMinutesY ) * 60;
167 if ( qRound( mySecondsX * pow( 10.0, thePrecision ) ) >= 60 * pow( 10.0, thePrecision ) )
169 mySecondsX = qMax( mySecondsX - 60, 0.0 );
171 if ( myIntMinutesX >= 60 )
177 if ( qRound( mySecondsY * pow( 10.0, thePrecision ) ) >= 60 * pow( 10.0, thePrecision ) )
179 mySecondsY = qMax( mySecondsY - 60, 0.0 );
181 if ( myIntMinutesY >= 60 )
188 QString myXHemisphere;
189 QString myYHemisphere;
199 if ( myWrappedX < 0 )
210 if ( myDegreesX == 0 && myIntMinutesX == 0 && qRound( mySecondsX * pow( 10.0, thePrecision ) ) == 0 )
213 myXHemisphere = QString();
215 if ( myDegreesY == 0 && myIntMinutesY == 0 && qRound( mySecondsY * pow( 10.0, thePrecision ) ) == 0 )
218 myYHemisphere = QString();
221 if ( myDegreesX == 180 && myIntMinutesX == 0 && qRound( mySecondsX * pow( 10.0, thePrecision ) ) == 0 )
223 myXHemisphere = QString();
226 QString myMinutesX = padded ? QString(
"%1" ).arg( myIntMinutesX, 2, 10, QChar(
'0' ) ) : QString::number( myIntMinutesX );
227 QString myMinutesY = padded ? QString(
"%1" ).arg( myIntMinutesY, 2, 10, QChar(
'0' ) ) : QString::number( myIntMinutesY );
229 int digits = 2 + ( thePrecision == 0 ? 0 : 1 + thePrecision );
230 QString myStrSecondsX = padded ? QString(
"%1" ).arg( mySecondsX, digits,
'f', thePrecision, QChar(
'0' ) ) : QString::number( mySecondsX,
'f', thePrecision );
231 QString myStrSecondsY = padded ? QString(
"%1" ).arg( mySecondsY, digits,
'f', thePrecision, QChar(
'0' ) ) : QString::number( mySecondsY,
'f', thePrecision );
233 QString rep = myXSign + QString::number( myDegreesX ) + QChar( 176 ) +
234 myMinutesX + QChar( 0x2032 ) +
235 myStrSecondsX + QChar( 0x2033 ) +
236 myXHemisphere + QString(
"," ) +
237 myYSign + QString::number( myDegreesY ) + QChar( 176 ) +
238 myMinutesY + QChar( 0x2032 ) +
239 myStrSecondsY + QChar( 0x2033 ) +
247 double myWrappedX = fmod( m_x, 360.0 );
249 if ( myWrappedX > 180.0 )
251 myWrappedX = myWrappedX - 360.0;
253 else if ( myWrappedX < -180.0 )
255 myWrappedX = myWrappedX + 360.0;
258 int myDegreesX = int( qAbs( myWrappedX ) );
259 double myFloatMinutesX = double(( qAbs( myWrappedX ) - myDegreesX ) * 60 );
261 int myDegreesY = int( qAbs( m_y ) );
262 double myFloatMinutesY = double(( qAbs( m_y ) - myDegreesY ) * 60 );
265 if ( qRound( myFloatMinutesX * pow( 10.0, thePrecision ) ) >= 60 * pow( 10.0, thePrecision ) )
267 myFloatMinutesX = qMax( myFloatMinutesX - 60, 0.0 );
270 if ( qRound( myFloatMinutesY * pow( 10.0, thePrecision ) ) >= 60 * pow( 10.0, thePrecision ) )
272 myFloatMinutesY = qMax( myFloatMinutesY - 60, 0.0 );
276 QString myXHemisphere;
277 QString myYHemisphere;
287 if ( myWrappedX < 0 )
298 if ( myDegreesX == 0 && qRound( myFloatMinutesX * pow( 10.0, thePrecision ) ) == 0 )
301 myXHemisphere = QString();
303 if ( myDegreesY == 0 && qRound( myFloatMinutesY * pow( 10.0, thePrecision ) ) == 0 )
306 myYHemisphere = QString();
309 if ( myDegreesX == 180 && qRound( myFloatMinutesX * pow( 10.0, thePrecision ) ) == 0 )
311 myXHemisphere = QString();
315 int digits = 2 + ( thePrecision == 0 ? 0 : 1 + thePrecision );
316 QString myStrMinutesX = padded ? QString(
"%1" ).arg( myFloatMinutesX, digits,
'f', thePrecision, QChar(
'0' ) ) : QString::number( myFloatMinutesX,
'f', thePrecision );
317 QString myStrMinutesY = padded ? QString(
"%1" ).arg( myFloatMinutesY, digits,
'f', thePrecision, QChar(
'0' ) ) : QString::number( myFloatMinutesY,
'f', thePrecision );
319 QString rep = myXSign + QString::number( myDegreesX ) + QChar( 176 ) +
320 myStrMinutesX + QChar( 0x2032 ) +
321 myXHemisphere + QString(
"," ) +
322 myYSign + QString::number( myDegreesY ) + QChar( 176 ) +
323 myStrMinutesY + QChar( 0x2032 ) +
335 return ( m_x - x ) * ( m_x -
x ) + ( m_y - y ) * ( m_y -
y );
345 double dx = other.
x() - m_x;
346 double dy = other.
y() - m_y;
347 return ( atan2( dx, dy ) * 180.0 /
M_PI );
353 if (( m_x == other.
x() ) && ( m_y == other.
y() ) )
361 if (( m_x == other.
x() ) && ( m_y == other.
y() ) )
369 if ( &other !=
this )
388 qAbs(( b.
y() - a.
y() ) *( m_x - a.
x() ) - ( m_y - a.
y() ) *( b.
x() - a.
x() ) )
389 >= qMax( qAbs( b.
x() - a.
x() ), qAbs( b.
y() - a.
y() ) )
394 if (( b.
x() < a.
x() && a.
x() < m_x ) || ( b.
y() < a.
y() && a.
y() < m_y ) )
398 if (( m_x < a.
x() && a.
x() < b.
x() ) || ( m_y < a.
y() && a.
y() < b.
y() ) )
402 if (( a.
x() < b.
x() && b.
x() < m_x ) || ( a.
y() < b.
y() && b.
y() < m_y ) )
406 if (( m_x < b.
x() && b.
x() < a.
x() ) || ( m_y < b.
y() && b.
y() < a.
y() ) )
422 t = ( m_x * ny - m_y * nx - x1 * ny + y1 * nx ) / (( x2 - x1 ) * ny - ( y2 - y1 ) * nx );
426 minDistPoint.
setX( x1 );
427 minDistPoint.
setY( y1 );
431 minDistPoint.
setX( x2 );
432 minDistPoint.
setY( y2 );
436 minDistPoint.
setX( x1 + t *( x2 - x1 ) );
437 minDistPoint.
setY( y1 + t *( y2 - y1 ) );
440 double dist =
sqrDist( minDistPoint );
444 minDistPoint.
setX( m_x );
445 minDistPoint.
setY( m_y );