Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix endless loop on curve linearization with maxdistance tolerance hi…
…gher than arc radius (#31838)

* Test curve linearization with higher than sagitta tolerance
* segmentizeArc: keep max distance tolerance below twice the radius

Fixes #31832
  • Loading branch information
strk committed Sep 17, 2019
1 parent 68a7805 commit 6942b4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/core/geometry/qgsgeometryutils.cpp
Expand Up @@ -910,6 +910,8 @@ void QgsGeometryUtils::segmentizeArc( const QgsPoint &p1, const QgsPoint &p2, co
double increment = tolerance; //one segment per degree
if ( toleranceType == QgsAbstractGeometry::MaximumDifference )
{
// Ensure tolerance is not higher than twice the radius
tolerance = std::min( tolerance, radius * 2 );
double halfAngle = std::acos( -tolerance / radius + 1 );
increment = 2 * halfAngle;
}
Expand Down
7 changes: 6 additions & 1 deletion tests/src/core/testqgscurve.cpp
Expand Up @@ -2,7 +2,7 @@
testqgscurve.cpp
--------------------------------------
Date : 21 July 2017
Copyright : (C) 2017 by Sandro Santilli
Copyright : (C) 2017-2019 by Sandro Santilli
Email : strk @ kbt.io
***************************************************************************
* *
Expand Down Expand Up @@ -92,6 +92,11 @@ void TestQgsCurve::curveToLine()
TEST_C2L( circularString, 10, QgsAbstractGeometry::MaximumDifference,
"LineString (0 0, 29.29 70.71, 100 100, 170.71 70.71, 200 0)", 2 );

/* op: Maximum of 300 units (higher than sagitta) of difference, symmetric */
/* See https://github.com/qgis/QGIS/issues/31832 */
TEST_C2L( circularString, 300, QgsAbstractGeometry::MaximumDifference,
"LineString (0 0, 200 0)", 2 );

/* op: Maximum of M_PI / 8 degrees of angle, (a)symmetric */
/* See https://github.com/qgis/QGIS/issues/24616 */
TEST_C2L( circularString, M_PI / 8, QgsAbstractGeometry::MaximumAngle,
Expand Down

0 comments on commit 6942b4b

Please sign in to comment.