private static void TestIntervalOps(S1Interval x, S1Interval y, string expected_relation, S1Interval expected_union, S1Interval expected_intersection) { // Test all of the interval operations on the given pair of intervals. // "expected_relation" is a sequence of "T" and "F" characters corresponding // to the expected results of Contains(), InteriorContains(), Intersects(), // and InteriorIntersects() respectively. Assert.Equal(x.Contains(y), expected_relation[0] == 'T'); Assert.Equal(x.InteriorContains(y), expected_relation[1] == 'T'); Assert.Equal(x.Intersects(y), expected_relation[2] == 'T'); Assert.Equal(x.InteriorIntersects(y), expected_relation[3] == 'T'); // bounds() returns a reference to a member variable, so we need to // make a copy when invoking it on a temporary object. Assert.Equal(R2Point.FromCoords(x.Union(y).Bounds()).Bounds(), expected_union.Bounds()); Assert.Equal(R2Point.FromCoords(x.Intersection(y).Bounds()).Bounds(), expected_intersection.Bounds()); Assert.Equal(x.Contains(y), x.Union(y) == x); Assert.Equal(x.Intersects(y), !x.Intersection(y).IsEmpty()); if (y.Lo == y.Hi) { var r = S1Interval.AddPoint(x, y.Lo); Assert.Equal(r.Bounds(), expected_union.Bounds()); } }
public void Test_S1IntervalTestBase_AddPoint() { Assert.Equal(zero, S1Interval.AddPoint(empty, 0)); Assert.Equal(pi, S1Interval.AddPoint(empty, Math.PI)); Assert.Equal(mipi, S1Interval.AddPoint(empty, -Math.PI)); Assert.Equal(pi, S1Interval.AddPoints(empty, Math.PI, -Math.PI)); Assert.Equal(mipi, S1Interval.AddPoints(empty, -Math.PI, Math.PI)); Assert.Equal(mid12, S1Interval.AddPoints(empty, mid12.Lo, mid12.Hi)); Assert.Equal(mid23, S1Interval.AddPoints(empty, mid23.Lo, mid23.Hi)); Assert.Equal(quad123, S1Interval.AddPoints(quad1, -0.9 * Math.PI, -S2.M_PI_2)); Assert.True(S1Interval.AddPoint(full, 0).IsFull()); Assert.True(S1Interval.AddPoint(full, Math.PI).IsFull()); Assert.True(S1Interval.AddPoint(full, -Math.PI).IsFull()); }