Example #1
0
    public void Test_S1IntervalTestBase_ConstructorsAndAccessors()
    {
        // Spot-check the constructors and accessors.
        Assert.Equal(0, quad12.Lo);
        Assert.Equal(quad12.Hi, Math.PI);
        Assert.Equal(quad34[0], Math.PI);
        Assert.Equal(0, quad34[1]);
        Assert.Equal(quad34.Bounds(), new R2Point(Math.PI, 0).Bounds());
        Assert.Equal(pi.Lo, Math.PI);
        Assert.Equal(pi.Hi, Math.PI);

        // Check that [-Pi, -Pi] is normalized to [Pi, Pi].
        Assert.Equal(mipi.Lo, Math.PI);
        Assert.Equal(mipi.Hi, Math.PI);
        Assert.Equal(quad23.Lo, S2.M_PI_2);
        Assert.Equal(quad23.Hi, -S2.M_PI_2);

        // Check that the default S1Interval is identical to Empty().
        S1Interval default_empty = S1Interval.Empty;

        Assert.True(default_empty.IsValid());
        Assert.True(default_empty.IsEmpty());
        Assert.Equal(empty.Lo, default_empty.Lo);
        Assert.Equal(empty.Hi, default_empty.Hi);
    }
Example #2
0
 public void Test_S1IntervalTestBase_SimplePredicates()
 {
     // is_valid(), IsEmpty, IsFull, IsInverted
     Assert.True(zero.IsValid() && !zero.IsEmpty() && !zero.IsFull());
     Assert.True(empty.IsValid() && empty.IsEmpty() && !empty.IsFull());
     Assert.True(empty.IsInverted());
     Assert.True(full.IsValid() && !full.IsEmpty() && full.IsFull());
     Assert.True(!quad12.IsEmpty() && !quad12.IsFull() && !quad12.IsInverted());
     Assert.True(!quad23.IsEmpty() && !quad23.IsFull() && quad23.IsInverted());
     Assert.True(pi.IsValid() && !pi.IsEmpty() && !pi.IsInverted());
     Assert.True(mipi.IsValid() && !mipi.IsEmpty() && !mipi.IsInverted());
 }
Example #3
0
    // Returns the minimum distance from X to the latitude line segment defined by
    // the given latitude and longitude interval.
    private static S1Angle GetDistance(S2LatLng x, S1Angle lat, S1Interval interval)
    {
        Assert.True(x.IsValid());
        Assert.True(interval.IsValid());

        // Is X inside the longitude interval?
        if (interval.Contains(x.LngRadians))
        {
            return(S1Angle.FromRadians((x.Lat() - lat).Abs()));
        }

        // Return the distance to the closer endpoint.
        return(new[] { x.GetDistance(new S2LatLng(lat, S1Angle.FromRadians(interval.Lo))),
                       x.GetDistance(new S2LatLng(lat, S1Angle.FromRadians(interval.Hi))) }.Min());
    }