示例#1
0
    public void DistanceSquaredTest()
    {
        GridPosition origin = new GridPosition(0, 0, 0);
        GridPosition v1     = new GridPosition(2, 2, 2);
        GridPosition v2     = new GridPosition(-2, -2, -2);
        GridPosition v3     = new GridPosition(4, -3, 5);

        Assert.AreEqual(12, GridPosition.DistanceSquared(v1, origin), "#1");
        Assert.AreEqual(12, GridPosition.DistanceSquared(v2, origin), "#2");
        Assert.AreEqual(50, GridPosition.DistanceSquared(v3, origin), "#3");

        Assert.AreEqual(GridPosition.DistanceSquared(v1, origin),
                        GridPosition.DistanceSquared(v2, origin), "#4");
        Assert.AreEqual(GridPosition.DistanceSquared(v3, origin),
                        GridPosition.DistanceSquared(origin, v3), "#5");

        Assert.AreEqual(12, GridPosition.DistanceSquared(origin, v1), "#6");
        Assert.AreEqual(12, GridPosition.DistanceSquared(origin, v2), "#7");
        Assert.AreEqual(50, GridPosition.DistanceSquared(origin, v3), "#8");

        Assert.AreEqual(3, GridPosition.DistanceSquared(origin, GridPosition.One), "#9");
        Assert.AreEqual(0, GridPosition.DistanceSquared(v3, v3), "#10");
    }