Skip to content
Permalink
Browse files

more efficient and reliable wedgebuffer calculation

  • Loading branch information
raymondnijssen authored and nyalldawson committed Aug 8, 2018
1 parent 5121f72 commit 5c285aa0806861aef4c5d294392eba49cde24675
Showing with 25 additions and 12 deletions.
  1. +25 −12 src/core/geometry/qgsgeometry.cpp
@@ -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 ) );
@@ -3275,3 +3287,4 @@ QDataStream &operator>>( QDataStream &in, QgsGeometry &geometry )
geometry.fromWkb( byteArray );
return in;
}

0 comments on commit 5c285aa

Please sign in to comment.
You can’t perform that action at this time.