Skip to content

Commit

Permalink
more efficient and reliable wedgebuffer calculation
Browse files Browse the repository at this point in the history
(cherry-picked from 5c285aa)
  • Loading branch information
raymondnijssen authored and nyalldawson committed Aug 9, 2018
1 parent 829a983 commit 99de233
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/core/geometry/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,28 +262,40 @@ QgsGeometry QgsGeometry::createWedgeBuffer( const QgsPoint &center, const double
{
if ( angularWidth >= 360.0 )
{
std::unique_ptr< QgsCompoundCurve > outer = qgis::make_unique< QgsCompoundCurve >();
std::unique_ptr< QgsCompoundCurve > outerCc = qgis::make_unique< QgsCompoundCurve >();

const QgsPoint outerP1 = center.project( outerRadius, azimuth );
const QgsPoint outerP2 = center.project( outerRadius, azimuth + 180.0 );
QgsPointSequence outerPs = QgsPointSequence()
<< QgsPoint( center.x(), center.y() + outerRadius )
<< QgsPoint( center.x() + outerRadius, center.y() )
<< QgsPoint( center.x(), center.y() - outerRadius )
<< QgsPoint( center.x() - outerRadius, center.y() )
<< QgsPoint( center.x(), center.y() + outerRadius );

outer->addCurve( new QgsCircularString( QgsCircularString::fromTwoPointsAndCenter( outerP1, outerP2, center ) ) );
outer->addCurve( new QgsCircularString( QgsCircularString::fromTwoPointsAndCenter( outerP2, outerP1, center ) ) );
QgsCircularString *outerCs = new QgsCircularString;
outerCs->setPoints( outerPs );

outerCc->addCurve( outerCs );

std::unique_ptr< QgsCurvePolygon > cp = qgis::make_unique< QgsCurvePolygon >();
cp->setExteriorRing( outer.release() );
cp->setExteriorRing( outerCc.release() );

if ( !qgsDoubleNear( innerRadius, 0.0 ) && innerRadius > 0 )
{
std::unique_ptr< QgsCompoundCurve > inner = qgis::make_unique< QgsCompoundCurve >();
std::unique_ptr< QgsCompoundCurve > innerCc = qgis::make_unique< QgsCompoundCurve >();

QgsPointSequence innerPs = QgsPointSequence()
<< QgsPoint( center.x(), center.y() + innerRadius )
<< QgsPoint( center.x() + innerRadius, center.y() )
<< QgsPoint( center.x(), center.y() - innerRadius )
<< QgsPoint( center.x() - innerRadius, center.y() )
<< QgsPoint( center.x(), center.y() + innerRadius );

const QgsPoint innerP1 = center.project( innerRadius, azimuth );
const QgsPoint innerP2 = center.project( innerRadius, azimuth + 180.0 );
QgsCircularString *innerCs = new QgsCircularString;
innerCs->setPoints( innerPs );

inner->addCurve( new QgsCircularString( QgsCircularString::fromTwoPointsAndCenter( innerP1, innerP2, center ) ) );
inner->addCurve( new QgsCircularString( QgsCircularString::fromTwoPointsAndCenter( innerP2, innerP1, center ) ) );
innerCc->addCurve( innerCs );

cp->setInteriorRings( { inner.release() } );
cp->setInteriorRings( { innerCc.release() } );
}

return QgsGeometry( std::move( cp ) );
Expand Down Expand Up @@ -3256,3 +3268,4 @@ QDataStream &operator>>( QDataStream &in, QgsGeometry &geometry )
geometry.fromWkb( byteArray );
return in;
}

0 comments on commit 99de233

Please sign in to comment.