Skip to content

Commit

Permalink
Add additional check if the transformation was valid.
Browse files Browse the repository at this point in the history
  • Loading branch information
erykoff committed Oct 2, 2023
1 parent 4aebff2 commit fef4809
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/geom/SpanSet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,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 fef4809

Please sign in to comment.