bool QgsCurvePolygon::insertVertex( QgsVertexId vId, const QgsPoint &vertex ) { if ( !mExteriorRing || vId.ring < 0 || vId.ring >= 1 + mInteriorRings.size() ) { return false; } QgsCurve *ring = vId.ring == 0 ? mExteriorRing.get() : mInteriorRings.at( vId.ring - 1 ); int n = ring->numPoints(); bool success = ring->insertVertex( QgsVertexId( 0, 0, vId.vertex ), vertex ); if ( !success ) { return false; } // If first or last vertex is inserted, re-sync the last/first vertex if ( vId.vertex == 0 ) ring->moveVertex( QgsVertexId( 0, 0, n ), vertex ); else if ( vId.vertex == n ) ring->moveVertex( QgsVertexId( 0, 0, 0 ), vertex ); clearCache(); return true; }
bool QgsTriangle::moveVertex( QgsVertexId vId, const QgsPointV2 &newPos ) { if ( !mExteriorRing || vId.part != 0 || vId.ring != 0 || vId.vertex < 0 || vId.vertex > 4 ) { return false; } if ( vId.vertex == 4 ) { vId.vertex = 0; } QgsPointV2 p1( vId.vertex == 0 ? newPos : vertexAt( 0 ) ); QgsPointV2 p2( vId.vertex == 1 ? newPos : vertexAt( 1 ) ); QgsPointV2 p3( vId.vertex == 2 ? newPos : vertexAt( 2 ) ); if ( !validateGeom( p1, p2, p3 ) ) { return false; } QgsCurve *ring = mExteriorRing; int n = ring->numPoints(); bool success = ring->moveVertex( vId, newPos ); if ( success ) { // If first or last vertex is moved, also move the last/first vertex if ( vId.vertex == 0 ) ring->moveVertex( QgsVertexId( vId.part, vId.ring, n - 1 ), newPos ); clearCache(); } return success; }
bool QgsCurvePolygon::deleteVertex( QgsVertexId vId ) { if ( !mExteriorRing || vId.ring < 0 || vId.ring >= 1 + mInteriorRings.size() ) { return false; } QgsCurve *ring = vId.ring == 0 ? mExteriorRing.get() : mInteriorRings.at( vId.ring - 1 ); int n = ring->numPoints(); if ( n <= 4 ) { //no points will be left in ring, so remove whole ring if ( vId.ring == 0 ) { mExteriorRing.reset(); if ( !mInteriorRings.isEmpty() ) { mExteriorRing.reset( mInteriorRings.takeFirst() ); } } else { removeInteriorRing( vId.ring - 1 ); } clearCache(); return true; } bool success = ring->deleteVertex( vId ); if ( success ) { // If first or last vertex is removed, re-sync the last/first vertex // Do not use "n - 2", but "ring->numPoints() - 1" as more than one vertex // may have been deleted (e.g. with CircularString) if ( vId.vertex == 0 ) ring->moveVertex( QgsVertexId( 0, 0, ring->numPoints() - 1 ), ring->vertexAt( QgsVertexId( 0, 0, 0 ) ) ); else if ( vId.vertex == n - 1 ) ring->moveVertex( QgsVertexId( 0, 0, 0 ), ring->vertexAt( QgsVertexId( 0, 0, ring->numPoints() - 1 ) ) ); clearCache(); } return success; }
bool QgsCurvePolygon::moveVertex( QgsVertexId vId, const QgsPoint &newPos ) { if ( !mExteriorRing || vId.ring < 0 || vId.ring >= 1 + mInteriorRings.size() ) { return false; } QgsCurve *ring = vId.ring == 0 ? mExteriorRing.get() : mInteriorRings.at( vId.ring - 1 ); int n = ring->numPoints(); bool success = ring->moveVertex( vId, newPos ); if ( success ) { // If first or last vertex is moved, also move the last/first vertex if ( vId.vertex == 0 ) ring->moveVertex( QgsVertexId( vId.part, vId.ring, n - 1 ), newPos ); else if ( vId.vertex == n - 1 ) ring->moveVertex( QgsVertexId( vId.part, vId.ring, 0 ), newPos ); clearCache(); } return success; }