Skip to content

Commit 4da787f

Browse files
zmerlynnclaude
andcommitted
Fuzz-class fix: scale TranslationInvariance area tol with |translate|
With position-inclusive eps (InferEps uses bBox.Scale()), vertex snapping at large translations changes area in either direction - not just shrinkage. The prior EXPECT_LE was wrong; switching back to EXPECT_NEAR with a tol that scales with |translate|: O(N * eps * edge_length) = O(|translate| * 1e-7), so 1e-6 * (1 + rawArea + |tx| + |ty|) provides a 7.5x+ margin. NumContour stays one-sided (EXPECT_LE): larger eps can only merge features, never invent new contours. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a4045b1 commit 4da787f

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

test/cross_section_fuzz.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -941,11 +941,14 @@ void TranslationInvariance(const std::vector<double>& radii, double translateX,
941941
ExpectCrossSectionValid(shifted);
942942

943943
// With position-inclusive eps (InferEps uses bBox.Scale()), far-from-origin
944-
// polygons have larger eps, which can merge thin features. These are
945-
// one-sided checks: eps merging can only shrink area and drop contours,
946-
// never invent area or add contours.
947-
const double tol = 1e-6 * (1.0 + std::fabs(rawArea));
948-
EXPECT_LE(shifted.Area(), rawArea + tol);
944+
// polygons have larger eps. Vertex snapping near the origin changes area by
945+
// O(N * eps * edge_length) = O(|translate| * 1e-7), and the direction is
946+
// not monotone (snapping can increase or decrease area). The tol scales with
947+
// |translate| to cover this: at |t| = 1e3, tol ~ 2e-3; at 1e9, tol ~ 1e3.
948+
// NumContour is one-sided: larger eps can only merge features, never invent.
949+
const double tol = 1e-6 * (1.0 + std::fabs(rawArea) + std::fabs(translateX) +
950+
std::fabs(translateY));
951+
EXPECT_NEAR(shifted.Area(), rawArea, tol);
949952
EXPECT_LE(shifted.NumContour(), base.NumContour());
950953
}
951954

0 commit comments

Comments
 (0)