Skip to content

Commit 5789eec

Browse files
author
wonder
committed
- more sane function prototypes for searching for closest vertex/segment
- fixed some problems in python bindings git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6896 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d2d4b23 commit 5789eec

File tree

10 files changed

+130
-139
lines changed

10 files changed

+130
-139
lines changed

python/core/qgsgeometry.sip

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class QgsGeometry
206206
*/
207207
// SIP: buffer will be transferred from python to C++
208208
// TODO: create pythonic interface that will receive wkb as a string
209-
void setWkbAndOwnership(unsigned char * wkb /Transfer/, size_t length);
209+
void setWkbAndOwnership(unsigned char * wkb /Transfer, Array/, size_t length /ArraySize/);
210210

211211
/**
212212
Returns the buffer containing this geometry in WKB format.
@@ -298,36 +298,34 @@ class QgsGeometry
298298

299299
*/
300300
double sqrDistToVertexAt(QgsPoint& point,
301-
QgsGeometryVertexIndex& atVertex);
301+
QgsGeometryVertexIndex& atVertex /Out/);
302302

303303
/**
304-
* Modifies x and y to indicate the location of
305-
* the vertex at the given position number,
306-
* ring and item (first number is index 0)
307-
* to the given coordinates
308-
*
309-
* Returns TRUE if atVertex is a valid position on
310-
* the geometry, otherwise FALSE.
311-
*
312-
* If FALSE, x and y are not modified.
304+
* Returns coordinates of a vertex.
305+
* @param atVertex index of the vertex
306+
* @return Coordinates of the vertex or QgsPoint(0,0) on error
313307
*/
314-
bool vertexAt(double &x, double &y, QgsGeometryVertexIndex atVertex);
308+
QgsPoint vertexAt(const QgsGeometryVertexIndex& atVertex);
315309

316310
/**
317-
Returns, in atVertex, the closest vertex in this geometry to the given point.
318-
The squared cartesian distance is also returned in sqrDist.
311+
* Searches for the the closest vertex in this geometry to the given point.
312+
* @param point Specifiest the point for search
313+
* @param atVertex Receives index of the closest vertex
314+
* @return The squared cartesian distance is also returned in sqrDist, negative number on error
319315
*/
320-
QgsPoint closestVertexWithContext(QgsPoint& point,
321-
QgsGeometryVertexIndex& atVertex,
322-
double& sqrDist);
316+
double closestVertexWithContext(const QgsPoint& point,
317+
QgsGeometryVertexIndex& atVertex /Out/);
323318

324319
/**
325-
Returns, in beforeVertex, the closest segment in this geometry to the given point.
326-
The squared cartesian distance is also returned in sqrDist.
320+
* Searches for the closest segment of geometry to the given point
321+
* @param point Specifies the point for search
322+
* @param minDistPoint Receives the nearest point on the segment
323+
* @param beforeVertex Receives index of the vertex before the closest segment
324+
* @return The squared cartesian distance is also returned in sqrDist, negative number on error
327325
*/
328-
QgsPoint closestSegmentWithContext(QgsPoint& point,
329-
QgsGeometryVertexIndex& beforeVertex,
330-
double& sqrDist);
326+
double closestSegmentWithContext(const QgsPoint& point,
327+
QgsPoint& minDistPoint /Out/,
328+
QgsGeometryVertexIndex& beforeVertex /Out/);
331329

332330
/**Returns the bounding box of this feature*/
333331
QgsRect boundingBox();

python/core/qgspoint.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public:
6262
/**Returns the squared distance between this point and x,y*/
6363
double sqrDist(double x, double y) const;
6464

65+
/**Returns the squared distance between this and other point*/
66+
double sqrDist(const QgsPoint& other);
67+
6568
//! equality operator
6669
bool operator==(const QgsPoint &other);
6770

python/core/qgsvectorlayer.sip

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public:
185185
If there is no point within this tolerance, point is left unchanged.
186186
@param tolerance The snapping tolerance
187187
@return true if the position of point has been changed, and false otherwise */
188-
bool snapPoint(QgsPoint& point, double tolerance);
188+
bool snapPoint(QgsPoint& point /In, Out/, double tolerance);
189189

190190
/**Snaps a point to the closest vertex if there is one within the snapping tolerance
191191
@param atVertex Set to a vertex index of the snapped-to vertex
@@ -199,11 +199,11 @@ public:
199199
TODO: Handle returning multiple verticies if they are coincident
200200
*/
201201
bool snapVertexWithContext(QgsPoint& point,
202-
QgsGeometryVertexIndex& atVertex,
203-
int& beforeVertexIndex,
204-
int& afterVertexIndex,
205-
int& snappedFeatureId,
206-
QgsGeometry& snappedGeometry,
202+
QgsGeometryVertexIndex& atVertex /Out/,
203+
int& beforeVertexIndex /Out/,
204+
int& afterVertexIndex /Out/,
205+
int& snappedFeatureId /Out/,
206+
QgsGeometry& snappedGeometry /Out/,
207207
double tolerance);
208208

209209
/**Snaps a point to the closest line segment if there is one within the snapping tolerance
@@ -215,10 +215,10 @@ public:
215215

216216
TODO: Handle returning multiple lineFeatures if they are coincident
217217
*/
218-
bool snapSegmentWithContext(QgsPoint& point,
219-
QgsGeometryVertexIndex& beforeVertex,
220-
int& snappedFeatureId,
221-
QgsGeometry& snappedGeometry,
218+
bool snapSegmentWithContext(QgsPoint& point /In, Out/,
219+
QgsGeometryVertexIndex& beforeVertex /Out/,
220+
int& snappedFeatureId /Out/,
221+
QgsGeometry& snappedGeometry /Out/,
222222
double tolerance);
223223

224224
/**

src/app/qgsmaptoolvertexedit.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
9999
{
100100
QgsPoint point = toMapCoords(e->pos());
101101

102-
double x1, y1;
103-
double x2, y2;
104102
QgsGeometryVertexIndex index, rb1Index, rb2Index; //rb1Index/rb2Index is for rubberbanding
105103

106104
if (mTool == AddVertex)
@@ -122,20 +120,20 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
122120

123121
index = mSnappedBeforeVertex;
124122
// Get the endpoint of the snapped-to segment
125-
mSnappedAtGeometry.vertexAt(x2, y2, index);
123+
QgsPoint pnt2 = mSnappedAtGeometry.vertexAt(index);
126124

127125
// Get the startpoint of the snapped-to segment
128126
index.decrement_back();
129-
mStartPointValid = mSnappedAtGeometry.vertexAt(x1, y1, index);
127+
QgsPoint pnt1 = mSnappedAtGeometry.vertexAt(index);
130128

131129
createRubberBand();
132130

133-
if (mStartPointValid)
131+
if (pnt1 != QgsPoint(0,0))
134132
{
135-
mRubberBand->addPoint(QgsPoint(x1,y1));
133+
mRubberBand->addPoint(pnt1);
136134
}
137135
mRubberBand->addPoint(toMapCoords(e->pos()));
138-
mRubberBand->addPoint(QgsPoint(x2,y2));
136+
mRubberBand->addPoint(pnt2);
139137
}
140138
else if (mTool == MoveVertex)
141139
{
@@ -190,8 +188,8 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
190188
if(mRubberBandIndex1 != -1)
191189
{
192190
rb1Index.push_back(mRubberBandIndex1);
193-
mSnappedAtGeometry.vertexAt(x1, y1, rb1Index);
194-
mRubberBand->addPoint(QgsPoint(x1,y1));
191+
QgsPoint pnt1 = mSnappedAtGeometry.vertexAt(rb1Index);
192+
mRubberBand->addPoint(pnt1);
195193
mStartPointValid = true;
196194
}
197195
else
@@ -205,8 +203,8 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
205203
if(mRubberBandIndex2 != -1)
206204
{
207205
rb2Index.push_back(mRubberBandIndex2);
208-
mSnappedAtGeometry.vertexAt(x2, y2, rb2Index);
209-
mRubberBand->addPoint(QgsPoint(x2,y2));
206+
QgsPoint pnt2 = mSnappedAtGeometry.vertexAt(rb2Index);
207+
mRubberBand->addPoint(pnt2);
210208
}
211209
#ifdef QGISDEBUG
212210
qWarning("Creating rubber band for moveVertex");
@@ -230,11 +228,11 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
230228
}
231229

232230
// Get the point of the snapped-to vertex
233-
mSnappedAtGeometry.vertexAt(x1, y1, mSnappedAtVertex);
231+
QgsPoint pnt = mSnappedAtGeometry.vertexAt(mSnappedAtVertex);
234232

235233
mCross = new QgsVertexMarker(mCanvas);
236234
mCross->setIconType(QgsVertexMarker::ICON_X);
237-
mCross->setCenter(QgsPoint(x1,y1));
235+
mCross->setCenter(pnt);
238236
}
239237

240238
}

0 commit comments

Comments
 (0)