From 95cf2c269f53bc30d67b17cfbda668fd31d2494f Mon Sep 17 00:00:00 2001 From: Nate Lust Date: Wed, 5 Feb 2020 14:46:41 -0600 Subject: [PATCH] Fix SpanSet Creation from large circles Fix an issue where data-types were not large enough to hold values that may be plausibly used. --- src/geom/SpanSet.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/geom/SpanSet.cc b/src/geom/SpanSet.cc index 4ade011621..02b98f363a 100644 --- a/src/geom/SpanSet.cc +++ b/src/geom/SpanSet.cc @@ -691,9 +691,13 @@ std::shared_ptr SpanSet::fromShape(int r, Stencil s, lsst::geom::Point2 tempVec.reserve(2 * r + 1); switch (s) { case Stencil::CIRCLE: - for (auto dy = -r; dy <= r; ++dy) { - int dx = static_cast(sqrt(r * r - dy * dy)); - tempVec.emplace_back(dy + offset.getY(), -dx + offset.getX(), dx + offset.getX()); + { + double dr = static_cast(r); + dr *= dr; + for (auto dy = std::make_pair(-r, -r); dy.first <= r; ++dy.first, ++dy.second) { + int dx = static_cast(sqrt(dr-(dy.second*dy.second))); + tempVec.emplace_back(dy.first + offset.getY(), -dx + offset.getX(), dx + offset.getX()); + } } break; case Stencil::MANHATTAN: