Exemple #1
0
 public void Test_S1IntervalTestBase_Contains()
 {
     // Contains(double), InteriorContains(double)
     Assert.True(!empty.Contains(0) && !empty.Contains(Math.PI) &&
                 !empty.Contains(-Math.PI));
     Assert.True(!empty.InteriorContains(Math.PI) && !empty.InteriorContains(-Math.PI));
     Assert.True(full.Contains(0) && full.Contains(Math.PI) && full.Contains(-Math.PI));
     Assert.True(full.InteriorContains(Math.PI) && full.InteriorContains(-Math.PI));
     Assert.True(quad12.Contains(0) && quad12.Contains(Math.PI) &&
                 quad12.Contains(-Math.PI));
     Assert.True(quad12.InteriorContains(S2.M_PI_2) && !quad12.InteriorContains(0));
     Assert.True(!quad12.InteriorContains(Math.PI) &&
                 !quad12.InteriorContains(-Math.PI));
     Assert.True(quad23.Contains(S2.M_PI_2) && quad23.Contains(-S2.M_PI_2));
     Assert.True(quad23.Contains(Math.PI) && quad23.Contains(-Math.PI));
     Assert.True(!quad23.Contains(0));
     Assert.True(!quad23.InteriorContains(S2.M_PI_2) &&
                 !quad23.InteriorContains(-S2.M_PI_2));
     Assert.True(quad23.InteriorContains(Math.PI) && quad23.InteriorContains(-Math.PI));
     Assert.True(!quad23.InteriorContains(0));
     Assert.True(pi.Contains(Math.PI) && pi.Contains(-Math.PI) && !pi.Contains(0));
     Assert.True(!pi.InteriorContains(Math.PI) && !pi.InteriorContains(-Math.PI));
     Assert.True(mipi.Contains(Math.PI) && mipi.Contains(-Math.PI) && !mipi.Contains(0));
     Assert.True(!mipi.InteriorContains(Math.PI) && !mipi.InteriorContains(-Math.PI));
     Assert.True(zero.Contains(0) && !zero.InteriorContains(0));
 }
Exemple #2
0
    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());
        }
    }