Skip to content

Commit

Permalink
In Vertex editing, if editing a polygon, preference is now given to e…
Browse files Browse the repository at this point in the history
…diting the polygon that the mouse is in (as opposed to an adjacent polygon whose edge passes equally close to the mouse). Previously the polygon choice was essentially random (being which one had the lower feature ID).

This is solving a similar problem to the linestring case in r5550.


git-svn-id: http://svn.osgeo.org/qgis/trunk@5569 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Jul 8, 2006
1 parent 002e57a commit dc63a47
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/core/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,20 @@ bool QgsGeometry::intersects(QgsRect* r) const
}


bool QgsGeometry::contains(QgsPoint* p) const
{
bool returnval = false;

exportWkbToGeos();

geos::Point* geosPoint = geosGeometryFactory->createPoint(geos::Coordinate(p->x(), p->y()));

return mGeos->contains(geosPoint);

delete geosPoint;
}


bool QgsGeometry::exportToWkt(unsigned char * geom) const
{
#ifdef QGISDEBUG
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ class QgsGeometry {
/**Returns the bounding box of this feature*/
QgsRect boundingBox() const;

/**Test for intersection with a rectangle (uses GEOS)*/
/** Test for intersection with a rectangle (uses GEOS) */
bool intersects(QgsRect* r) const;

/** Test for containment of a point (uses GEOS) */
bool contains(QgsPoint* p) const;

/**Creates a geos geometry from this features geometry. Note, that the returned object needs to be deleted*/
geos::Geometry* geosGeometry() const;

Expand All @@ -190,6 +193,7 @@ class QgsGeometry {

// Private static members

//! This is used to create new GEOS variables.
static geos::GeometryFactory* geosGeometryFactory;


Expand Down
58 changes: 52 additions & 6 deletions src/gui/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,10 @@ QGis::VectorType QgsVectorLayer::vectorType() const
case QGis::WKBMultiPolygon:
return QGis::Polygon;
}
#ifdef QGISDEBUG
QgsLogger::debug("Warning: Data Provider Geometry type is not recognised, is", type, 1, __FILE__, __FUNCTION__, __LINE__);
#endif

}
else
{
Expand Down Expand Up @@ -2857,7 +2861,14 @@ int& snappedFeatureId, QgsGeometry& snappedGeometry, double tolerance)
}

minDistSegPoint = feature->geometry()->closestVertex(origPoint, atVertexTemp, beforeVertexIndexTemp, afterVertexIndexTemp, testSqrDist);
if(testSqrDist < minSqrDist)
if (
(testSqrDist < minSqrDist) ||
(
// this test will "choose" the polygon that the origPoint is in:
(testSqrDist == minSqrDist) &&
(feature->geometry()->contains(&origPoint))
)
)
{
point = minDistSegPoint;
minSqrDist = testSqrDist;
Expand Down Expand Up @@ -2887,7 +2898,14 @@ int& snappedFeatureId, QgsGeometry& snappedGeometry, double tolerance)
{
minDistSegPoint = (*iter)->geometry()->closestVertex(origPoint, atVertexTemp, beforeVertexIndexTemp, afterVertexIndexTemp, testSqrDist);
}
if(testSqrDist < minSqrDist)
if (
(testSqrDist < minSqrDist) ||
(
// this test will "choose" the polygon that the origPoint is in:
(testSqrDist == minSqrDist) &&
((*iter)->geometry()->contains(&origPoint))
)
)
{
point = minDistSegPoint;
minSqrDist = testSqrDist;
Expand All @@ -2905,7 +2923,14 @@ int& snappedFeatureId, QgsGeometry& snappedGeometry, double tolerance)
for(std::map<int, QgsGeometry>::iterator it = mChangedGeometries.begin(); it != mChangedGeometries.end(); ++it)
{
minDistSegPoint = it->second.closestVertex(origPoint, atVertexTemp, beforeVertexIndexTemp, afterVertexIndexTemp, testSqrDist);
if(testSqrDist < minSqrDist)
if (
(testSqrDist < minSqrDist) ||
(
// this test will "choose" the polygon that the origPoint is in:
(testSqrDist == minSqrDist) &&
(it->second.contains(&origPoint))
)
)
{
point = minDistSegPoint;
minSqrDist = testSqrDist;
Expand Down Expand Up @@ -2992,7 +3017,14 @@ QgsGeometry& snappedGeometry, double tolerance)

minDistSegPoint = feature->geometry()->closestSegmentWithContext(origPoint, beforeVertexTemp, testSqrDist);

if (testSqrDist < minSqrDist)
if (
(testSqrDist < minSqrDist) ||
(
// this test will "choose" the polygon that the origPoint is in:
(testSqrDist == minSqrDist) &&
(feature->geometry()->contains(&origPoint))
)
)
{
point = minDistSegPoint;
minSqrDist = testSqrDist;
Expand Down Expand Up @@ -3022,7 +3054,14 @@ QgsGeometry& snappedGeometry, double tolerance)
minDistSegPoint = (*iter)->geometry()->closestSegmentWithContext(origPoint, beforeVertexTemp, testSqrDist);
}

if (testSqrDist < minSqrDist)
if (
(testSqrDist < minSqrDist) ||
(
// this test will "choose" the polygon that the origPoint is in:
(testSqrDist == minSqrDist) &&
((*iter)->geometry()->contains(&origPoint))
)
)
{
point = minDistSegPoint;
minSqrDist = testSqrDist;
Expand All @@ -3038,7 +3077,14 @@ QgsGeometry& snappedGeometry, double tolerance)
for(std::map<int, QgsGeometry>::iterator it = mChangedGeometries.begin(); it != mChangedGeometries.end(); ++it)
{
minDistSegPoint = it->second.closestSegmentWithContext(origPoint, beforeVertexTemp, testSqrDist);
if(testSqrDist < minSqrDist)
if (
(testSqrDist < minSqrDist) ||
(
// this test will "choose" the polygon that the origPoint is in:
(testSqrDist == minSqrDist) &&
(it->second.contains(&origPoint))
)
)
{
point = minDistSegPoint;
minSqrDist = testSqrDist;
Expand Down

0 comments on commit dc63a47

Please sign in to comment.