private static void TestIntervalOps(R2Rect x, R2Rect y, string expected_rexion, R2Rect expected_union, R2Rect expected_intersection) { // Test all of the interval operations on the given pair of intervals. // "expected_rexion" is a sequence of "T" and "F" characters corresponding // to the expected results of Contains(), InteriorContains(), Intersects(), // and InteriorIntersects() respectively. Assert.Equal(expected_rexion[0] == 'T', x.Contains(y)); Assert.Equal(expected_rexion[1] == 'T', x.InteriorContains(y)); Assert.Equal(expected_rexion[2] == 'T', x.Intersects(y)); Assert.Equal(expected_rexion[3] == 'T', x.InteriorIntersects(y)); Assert.Equal(x.Union(y) == x, x.Contains(y)); Assert.Equal(!x.Intersection(y).IsEmpty(), x.Intersects(y)); Assert.Equal(expected_union, x.Union(y)); Assert.Equal(expected_intersection, x.Intersection(y)); R2Rect r = x; r = r.AddRect(y); Assert.Equal(expected_union, r); if (y.GetSize() == new R2Point(0, 0)) { r = x; r = r.AddPoint(y.Lo()); Assert.Equal(expected_union, r); } }
// Given a point P representing a possibly clipped endpoint A of an edge AB, // verify that "clip" contains P, and that if clipping occurred (i.e., P != A) // then P is on the boundary of "clip". private static void CheckPointOnBoundary(R2Point p, R2Point a, R2Rect clip) { Assert.True(clip.Contains(p)); if (p != a) { Assert.False(clip.Contains(new R2Point(MathUtils.NextAfter(p[0], a[0]), MathUtils.NextAfter(p[1], a[1])))); } }