Skip to content

Commit b82c9b8

Browse files
raymondnijssen3nids
authored andcommittedApr 30, 2017
sipify QgsPoint
1 parent bb3a418 commit b82c9b8

File tree

3 files changed

+294
-135
lines changed

3 files changed

+294
-135
lines changed
 

‎python/auto_sip.blacklist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ core/qgspallabeling.sip
6565
core/qgspathresolver.sip
6666
core/qgspluginlayer.sip
6767
core/qgspluginlayerregistry.sip
68-
core/qgspoint.sip
6968
core/qgspointlocator.sip
7069
core/qgsproject.sip
7170
core/qgsprojectbadlayerhandler.sip

‎python/core/qgspoint.sip

Lines changed: 254 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,222 +1,343 @@
1-
/** \ingroup core
2-
* A class to represent a point.
3-
* Currently no Z axis / 2.5D support is implemented.
4-
*/
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/qgspoint.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
14+
515
class QgsPoint
616
{
17+
%Docstring
18+
A class to represent a point.
19+
For Z and M support prefer QgsPointV2.
20+
%End
721

822
%TypeHeaderCode
9-
#include <qgspoint.h>
10-
#include <QString>
23+
#include "qgspoint.h"
1124
%End
12-
1325
public:
14-
/// Default constructor
1526
QgsPoint();
1627

17-
/** Create a point from another point */
18-
QgsPoint( const QgsPoint& p );
28+
QgsPoint( const QgsPoint &p );
29+
%Docstring
30+
Create a point from another point
31+
%End
1932

20-
/** Create a point from x,y coordinates
21-
* @param x x coordinate
22-
* @param y y coordinate
23-
*/
2433
QgsPoint( double x, double y );
34+
%Docstring
35+
Create a point from x,y coordinates
36+
\param x x coordinate
37+
\param y y coordinate
38+
%End
2539

26-
/** Create a point from a QPointF
27-
* @param point QPointF source
28-
* @note added in QGIS 2.7
29-
*/
3040
QgsPoint( QPointF point );
41+
%Docstring
42+
Create a point from a QPointF
43+
\param point QPointF source
44+
.. versionadded:: 2.7
45+
%End
3146

32-
/** Create a point from a QPoint
33-
* @param point QPoint source
34-
* @note added in QGIS 2.7
35-
*/
3647
QgsPoint( QPoint point );
48+
%Docstring
49+
Create a point from a QPoint
50+
\param point QPoint source
51+
.. versionadded:: 2.7
52+
%End
53+
54+
QgsPoint( const QgsPointV2 &point );
55+
%Docstring
56+
Create a new point.
57+
Z and M values will be dropped.
58+
59+
.. versionadded:: 3.0
60+
%End
3761

3862
~QgsPoint();
3963

40-
/** Sets the x value of the point
41-
* @param x x coordinate
42-
*/
4364
void setX( double x );
65+
%Docstring
66+
Sets the x value of the point
67+
\param x x coordinate
68+
%End
4469

45-
/** Sets the y value of the point
46-
* @param y y coordinate
47-
*/
4870
void setY( double y );
71+
%Docstring
72+
Sets the y value of the point
73+
\param y y coordinate
74+
%End
4975

50-
/** Sets the x and y value of the point */
5176
void set( double x, double y );
77+
%Docstring
78+
Sets the x and y value of the point
79+
%End
5280

53-
/** Get the x value of the point
54-
* @return x coordinate
55-
*/
5681
double x() const;
82+
%Docstring
83+
Get the x value of the point
84+
:return: x coordinate
85+
:rtype: float
86+
%End
5787

58-
/** Get the y value of the point
59-
* @return y coordinate
60-
*/
6188
double y() const;
89+
%Docstring
90+
Get the y value of the point
91+
:return: y coordinate
92+
:rtype: float
93+
%End
6294

63-
/** Converts a point to a QPointF
64-
* @returns QPointF with same x and y values
65-
* @note added in QGIS 2.7
66-
*/
6795
QPointF toQPointF() const;
96+
%Docstring
97+
Converts a point to a QPointF
98+
:return: QPointF with same x and y values
99+
.. versionadded:: 2.7
100+
:rtype: QPointF
101+
%End
68102

69-
//! String representation of the point (x,y)
70103
QString toString() const;
104+
%Docstring
105+
String representation of the point (x,y)
106+
:rtype: str
107+
%End
71108

72-
//! As above but with precision for string representation of a point
73109
QString toString( int precision ) const;
110+
%Docstring
111+
As above but with precision for string representation of a point
112+
:rtype: str
113+
%End
74114

75-
/** Return a string representation as degrees minutes seconds.
76-
* Its up to the calling function to ensure that this point can
77-
* be meaningfully represented in this form.
78-
* @param precision number of decimal points to use for seconds
79-
* @param useSuffix set to true to include a direction suffix (e.g., 'N'),
80-
* set to false to use a "-" prefix for west and south coordinates
81-
* @param padded set to true to force minutes and seconds to use two decimals,
82-
* e.g., '05' instead of '5'.
83-
*/
84115
QString toDegreesMinutesSeconds( int precision, const bool useSuffix = true, const bool padded = false ) const;
116+
%Docstring
117+
Return a string representation as degrees minutes seconds.
118+
Its up to the calling function to ensure that this point can
119+
be meaningfully represented in this form.
120+
\param precision number of decimal points to use for seconds
121+
\param useSuffix set to true to include a direction suffix (e.g., 'N'),
122+
set to false to use a "-" prefix for west and south coordinates
123+
\param padded set to true to force minutes and seconds to use two decimals,
124+
e.g., '05' instead of '5'.
125+
:rtype: str
126+
%End
85127

86-
/** Return a string representation as degrees minutes.
87-
* Its up to the calling function to ensure that this point can
88-
* be meaningfully represented in this form.
89-
* @param precision number of decimal points to use for minutes
90-
* @param useSuffix set to true to include a direction suffix (e.g., 'N'),
91-
* set to false to use a "-" prefix for west and south coordinates
92-
* @param padded set to true to force minutes to use two decimals,
93-
* e.g., '05' instead of '5'.
94-
*/
95128
QString toDegreesMinutes( int precision, const bool useSuffix = true, const bool padded = false ) const;
129+
%Docstring
130+
Return a string representation as degrees minutes.
131+
Its up to the calling function to ensure that this point can
132+
be meaningfully represented in this form.
133+
\param precision number of decimal points to use for minutes
134+
\param useSuffix set to true to include a direction suffix (e.g., 'N'),
135+
set to false to use a "-" prefix for west and south coordinates
136+
\param padded set to true to force minutes to use two decimals,
137+
e.g., '05' instead of '5'.
138+
:rtype: str
139+
%End
96140

97141

98-
/** Return the well known text representation for the point.
99-
* The wkt is created without an SRID.
100-
* @return Well known text in the form POINT(x y)
101-
*/
102142
QString wellKnownText() const;
143+
%Docstring
144+
Return the well known text representation for the point.
145+
The wkt is created without an SRID.
146+
:return: Well known text in the form POINT(x y)
147+
:rtype: str
148+
%End
103149

104-
/** Returns the squared distance between this point a specified x, y coordinate.
105-
* @see distance()
106-
*/
107150
double sqrDist( double x, double y ) const;
151+
%Docstring
152+
Returns the squared distance between this point a specified x, y coordinate.
153+
.. seealso:: distance()
154+
:rtype: float
155+
%End
156+
157+
double sqrDist( const QgsPoint &other ) const;
158+
%Docstring
159+
Returns the squared distance between this point another point.
160+
.. seealso:: distance()
161+
:rtype: float
162+
%End
108163

109-
/** Returns the squared distance between this point another point.
110-
* @see distance()
111-
*/
112-
double sqrDist( const QgsPoint& other ) const;
113-
114-
/** Returns the distance between this point and a specified x, y coordinate.
115-
* @param x x-coordniate
116-
* @param y y-coordinate
117-
* @see sqrDist()
118-
* @note added in QGIS 2.16
119-
*/
120164
double distance( double x, double y ) const;
165+
%Docstring
166+
Returns the distance between this point and a specified x, y coordinate.
167+
\param x x-coordniate
168+
\param y y-coordinate
169+
.. seealso:: sqrDist()
170+
.. versionadded:: 2.16
171+
:rtype: float
172+
%End
173+
174+
double distance( const QgsPoint &other ) const;
175+
%Docstring
176+
Returns the distance between this point and another point.
177+
\param other other point
178+
.. seealso:: sqrDist()
179+
.. versionadded:: 2.16
180+
:rtype: float
181+
%End
182+
183+
double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint &minDistPoint /Out/, double epsilon = DEFAULT_SEGMENT_EPSILON ) const;
184+
%Docstring
185+
Returns the minimum distance between this point and a segment
186+
:rtype: float
187+
%End
188+
189+
double azimuth( const QgsPoint &other ) const;
190+
%Docstring
191+
Calculates azimuth between this point and other one (clockwise in degree, starting from north)
192+
:rtype: float
193+
%End
121194

122-
/** Returns the distance between this point and another point.
123-
* @param other other point
124-
* @see sqrDist()
125-
* @note added in QGIS 2.16
126-
*/
127-
double distance( const QgsPoint& other ) const;
128-
129-
/** Returns the minimum distance between this point and a segment */
130-
double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint& minDistPoint /Out/, double epsilon = DEFAULT_SEGMENT_EPSILON ) const;
131-
132-
/** Calculates azimuth between this point and other one (clockwise in degree, starting from north) */
133-
double azimuth( const QgsPoint& other ) const;
134-
135-
/** Returns a new point which corresponds to this point projected by a specified distance
136-
* in a specified bearing.
137-
* @param distance distance to project
138-
* @param bearing angle to project in, clockwise in degrees starting from north
139-
* @note added in QGIS 2.16
140-
*/
141195
QgsPoint project( double distance, double bearing ) const;
196+
%Docstring
197+
Returns a new point which corresponds to this point projected by a specified distance
198+
in a specified bearing.
199+
\param distance distance to project
200+
\param bearing angle to project in, clockwise in degrees starting from north
201+
.. versionadded:: 2.16
202+
:rtype: QgsPoint
203+
%End
142204

143-
/** Compares this point with another point with a fuzzy tolerance
144-
* @param other point to compare with
145-
* @param epsilon maximum difference for coordinates between the points
146-
* @returns true if points are equal within specified tolerance
147-
* @note added in QGIS 2.9
148-
*/
149205
bool compare( const QgsPoint &other, double epsilon = 4 * DBL_EPSILON ) const;
206+
%Docstring
207+
Compares this point with another point with a fuzzy tolerance
208+
\param other point to compare with
209+
\param epsilon maximum difference for coordinates between the points
210+
:return: true if points are equal within specified tolerance
211+
.. versionadded:: 2.9
212+
:rtype: bool
213+
%End
150214

151-
//! equality operator
152215
bool operator==( const QgsPoint &other );
216+
%Docstring
217+
equality operator
218+
:rtype: bool
219+
%End
153220

154-
//! Inequality operator
155221
bool operator!=( const QgsPoint &other ) const;
222+
%Docstring
223+
Inequality operator
224+
:rtype: bool
225+
%End
156226

157-
//! Multiply x and y by the given value
158227
void multiply( double scalar );
228+
%Docstring
229+
Multiply x and y by the given value
230+
%End
231+
232+
int onSegment( const QgsPoint &a, const QgsPoint &b ) const;
233+
%Docstring
234+
3 if point is on open ray b.
235+
:rtype: int
236+
%End
159237

160-
//! Test if this point is on the segment defined by points a, b
161-
//! @return 0 if this point is not on the open ray through a and b,
162-
//! 1 if point is on open ray a, 2 if point is within line segment,
163-
//! 3 if point is on open ray b.
164-
int onSegment( const QgsPoint& a, const QgsPoint& b ) const;
165238

166-
//! Calculates the vector obtained by subtracting a point from this point
167-
QgsVector operator-( const QgsPoint& p ) const;
239+
QgsVector operator-( const QgsPoint &p ) const;
240+
%Docstring
241+
Calculates the vector obtained by subtracting a point from this point
242+
:rtype: QgsVector
243+
%End
168244

169-
//! Adds a vector to this point in place
170245
QgsPoint &operator+=( QgsVector v );
246+
%Docstring
247+
Adds a vector to this point in place
248+
:rtype: QgsPoint
249+
%End
171250

172-
//! Subtracts a vector from this point in place
173251
QgsPoint &operator-=( QgsVector v );
252+
%Docstring
253+
Subtracts a vector from this point in place
254+
:rtype: QgsPoint
255+
%End
174256

175-
//! Adds a vector to this point
176257
QgsPoint operator+( QgsVector v ) const;
258+
%Docstring
259+
Adds a vector to this point
260+
:rtype: QgsPoint
261+
%End
177262

178-
//! Subtracts a vector from this point
179263
QgsPoint operator-( QgsVector v ) const;
264+
%Docstring
265+
Subtracts a vector from this point
266+
:rtype: QgsPoint
267+
%End
180268

181-
//! Multiplies the coordinates in this point by a scalar quantity
182269
QgsPoint operator*( double scalar ) const;
270+
%Docstring
271+
Multiplies the coordinates in this point by a scalar quantity
272+
:rtype: QgsPoint
273+
%End
183274

184-
//! Divides the coordinates in this point by a scalar quantity
185275
QgsPoint operator/( double scalar ) const;
276+
%Docstring
277+
Divides the coordinates in this point by a scalar quantity
278+
:rtype: QgsPoint
279+
%End
186280

187-
//! Multiplies the coordinates in this point by a scalar quantity in place
188281
QgsPoint &operator*=( double scalar );
282+
%Docstring
283+
Multiplies the coordinates in this point by a scalar quantity in place
284+
:rtype: QgsPoint
285+
%End
189286

190-
//! Divides the coordinates in this point by a scalar quantity in place
191287
QgsPoint &operator/=( double scalar );
288+
%Docstring
289+
Divides the coordinates in this point by a scalar quantity in place
290+
:rtype: QgsPoint
291+
%End
192292

193-
SIP_PYOBJECT __repr__();
293+
private:
294+
SIP_PYOBJECT __repr__();
194295
%MethodCode
195-
QString str = "(" + QString::number(sipCpp->x()) + "," + QString::number(sipCpp->y()) + ")";
296+
QString str = "(" + QString::number( sipCpp->x() ) + "," + QString::number( sipCpp->y() ) + ")";
196297
//QString str("(%f,%f)").arg(sipCpp->x()).arg(sipCpp->y());
197298
sipRes = PyUnicode_FromString( str.toUtf8().data() );
198299
%End
199300

200-
int __len__();
301+
int __len__();
302+
%Docstring
303+
:rtype: int
304+
%End
201305
%MethodCode
202306
sipRes = 2;
203307
%End
204308

205309

206-
SIP_PYOBJECT __getitem__(int);
310+
SIP_PYOBJECT __getitem__( int );
207311
%MethodCode
208-
if (a0 == 0) {
209-
sipRes = Py_BuildValue("d",sipCpp->x());
210-
} else if (a0 == 1) {
211-
sipRes = Py_BuildValue("d",sipCpp->y());
212-
} else {
213-
QString msg = QString("Bad index: %1").arg(a0);
214-
PyErr_SetString(PyExc_IndexError, msg.toAscii().constData());
312+
if ( a0 == 0 )
313+
{
314+
sipRes = Py_BuildValue( "d", sipCpp->x() );
315+
}
316+
else if ( a0 == 1 )
317+
{
318+
sipRes = Py_BuildValue( "d", sipCpp->y() );
319+
}
320+
else
321+
{
322+
QString msg = QString( "Bad index: %1" ).arg( a0 );
323+
PyErr_SetString( PyExc_IndexError, msg.toAscii().constData() );
215324
}
216325
%End
217326

218-
long __hash__() const;
327+
long __hash__() const;
328+
%Docstring
329+
:rtype: long
330+
%End
219331
%MethodCode
220-
sipRes = qHash( *sipCpp );
332+
sipRes = qHash( *sipCpp );
221333
%End
222334
}; // class QgsPoint
335+
336+
337+
/************************************************************************
338+
* This file has been generated automatically from *
339+
* *
340+
* src/core/qgspoint.h *
341+
* *
342+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
343+
************************************************************************/

‎src/core/qgspoint.h

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class CORE_EXPORT QgsPoint
195195
double distance( const QgsPoint &other ) const;
196196

197197
//! Returns the minimum distance between this point and a segment
198-
double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint &minDistPoint, double epsilon = DEFAULT_SEGMENT_EPSILON ) const;
198+
double sqrDistToSegment( double x1, double y1, double x2, double y2, QgsPoint &minDistPoint SIP_OUT, double epsilon = DEFAULT_SEGMENT_EPSILON ) const;
199199

200200
//! Calculates azimuth between this point and other one (clockwise in degree, starting from north)
201201
double azimuth( const QgsPoint &other ) const;
@@ -271,8 +271,45 @@ class CORE_EXPORT QgsPoint
271271

272272
friend uint qHash( const QgsPoint &pnt );
273273

274+
#ifdef SIP_RUN
275+
SIP_PYOBJECT __repr__();
276+
% MethodCode
277+
QString str = "(" + QString::number( sipCpp->x() ) + "," + QString::number( sipCpp->y() ) + ")";
278+
//QString str("(%f,%f)").arg(sipCpp->x()).arg(sipCpp->y());
279+
sipRes = PyUnicode_FromString( str.toUtf8().data() );
280+
% End
281+
282+
int __len__();
283+
% MethodCode
284+
sipRes = 2;
285+
% End
286+
287+
288+
SIP_PYOBJECT __getitem__( int );
289+
% MethodCode
290+
if ( a0 == 0 )
291+
{
292+
sipRes = Py_BuildValue( "d", sipCpp->x() );
293+
}
294+
else if ( a0 == 1 )
295+
{
296+
sipRes = Py_BuildValue( "d", sipCpp->y() );
297+
}
298+
else
299+
{
300+
QString msg = QString( "Bad index: %1" ).arg( a0 );
301+
PyErr_SetString( PyExc_IndexError, msg.toAscii().constData() );
302+
}
303+
% End
304+
305+
long __hash__() const;
306+
% MethodCode
307+
sipRes = qHash( *sipCpp );
308+
% End
309+
#endif
274310
}; // class QgsPoint
275311

312+
#ifndef SIP_RUN
276313

277314
inline bool operator==( const QgsPoint &p1, const QgsPoint &p2 )
278315
{
@@ -298,4 +335,6 @@ inline uint qHash( const QgsPoint &p )
298335
return hash;
299336
}
300337

338+
#endif
339+
301340
#endif //QGSPOINT_H

0 commit comments

Comments
 (0)
Please sign in to comment.