Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Consistently use unsigned int for QgsRegularPolygon
  • Loading branch information
nyalldawson committed Sep 19, 2017
1 parent 92d7396 commit 328fc9c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
11 changes: 5 additions & 6 deletions python/core/geometry/qgsregularpolygon.sip
Expand Up @@ -35,7 +35,7 @@ class QgsRegularPolygon

QgsRegularPolygon();

QgsRegularPolygon( const QgsPoint &center, const double radius, const double azimuth, const int numberSides, const ConstructionOption circle );
QgsRegularPolygon( const QgsPoint &center, const double radius, const double azimuth, const unsigned int numberSides, const ConstructionOption circle );
%Docstring
Constructs a regular polygon by ``center`` and parameters for the first vertex. An empty regular polygon is returned if ``numberSides`` < 3 or ``ConstructionOption`` isn't valid.
\param center The center of the regular polygon.
Expand All @@ -45,7 +45,7 @@ class QgsRegularPolygon
.. seealso:: ConstructionOption
%End

QgsRegularPolygon( const QgsPoint &center, const QgsPoint &pt1, const int numberSides, const ConstructionOption circle );
QgsRegularPolygon( const QgsPoint &center, const QgsPoint &pt1, const unsigned int numberSides, const ConstructionOption circle );
%Docstring
Constructs a regular polygon by ``center`` and another point.
\param center The center of the regular polygon.
Expand All @@ -54,7 +54,7 @@ class QgsRegularPolygon
\param circle Option to create the polygon inscribed in circle (the radius is the distance between the center and vertices) or circumscribed about circle (the radius is the distance from the center to the midpoints of the sides).
%End

QgsRegularPolygon( const QgsPoint &pt1, const QgsPoint &pt2, const int numberSides );
QgsRegularPolygon( const QgsPoint &pt1, const QgsPoint &pt2, const unsigned int numberSides );
%Docstring
Constructs a regular polygon by two points of the first side.
\param pt1 The first vertex of the first side, also first vertex of the regular polygon.
Expand Down Expand Up @@ -102,11 +102,10 @@ A regular polygon is empty if radius equal to 0 or number of sides < 3
:rtype: float
%End

int numberSides() const;
unsigned int numberSides() const;
%Docstring
Returns the number of sides of the regular polygon.
.. seealso:: setNumberSides()
:rtype: int
%End

void setCenter( const QgsPoint &center );
Expand All @@ -130,7 +129,7 @@ A regular polygon is empty if radius equal to 0 or number of sides < 3
.. seealso:: firstVertex()
%End

void setNumberSides( const int numberSides );
void setNumberSides( const unsigned int numberSides );
%Docstring
Sets the number of sides.
If numberSides < 3, the number of sides is unchanged.
Expand Down
10 changes: 5 additions & 5 deletions src/core/geometry/qgsregularpolygon.h
Expand Up @@ -60,22 +60,22 @@ class CORE_EXPORT QgsRegularPolygon
* \param numberSides Number of sides of the regular polygon.
* \param circle Option to create the polygon. \see ConstructionOption
*/
QgsRegularPolygon( const QgsPoint &center, const double radius, const double azimuth, const int numberSides, const ConstructionOption circle );
QgsRegularPolygon( const QgsPoint &center, const double radius, const double azimuth, const unsigned int numberSides, const ConstructionOption circle );

/** Constructs a regular polygon by \a center and another point.
* \param center The center of the regular polygon.
* \param pt1 The first vertex if the polygon is inscribed in circle or the midpoint of a side if the polygon is circumscribed about circle.
* \param numberSides Number of sides of the regular polygon.
* \param circle Option to create the polygon inscribed in circle (the radius is the distance between the center and vertices) or circumscribed about circle (the radius is the distance from the center to the midpoints of the sides).
*/
QgsRegularPolygon( const QgsPoint &center, const QgsPoint &pt1, const int numberSides, const ConstructionOption circle );
QgsRegularPolygon( const QgsPoint &center, const QgsPoint &pt1, const unsigned int numberSides, const ConstructionOption circle );

/** Constructs a regular polygon by two points of the first side.
* \param pt1 The first vertex of the first side, also first vertex of the regular polygon.
* \param pt2 The second vertex of the first side.
* \param numberSides Number of sides of the regular polygon.
*/
QgsRegularPolygon( const QgsPoint &pt1, const QgsPoint &pt2, const int numberSides );
QgsRegularPolygon( const QgsPoint &pt1, const QgsPoint &pt2, const unsigned int numberSides );

bool operator ==( const QgsRegularPolygon &rp ) const;
bool operator !=( const QgsRegularPolygon &rp ) const;
Expand Down Expand Up @@ -109,7 +109,7 @@ class CORE_EXPORT QgsRegularPolygon
/** Returns the number of sides of the regular polygon.
* \see setNumberSides()
*/
int numberSides() const { return mNumberSides; }
unsigned int numberSides() const { return mNumberSides; }

/** Sets the center point.
* Radius is unchanged. The first vertex is reprojected from the new center.
Expand All @@ -133,7 +133,7 @@ class CORE_EXPORT QgsRegularPolygon
* If numberSides < 3, the number of sides is unchanged.
* \see numberSides()
*/
void setNumberSides( const int numberSides );
void setNumberSides( const unsigned int numberSides );

/** Returns a list including the vertices of the regular polygon.
*/
Expand Down
12 changes: 6 additions & 6 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -4313,7 +4313,7 @@ void TestQgsGeometry::regularPolygon()
QgsRegularPolygon rp1 = QgsRegularPolygon();
QCOMPARE( rp1.center(), QgsPoint() );
QCOMPARE( rp1.firstVertex(), QgsPoint() );
QCOMPARE( rp1.numberSides(), 0 );
QCOMPARE( rp1.numberSides(), static_cast< unsigned int >( 0 ) );
QCOMPARE( rp1.radius(), 0.0 );
QVERIFY( rp1.isEmpty() );

Expand All @@ -4327,7 +4327,7 @@ void TestQgsGeometry::regularPolygon()
QVERIFY( !rp2.isEmpty() );
QCOMPARE( rp2.center(), QgsPoint() );
QCOMPARE( rp2.firstVertex(), QgsPoint( 0, 5 ) );
QCOMPARE( rp2.numberSides(), 5 );
QCOMPARE( rp2.numberSides(), static_cast< unsigned int>( 5 ) );
QCOMPARE( rp2.radius(), 5.0 );
QGSCOMPARENEAR( rp2.apothem(), 4.0451, 10E-4 );
QVERIFY( rp2 == QgsRegularPolygon( QgsPoint(), -5, 0, 5, QgsRegularPolygon::InscribedCircle ) );
Expand Down Expand Up @@ -4367,16 +4367,16 @@ void TestQgsGeometry::regularPolygon()

rp7.setNumberSides( 2 );
QVERIFY( rp7.isEmpty() );
QCOMPARE( rp7.numberSides(), 0 );
QCOMPARE( rp7.numberSides(), static_cast< unsigned int >( 0 ) );
rp7.setNumberSides( 5 );
QVERIFY( rp7.isEmpty() );
QCOMPARE( rp7.numberSides(), 5 );
QCOMPARE( rp7.numberSides(), static_cast< unsigned int >( 5 ) );
rp7.setNumberSides( 2 );
QVERIFY( rp7.isEmpty() );
QCOMPARE( rp7.numberSides(), 5 );
QCOMPARE( rp7.numberSides(), static_cast< unsigned int >( 5 ) );
rp7.setNumberSides( 3 );
QVERIFY( rp7.isEmpty() );
QCOMPARE( rp7.numberSides(), 3 );
QCOMPARE( rp7.numberSides(), static_cast< unsigned int >( 3 ) );

rp7.setRadius( -6 );
QVERIFY( !rp7.isEmpty() );
Expand Down

0 comments on commit 328fc9c

Please sign in to comment.