Skip to content

Commit

Permalink
Merge pull request #711 from lsst/tickets/DM-41012
Browse files Browse the repository at this point in the history
DM-41012: Check for empty spanset prior to trying to transform it
  • Loading branch information
erykoff authored Oct 4, 2023
2 parents dc60f39 + 7a34743 commit 29afe69
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/geom/SpanSet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,12 @@ std::shared_ptr<SpanSet> SpanSet::transformedBy(lsst::geom::AffineTransform cons
}

std::shared_ptr<SpanSet> SpanSet::transformedBy(TransformPoint2ToPoint2 const& t) const {
// If the SpanSet is empty, its bounding box corners are not
// meaningful and cannot be transformed.
if (_spanVector.empty()) {
return std::make_shared<SpanSet>();
}

// Transform points in SpanSet by Transform<Point2Endpoint, Point2Endpoint>
// Transform the original bounding box
lsst::geom::Box2D newBBoxD;
Expand All @@ -857,6 +863,18 @@ std::shared_ptr<SpanSet> SpanSet::transformedBy(TransformPoint2ToPoint2 const& t
fromCorners.emplace_back(lsst::geom::Point2D(fc));
}
auto toPoints = t.applyForward(fromCorners);

// Check that this was a valid transformation.
// Inverses should be good to floating point precision, this is just
// a very rough check.
auto fromToPoints = t.applyInverse(toPoints);
for (int i = 0; i < 4; ++i) {
if ((std::abs(fromToPoints[i].getX() - fromCorners[i].getX()) > 1.0) ||
(std::abs(fromToPoints[i].getY() - fromCorners[i].getY()) > 1.0)) {
return std::make_shared<SpanSet>();
}
}

for (auto const& tc : toPoints) {
newBBoxD.include(tc);
}
Expand Down

0 comments on commit 29afe69

Please sign in to comment.