bool QgsTriangle::moveVertex( QgsVertexId vId, const QgsPoint &newPos ) { if ( !mExteriorRing || vId.part != 0 || vId.ring != 0 || vId.vertex < 0 || vId.vertex > 4 ) { return false; } if ( vId.vertex == 4 ) { vId.vertex = 0; } QgsPoint p1( vId.vertex == 0 ? newPos : vertexAt( 0 ) ); QgsPoint p2( vId.vertex == 1 ? newPos : vertexAt( 1 ) ); QgsPoint p3( vId.vertex == 2 ? newPos : vertexAt( 2 ) ); if ( !validateGeom( p1, p2, p3 ) ) { return false; } int n = mExteriorRing->numPoints(); bool success = mExteriorRing->moveVertex( vId, newPos ); if ( success ) { // If first or last vertex is moved, also move the last/first vertex if ( vId.vertex == 0 ) mExteriorRing->moveVertex( QgsVertexId( vId.part, vId.ring, n - 1 ), newPos ); clearCache(); } return success; }
void QgsTriangle::setExteriorRing( QgsCurve *ring ) { if ( !ring ) { return; } if ( ring->hasCurvedSegments() ) { //need to segmentize ring as polygon does not support curves QgsCurve *line = ring->segmentize(); delete ring; ring = line; } if ( ( ring->numPoints() > 4 ) || ( ring->numPoints() < 3 ) ) { delete ring; return; } else if ( ring->numPoints() == 4 ) { if ( !ring->isClosed() ) { delete ring; return; } } else if ( ring->numPoints() == 3 ) { if ( ring->isClosed() ) { delete ring; return; } QgsLineString *lineString = static_cast< QgsLineString *>( ring ); if ( !lineString->isClosed() ) { lineString->close(); } ring = lineString; } if ( !validateGeom( ring->vertexAt( QgsVertexId( 0, 0, 0 ) ), ring->vertexAt( QgsVertexId( 0, 0, 1 ) ), ring->vertexAt( QgsVertexId( 0, 0, 2 ) ) ) ) { delete ring; return; } mExteriorRing.reset( ring ); //set proper wkb type setZMTypeFromSubGeometry( ring, QgsWkbTypes::Triangle ); clearCache(); }
QgsTriangle::QgsTriangle( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3 ) { mWkbType = QgsWkbTypes::Triangle; if ( !validateGeom( p1, p2, p3 ) ) { return; } QVector< double > x; x << p1.x() << p2.x() << p3.x(); QVector< double > y; y << p1.y() << p2.y() << p3.y(); QgsLineString *ext = new QgsLineString( x, y ); setExteriorRing( ext ); }
QgsTriangle::QgsTriangle( const QPointF p1, const QPointF p2, const QPointF p3 ) : QgsPolygonV2() { mWkbType = QgsWkbTypes::Triangle; QgsPointV2 pt1( p1 ); QgsPointV2 pt2( p2 ); QgsPointV2 pt3( p3 ); if ( !validateGeom( pt1, pt2, pt3 ) ) { return; } QVector< double > x; x << p1.x() << p2.x() << p3.x(); QVector< double > y; y << p1.y() << p2.y() << p3.y(); QgsLineString *ext = new QgsLineString( x, y ); setExteriorRing( ext ); }