mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Add methods for converting QgsPoint to and from QPointF and QPoint
Also add some more basic unit tests for QgsPoint
This commit is contained in:
parent
a987525ac9
commit
b5c9df0e61
@ -23,6 +23,18 @@ class QgsPoint
|
|||||||
*/
|
*/
|
||||||
QgsPoint( double x, double y );
|
QgsPoint( double x, double y );
|
||||||
|
|
||||||
|
/*! Create a point from a QPointF
|
||||||
|
* @param point QPointF source
|
||||||
|
* @note added in QGIS 2.7
|
||||||
|
*/
|
||||||
|
QgsPoint( const QPointF& point );
|
||||||
|
|
||||||
|
/*! Create a point from a QPoint
|
||||||
|
* @param point QPoint source
|
||||||
|
* @note added in QGIS 2.7
|
||||||
|
*/
|
||||||
|
QgsPoint( const QPoint& point );
|
||||||
|
|
||||||
~QgsPoint();
|
~QgsPoint();
|
||||||
|
|
||||||
/*! Sets the x value of the point
|
/*! Sets the x value of the point
|
||||||
@ -48,6 +60,12 @@ class QgsPoint
|
|||||||
*/
|
*/
|
||||||
double y() const;
|
double y() const;
|
||||||
|
|
||||||
|
/** Converts a point to a QPointF
|
||||||
|
* @returns QPointF with same x and y values
|
||||||
|
* @note added in QGIS 2.7
|
||||||
|
*/
|
||||||
|
QPointF toQPointF() const;
|
||||||
|
|
||||||
//! String representation of the point (x,y)
|
//! String representation of the point (x,y)
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
|
|
||||||
@ -95,7 +113,7 @@ class QgsPoint
|
|||||||
@note added in QGIS 1.5*/
|
@note added in QGIS 1.5*/
|
||||||
double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint& minDistPoint /Out/, double epsilon = DEFAULT_SEGMENT_EPSILON ) const;
|
double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint& minDistPoint /Out/, double epsilon = DEFAULT_SEGMENT_EPSILON ) const;
|
||||||
|
|
||||||
/**Calculates azimut between this point and other one (clockwise in degree, starting from north)
|
/**Calculates azimuth between this point and other one (clockwise in degree, starting from north)
|
||||||
@note: this function has been added in version 1.7*/
|
@note: this function has been added in version 1.7*/
|
||||||
double azimuth( const QgsPoint& other );
|
double azimuth( const QgsPoint& other );
|
||||||
|
|
||||||
|
@ -118,6 +118,11 @@ QgsPoint::QgsPoint( const QgsPoint& p )
|
|||||||
m_y = p.y();
|
m_y = p.y();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPointF QgsPoint::toQPointF() const
|
||||||
|
{
|
||||||
|
return QPointF( m_x, m_y );
|
||||||
|
}
|
||||||
|
|
||||||
QString QgsPoint::toString() const
|
QString QgsPoint::toString() const
|
||||||
{
|
{
|
||||||
QString rep;
|
QString rep;
|
||||||
|
@ -78,6 +78,22 @@ class CORE_EXPORT QgsPoint
|
|||||||
: m_x( x ), m_y( y )
|
: m_x( x ), m_y( y )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/*! Create a point from a QPointF
|
||||||
|
* @param point QPointF source
|
||||||
|
* @note added in QGIS 2.7
|
||||||
|
*/
|
||||||
|
QgsPoint( const QPointF& point )
|
||||||
|
: m_x( point.x() ), m_y( point.y() )
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*! Create a point from a QPoint
|
||||||
|
* @param point QPoint source
|
||||||
|
* @note added in QGIS 2.7
|
||||||
|
*/
|
||||||
|
QgsPoint( const QPoint& point )
|
||||||
|
: m_x( point.x() ), m_y( point.y() )
|
||||||
|
{}
|
||||||
|
|
||||||
~QgsPoint()
|
~QgsPoint()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -120,6 +136,12 @@ class CORE_EXPORT QgsPoint
|
|||||||
return m_y;
|
return m_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Converts a point to a QPointF
|
||||||
|
* @returns QPointF with same x and y values
|
||||||
|
* @note added in QGIS 2.7
|
||||||
|
*/
|
||||||
|
QPointF toQPointF() const;
|
||||||
|
|
||||||
//! String representation of the point (x,y)
|
//! String representation of the point (x,y)
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
|
|
||||||
@ -164,7 +186,7 @@ class CORE_EXPORT QgsPoint
|
|||||||
/**Returns the minimum distance between this point and a segment */
|
/**Returns the minimum distance between this point and a segment */
|
||||||
double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint& minDistPoint, double epsilon = DEFAULT_SEGMENT_EPSILON ) const;
|
double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint& minDistPoint, double epsilon = DEFAULT_SEGMENT_EPSILON ) const;
|
||||||
|
|
||||||
/**Calculates azimut between this point and other one (clockwise in degree, starting from north) */
|
/**Calculates azimuth between this point and other one (clockwise in degree, starting from north) */
|
||||||
double azimuth( const QgsPoint& other );
|
double azimuth( const QgsPoint& other );
|
||||||
|
|
||||||
//! equality operator
|
//! equality operator
|
||||||
|
@ -36,6 +36,10 @@ class TestQgsPoint: public QObject
|
|||||||
void cleanupTestCase();// will be called after the last testfunction was executed.
|
void cleanupTestCase();// will be called after the last testfunction was executed.
|
||||||
void init();// will be called before each testfunction is executed.
|
void init();// will be called before each testfunction is executed.
|
||||||
void cleanup();// will be called after every testfunction.
|
void cleanup();// will be called after every testfunction.
|
||||||
|
void equality();
|
||||||
|
void gettersSetters();
|
||||||
|
void constructors();
|
||||||
|
void toQPointF();
|
||||||
void toString();
|
void toString();
|
||||||
void toDegreesMinutesSeconds();
|
void toDegreesMinutesSeconds();
|
||||||
void toDegreesMinutesSecondsNoSuffix();
|
void toDegreesMinutesSecondsNoSuffix();
|
||||||
@ -71,6 +75,60 @@ void TestQgsPoint::cleanup()
|
|||||||
// will be called after every testfunction.
|
// will be called after every testfunction.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestQgsPoint::equality()
|
||||||
|
{
|
||||||
|
QgsPoint point1( 5.0, 9.0 );
|
||||||
|
QgsPoint point2( 5.0, 9.0 );
|
||||||
|
QCOMPARE( point1, point2 );
|
||||||
|
QgsPoint point3( 5.0, 6.0 );
|
||||||
|
QVERIFY( !( point3 == point1 ) );
|
||||||
|
QVERIFY( point3 != point1 );
|
||||||
|
QgsPoint point4( 8.0, 9.0 );
|
||||||
|
QVERIFY( !( point4 == point1 ) );
|
||||||
|
QVERIFY( point4 != point1 );
|
||||||
|
QVERIFY( !( point4 == point3 ) );
|
||||||
|
QVERIFY( point4 != point3 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestQgsPoint::gettersSetters()
|
||||||
|
{
|
||||||
|
QgsPoint point;
|
||||||
|
point.setX( 1.0 );
|
||||||
|
QCOMPARE( point.x(), 1.0 );
|
||||||
|
point.setY( 2.0 );
|
||||||
|
QCOMPARE( point.y(), 2.0 );
|
||||||
|
point.set( 3.0, 4.0 );
|
||||||
|
QCOMPARE( point.x(), 3.0 );
|
||||||
|
QCOMPARE( point.y(), 4.0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestQgsPoint::constructors()
|
||||||
|
{
|
||||||
|
QgsPoint point1 = QgsPoint( 20.0, -20.0 );
|
||||||
|
QCOMPARE( point1.x(), 20.0 );
|
||||||
|
QCOMPARE( point1.y(), -20.0 );
|
||||||
|
QgsPoint point2( point1 );
|
||||||
|
QCOMPARE( point2, point1 );
|
||||||
|
|
||||||
|
QPointF sourceQPointF( 20.0, -20.0 );
|
||||||
|
QgsPoint fromQPointF( sourceQPointF );
|
||||||
|
QCOMPARE( fromQPointF.x(), 20.0 );
|
||||||
|
QCOMPARE( fromQPointF.y(), -20.0 );
|
||||||
|
|
||||||
|
QPointF sourceQPoint( 20, -20 );
|
||||||
|
QgsPoint fromQPoint( sourceQPoint );
|
||||||
|
QCOMPARE( fromQPoint.x(), 20.0 );
|
||||||
|
QCOMPARE( fromQPoint.y(), -20.0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestQgsPoint::toQPointF()
|
||||||
|
{
|
||||||
|
QgsPoint point( 20.0, -20.0 );
|
||||||
|
QPointF result = point.toQPointF();
|
||||||
|
QCOMPARE( result.x(), 20.0 );
|
||||||
|
QCOMPARE( result.y(), -20.0 );
|
||||||
|
}
|
||||||
|
|
||||||
void TestQgsPoint::initTestCase()
|
void TestQgsPoint::initTestCase()
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user