예제 #1
0
    public void AddNodeRelPos(Vector3Int a_position, byte depth, int type)
    {
        byte       depthcoord = (byte)(this.octreeSize / Math.Pow(2, depth));
        Vector3Int position   = new Vector3Int(a_position.x / depthcoord, a_position.y / depthcoord, a_position.z / depthcoord);

        this.octree.Add(olc.Vec3ToLoc(position, depth), type);
    }
예제 #2
0
    public void AddNodeRelPos(Vector3 position, byte depth, int type)
    {
        int boop = (int)this.octreesize / (2 * depth);

        position = new Vector3((int)Math.Floor(position.x) / boop, (int)Math.Floor(position.y) / boop, (int)Math.Floor(position.z) / boop);
        AddNodeLocID(olc.Vec3ToLoc(position, depth), type);
    }
    //Vec3ToLocTest3 - Manual Code Test
    public void Vec3ToLoc_Test3_CodeManual()
    {
        OT_LocCode lc = new OT_LocCode();

        long[] TestVec = { lc.Vec3ToLoc(new Vector3(0, 0, 0), 1), lc.Vec3ToLoc(new Vector3(1, 1, 1), 1),
                           lc.Vec3ToLoc(new Vector3(0, 0, 0), 2), lc.Vec3ToLoc(new Vector3(3, 3, 3), 2),
                           lc.Vec3ToLoc(new Vector3(4, 4, 4), 3), lc.Vec3ToLoc(new Vector3(1, 0, 0), 1),
                           lc.Vec3ToLoc(new Vector3(1, 0, 0), 2), lc.Vec3ToLoc(new Vector3(5, 6, 2), 3),lc.Vec3ToLoc(new Vector3(15,  15, 15), 4) };
        long[] TestAssert = { 8, 15, 64, 127, 960, 12, 68, 924, 8191 };
        CollectionAssert.AreEqual(TestAssert, TestVec);
    }
    //Vec3ToLoc_Test1 - Manual Depth Test
    //TODO: Finish Vec3toLoc() to work with depths 7 or higher.
    public void Vec3ToLoc_Test1_DepthManual()
    {
        OT_LocCode lc = new OT_LocCode();

        long[] TestVec = { lc.Vec3ToLoc(new Vector3(0, 0, 0), 0), lc.Vec3ToLoc(new Vector3(0, 0, 0), 1),
                           lc.Vec3ToLoc(new Vector3(0, 0, 0), 2), lc.Vec3ToLoc(new Vector3(0, 0, 0), 3),
                           lc.Vec3ToLoc(new Vector3(0, 0, 0), 4), lc.Vec3ToLoc(new Vector3(0, 0, 0), 5),
                           lc.Vec3ToLoc(new Vector3(0, 0, 0), 6) };
        long[] TestAssert = { 1, 8, 64, 512, 4096, 32768, 262144 };
        CollectionAssert.AreEqual(TestVec, TestAssert);
    }
    public void LocToVec3_Test2_VectorsRandom()
    {
        OT_LocCode lc = new OT_LocCode();

        System.Random rnd = new System.Random();
        for (int i = 0; i < 4681; i++)
        {
            byte    d          = Convert.ToByte(rnd.Next(1, 6));
            int     coordlimit = Convert.ToInt32(Math.Pow(2, d));
            int     valuelimit = Convert.ToInt32(Math.Pow(8, d));
            Vector3 vec        = new Vector3(rnd.Next(0, coordlimit),
                                             rnd.Next(0, coordlimit), rnd.Next(0, coordlimit));
            long n = lc.Vec3ToLoc(vec, d);
            Assert.AreEqual(vec, lc.LocToVec3(n));
        }
    }
    //TODO: Update Vec3ToLoc() for depths larger than 6.
    public void Vec3ToLoc_Test5_CodeRangesRandom()
    {
        OT_LocCode lc = new OT_LocCode();

        System.Random rnd = new System.Random();
        for (int i = 0; i < 4681; i++)
        {
            byte    d          = Convert.ToByte(rnd.Next(1, 6));
            int     coordlimit = Convert.ToInt32(Math.Pow(2, d));
            int     valuelimit = Convert.ToInt32(Math.Pow(8, d));
            Vector3 vec        = new Vector3(rnd.Next(0, coordlimit),
                                             rnd.Next(0, coordlimit), rnd.Next(0, coordlimit));
            long n = lc.Vec3ToLoc(vec, d);
            Assert.IsTrue(valuelimit <= n && n < valuelimit * 2);
        }
    }
    //Vec3ToLoc_Test2 - Random Depth Test
    //TODO: Finish Vec3toLoc() to work with depths 7 or higher.
    public void Vec3ToLoc_Test2_DepthRandom()
    {
        OT_LocCode lc = new OT_LocCode();

        System.Random rnd = new System.Random();
        for (int i = 0; i < 16; i++)
        {
            byte d = Convert.ToByte(rnd.Next(1, 6));
            long n = lc.Vec3ToLoc(new Vector3(0, 0, 0), d);
            if (d > 0)
            {
                Assert.AreEqual(n, Convert.ToInt32(Mathf.Pow(8, d)));
            }
            else
            {
                Assert.AreEqual(n, 0);
            }
        }
    }
 //TODO: CalculateAdjacent Offset Random, do negative values
 public void CalculateAdjacent_Test2_Offset1Random()
 {
     {
         OT_LocCode    lc  = new OT_LocCode();
         System.Random rnd = new System.Random();
         for (int i = 0; i < 4681; i++)
         {
             byte    d          = Convert.ToByte(rnd.Next(1, 6));
             int     coordlimit = Convert.ToInt32(Math.Pow(2, d));
             int     valuelimit = Convert.ToInt32(Math.Pow(8, d));
             Vector3 vec        = new Vector3(rnd.Next(0, coordlimit - 1),
                                              rnd.Next(0, coordlimit - 1), rnd.Next(0, coordlimit - 1));
             long    n    = lc.Vec3ToLoc(vec, d);
             Vector3 vec1 = (new Vector3(1, 0, 0) + vec);
             long    n1   = lc.Vec3ToLoc(vec1, d);
             long    a    = lc.CalculateAdjacent(n, 2, 1);
             Assert.IsTrue(n1 == a || a == n);
             vec1 = (new Vector3(-1, 0, 0) + vec);
             n1   = lc.Vec3ToLoc(vec1, d);
             a    = lc.CalculateAdjacent(n, 2, -1);
             Assert.IsTrue(n1 == a || a == n);
             vec1 = (new Vector3(0, 1, 0) + vec);
             n1   = lc.Vec3ToLoc(vec1, d);
             a    = lc.CalculateAdjacent(n, 1, 1);
             Assert.IsTrue(n1 == a || a == n);;
             vec1 = (new Vector3(0, -1, 0) + vec);
             n1   = lc.Vec3ToLoc(vec1, d);
             a    = lc.CalculateAdjacent(n, 1, -1);
             Assert.IsTrue(n1 == a || a == n);
             vec1 = (new Vector3(0, 0, 1) + vec);
             n1   = lc.Vec3ToLoc(vec1, d);
             a    = lc.CalculateAdjacent(n, 0, 1);
             Assert.IsTrue(n1 == a || a == n);
             vec1 = (new Vector3(0, 0, -1) + vec);
             n1   = lc.Vec3ToLoc(vec1, d);
             a    = lc.CalculateAdjacent(n, 0, -1);
             Assert.IsTrue(n1 == a || a == n);
         }
     }
 }