Example #1
0
        public void ContainsPointCases(int x, int y, int z, bool shouldPass)
        {
            var point = new Point3Int(x, y, z);
            var box   = new BoundingCuboid(new Point3Int(-1, -1, -1), new Point3Int(1, 1, 1));

            Assert.AreEqual(shouldPass, box.ContainsPoint(point));
        }
        public void DontAddPoint()
        {
            var ut    = new OctTree <object>(BoundingCuboid.Max, 10, new SimpleOctTreeDivisionStrategy <object>());
            var point = new Point3Int <object>(Point3Int.Zero, new object());

            Assert.IsFalse(ut.Points.Contains(point));
        }
Example #3
0
        public void AssertValuesHold(int llx, int lly, int llz, int urx, int ury, int urz)
        {
            var lowerLeft  = new Point3Int(llx, lly, llz);
            var upperRight = new Point3Int(urx, ury, urz);

            var ut = new BoundingCuboid(lowerLeft, upperRight);

            Assert.AreEqual(lowerLeft, ut.LowerLeft);
            Assert.AreEqual(upperRight, ut.UpperRight);
        }
        public void AddAPointAssertExists(int x, int y, int z)
        {
            var ut        = new OctTree <object>(BoundingCuboid.Max, 10, new SimpleOctTreeDivisionStrategy <object>());
            var point3Int = new Point3Int(x, y, z);

            var point = new Point3Int <object>(point3Int, new object());

            ut.Add(point);

            Assert.Contains(point, ut.Points);
        }
Example #5
0
        public void BoundaryTests(int minx, int miny, int minz, int maxx, int maxy, int maxz, bool shouldPass)
        {
            var bottomLeft = new Point3Int(minx, miny, minz);
            var upperRight = new Point3Int(maxx, maxy, maxz);

            var ut = new BoundingCuboid(bottomLeft, upperRight);

            var box = new BoundingCuboid(new Point3Int(-2, -2, -2), new Point3Int(2, 2, 2));

            Assert.AreEqual(shouldPass, box.DoesBoundaryCuboidIntersect(ut));
        }
            public override bool Equals(Object obj)
            {
                // Check for null values and compare run-time types.
                if (obj == null || GetType() != obj.GetType())
                {
                    return(false);
                }

                Point3Int p = (Point3Int)obj;

                return((x == p.x) && (z == p.z) && (y == p.y));
            }
Example #7
0
        public void CenterTests(
            int minx, int miny, int minz,
            int maxx, int maxy, int maxz,
            int x, int y, int z,
            bool expected)
        {
            var ut     = new BoundingCuboid(new Point3Int(minx, miny, minz), new Point3Int(maxx, maxy, maxz));
            var point  = new Point3Int(x, y, z);
            var center = ut.CenterPoint();

            Assert.AreEqual(expected, point == center);
        }
Example #8
0
 public void AssertLowerLeftIsLessThanUpperRight(int llx, int lly, int llz, int urx, int ury, int urz, bool expectThrow)
 {
     if (expectThrow)
     {
         var lowerLeft  = new Point3Int(llx, lly, llz);
         var upperRight = new Point3Int(urx, ury, urz);
         // ReSharper disable once ObjectCreationAsStatement
         Assert.Throws <ArgumentOutOfRangeException>(() => new BoundingCuboid(lowerLeft, upperRight));
     }
     else
     {
         AssertValuesHold(llx, lly, llz, urx, ury, urz);
     }
 }
Example #9
0
            public bool Reverse_presice_to_map_coords(vec3 _precise)
            {
                try
                {
                    Point2Int _chunk   = new Point2Int(0, 0);
                    Point3Int _cubical = new Point3Int(0, 0, 0);

                    _chunk.x = (int)((_precise.x / (double)CubicalMemory.Cube.rangeOfTheEdge) / (double)CubicalMemory.Chunk.Width);
                    _chunk.z = (int)((_precise.z / (double)CubicalMemory.Cube.rangeOfTheEdge) / (double)CubicalMemory.Chunk.Length);

                    int x = (int)(_precise.x / (double)CubicalMemory.Cube.rangeOfTheEdge);
                    int z = (int)(_precise.z / (double)CubicalMemory.Cube.rangeOfTheEdge);
                    _cubical.y = (int)(_precise.y / (double)CubicalMemory.Cube.rangeOfTheEdge);

                    x -= _chunk.x * CubicalMemory.Chunk.Width;
                    z -= _chunk.z * CubicalMemory.Chunk.Length;

                    _cubical.x = x;
                    _cubical.z = z;

                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            for (int k = 0; k < 3; k++)
                            {
                                if (TryCheckByHeight(_chunk, new Point3Int(
                                                         _cubical.x - 1 + i,
                                                         _cubical.y - 1 + j,
                                                         _cubical.z - 1 + k
                                                         )))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
                return(false);
            }
        public void GetPointsInBoundingArea(int octMinX, int octMinY, int octMinZ, int octMaxX, int octMaxY, int octMaxZ,
                                            int boundaryMinX, int boundaryMinY, int boundaryMinZ, int boundaryMaxX, int boundaryMaxY, int boundaryMaxZ,
                                            int x, int y, int z,
                                            bool expected)
        {
            var octTreeBoundingBox = new BoundingCuboid(new Point3Int(octMinX, octMinY, octMinZ), new Point3Int(octMaxX, octMaxY, octMaxZ));

            var area = new BoundingCuboid(new Point3Int(boundaryMinX, boundaryMinY, boundaryMinZ), new Point3Int(boundaryMaxX, boundaryMaxY, boundaryMaxZ));

            var obj   = new object();
            var point = new Point3Int <object>(x, y, z, obj);

            var ut = new OctTree <object>(octTreeBoundingBox, 10, new SimpleOctTreeDivisionStrategy <object>());

            ut.Add(point);

            var points = new List <Point3Int <object> >();

            ut.GetPointsWithinBoundary(area, ref points);

            Assert.AreEqual(expected, points.Contains(point));
        }
 public static void CopyToFrom(ref Point3Int Output, Point3Int _Input)
 {
     Output.x = _Input.x;
     Output.y = _Input.y;
     Output.z = _Input.z;
 }
 public Point3Int(Point3Int input)
 {
     x = input.x; y = input.y; z = input.z;
 }
Example #13
0
            public void Exploding_Rewriter()
            {
                if (ExplosionCenter != null)
                {
                    Point2Int Bomb_chunk_position   = new Point2Int(0, 0);
                    Point3Int Bomb_cubical_position = new Point3Int(0, 0, 0);
                    Scene.SS.env.player.coords.Reverse_presice_to_map_coords(Bomb_precise_position, ref Bomb_chunk_position, ref Bomb_cubical_position);

                    int Range_of_chunk_explosion = (int)Projectile.settings.Explosion_radius;
                    //DataForDraw_ExplodingList.TemporalList.Clear();

                    int i = 0;
                    int j = 0;

                    int value = 0;
                    if ((value = Bomb_chunk_position.x - Range_of_chunk_explosion) > 0)
                    {
                        i = value;
                    }
                    else
                    {
                        i = 0;
                    }

                    for (; i < Scene.SS.env.cub_mem.world.World_as_Whole.Count() && i < Bomb_chunk_position.x + Range_of_chunk_explosion; i++)
                    {
                        if ((value = Bomb_chunk_position.z - Range_of_chunk_explosion) > 0)
                        {
                            j = value;
                        }
                        else
                        {
                            j = 0;
                        }

                        for (; j < Scene.SS.env.cub_mem.world.World_as_Whole[i].Count() && j < Bomb_chunk_position.z + Range_of_chunk_explosion; j++)
                        {
                            var XYworld = Scene.SS.env.cub_mem.world.World_as_Whole[i][j];

                            if (Math.Abs(XYworld.xz.x - Bomb_chunk_position.x) < Range_of_chunk_explosion &&
                                Math.Abs(XYworld.xz.z - Bomb_chunk_position.z) < Range_of_chunk_explosion)
                            {
                                foreach (var Xcube in XYworld.cubes)
                                {
                                    foreach (var XYcube in Xcube)
                                    {
                                        foreach (var XYZcube in XYcube)
                                        {
                                            if (XYZcube.IsFilled && !XYZcube.IsTakenForExplosion)
                                            {
                                                ShaderedScene.CalculateFromMaptoGraphical(XYZcube, ref x, ref y, ref z);

                                                //POINT OF VIEWER
                                                vec3 range_to_cube = new vec3(0, 0, 0);
                                                range_to_cube.x = Bomb_precise_position.x - x;
                                                range_to_cube.y = Bomb_precise_position.y - y;
                                                range_to_cube.z = Bomb_precise_position.z - z;
                                                float range = GeneralProgrammingStuff.vec3_range(range_to_cube);

                                                if (range < CubicalMemory.Cube.rangeOfTheEdge * Projectile.settings.Explosion_radius)
                                                {
                                                    XYZcube.FallingStartingTime = Explosion.exp.StartingTime;
                                                    DataForDraw_ExplodingList.TemporalList.Add(XYZcube);
                                                    //Draw_Quad_Full_Sunsided_not_angled(x, y, z, localed_range, XYZcube.color);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    ExplosionCenter.IsTakenForExplosion = true;
                }
            }
        public void SubDivide(Point3Int <T>[] existingPoints,
                              Point3Int <T> newPoint,
                              BoundingCuboid boundary,
                              out OctTree <T> tlf,
                              out OctTree <T> trf,
                              out OctTree <T> tlb,
                              out OctTree <T> trb,
                              out OctTree <T> blf,
                              out OctTree <T> brf,
                              out OctTree <T> blb,
                              out OctTree <T> brb)
        {
            int maxItems = existingPoints.Length;
            var center   = boundary.CenterPoint();

            //blf
            var minBlf = boundary.LowerLeft;
            var mzxBlf = center;

            blf = new OctTree <T>(new BoundingCuboid(minBlf, mzxBlf), maxItems, this);

            //brf
            var minBrf = new Point3Int(center.X, boundary.LowerLeft.Y, boundary.LowerLeft.Z);
            var maxBrf = new Point3Int(boundary.UpperRight.X, center.Y, center.Z);

            brf = new OctTree <T>(new BoundingCuboid(minBrf, maxBrf), maxItems, this);

            //blb
            var minBlb = new Point3Int(boundary.LowerLeft.X, boundary.LowerLeft.Y, center.Z);
            var maxBlb = new Point3Int(center.X, center.Y, boundary.UpperRight.Z);

            blb = new OctTree <T>(new BoundingCuboid(minBlb, maxBlb), maxItems, this);

            //brb
            var minBrb = new Point3Int(center.X, boundary.LowerLeft.Y, center.Z);
            var maxBrb = new Point3Int(boundary.UpperRight.X, center.Y, boundary.UpperRight.Z);

            brb = new OctTree <T>(new BoundingCuboid(minBrb, maxBrb), maxItems, this);

            //tlf
            var minTlf = new Point3Int(boundary.LowerLeft.X, center.Y, boundary.LowerLeft.Z);
            var maxTlf = new Point3Int(center.X, boundary.UpperRight.Y, center.Z);

            tlf = new OctTree <T>(new BoundingCuboid(minTlf, maxTlf), maxItems, this);

            //trf
            var minTrf = new Point3Int(center.X, center.Y, boundary.LowerLeft.Z);
            var maxTrf = new Point3Int(boundary.UpperRight.X, boundary.UpperRight.Y, center.Z);

            trf = new OctTree <T>(new BoundingCuboid(minTrf, maxTrf), maxItems, this);

            //tlb
            var minTlb = new Point3Int(boundary.LowerLeft.X, center.Y, center.Z);
            var maxTlb = new Point3Int(center.X, boundary.UpperRight.Y, boundary.UpperRight.Z);

            tlb = new OctTree <T>(new BoundingCuboid(minTlb, maxTlb), maxItems, this);

            //trb
            var minTrb = center;
            var maxTrb = boundary.UpperRight;

            trb = new OctTree <T>(new BoundingCuboid(minTrb, maxTrb), maxItems, this);

            foreach (var point3Int in existingPoints)
            {
                AddPoint(blf, brf, blb, brb, tlf, trf, tlb, trb, point3Int, center);
            }

            AddPoint(blf, brf, blb, brb, tlf, trf, tlb, trb, newPoint, center);
        }
Example #15
0
            /// <summary>
            /// Recalculate coordinates from player graphic position to chunk & cubical position.
            /// </summary>
            public void Reverse_presice_to_map_coords(Point3D _precise, ref Point2Int _chunk, ref Point3Int _cubical)
            {
                _chunk.x = (int)((_precise.x / (double)CubicalMemory.Cube.rangeOfTheEdge) / (double)CubicalMemory.Chunk.Width);
                _chunk.z = (int)((_precise.z / (double)CubicalMemory.Cube.rangeOfTheEdge) / (double)CubicalMemory.Chunk.Length);

                int x = (int)(_precise.x / (double)CubicalMemory.Cube.rangeOfTheEdge);
                int z = (int)(_precise.z / (double)CubicalMemory.Cube.rangeOfTheEdge);

                _cubical.y = (int)(_precise.y / (double)CubicalMemory.Cube.rangeOfTheEdge);

                x -= _chunk.x * CubicalMemory.Chunk.Width;
                z -= _chunk.z * CubicalMemory.Chunk.Length;

                _cubical.x = x;
                _cubical.z = z;
            }
Example #16
0
            public bool TryCheckByHeight(Point2Int _chunk, Point3Int _cubical)
            {
                if (_cubical.x < 0)
                {
                    if (_chunk.x > 1)
                    {
                        _chunk.x--;
                        _cubical.x = CubicalMemory.Chunk.Width - 1;
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (_cubical.z < 0)
                {
                    if (_chunk.z > 1)
                    {
                        _chunk.z--;
                        _cubical.z = CubicalMemory.Chunk.Length - 1;
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (_cubical.y < 0 || _cubical.y >= CubicalMemory.Chunk.Height)
                {
                    return(false);
                }
                if (_cubical.x >= CubicalMemory.Chunk.Width)
                {
                    if (_chunk.x < CubicalMemory.World.Quantity_of_chunks_in_root - 1)
                    {
                        _chunk.x++;
                        _cubical.x = 0;
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (_cubical.z >= CubicalMemory.Chunk.Width)
                {
                    if (_chunk.z < CubicalMemory.World.Quantity_of_chunks_in_root - 1)
                    {
                        _chunk.z++;
                        _cubical.z = 0;
                    }
                    else
                    {
                        return(false);
                    }
                }

                try
                {
                    if (Scene.SS.env.cub_mem.world.World_as_Whole[_chunk.x][_chunk.z].cubes[_cubical.x][_cubical.y][_cubical.z].IsFilled &&
                        !Scene.SS.env.cub_mem.world.World_as_Whole[_chunk.x][_chunk.z].cubes[_cubical.x][_cubical.y][_cubical.z].IsTakenForExplosion)
                    {
                        return(true);
                    }
                }
                catch (Exception) { }
                return(false);
            }
        public void AddPointsExceedCapacityAssertEndUpInRightOct()
        {
            var obj = new object();
            var blf = new Point3Int <object>(-2, -2, -2, obj);
            var brf = new Point3Int <object>(2, -2, -2, obj);

            var blb = new Point3Int <object>(-2, -2, 2, obj);
            var brb = new Point3Int <object>(2, -2, 2, obj);

            var ulf = new Point3Int <object>(-2, 2, -2, obj);
            var urf = new Point3Int <object>(2, 2, -2, obj);

            var ulb = new Point3Int <object>(-2, 2, 2, obj);
            var urb = new Point3Int <object>(2, 2, 2, obj);

            var magicNumber9 = new Point3Int <object>(0, 0, 0, obj);

            var ut = new OctTree <object>(BoundingCuboid.Max, 8, new SimpleOctTreeDivisionStrategy <object>());

            ut.Add(blf);
            ut.Add(brf);
            ut.Add(blb);
            ut.Add(brb);
            ut.Add(ulf);
            ut.Add(urf);
            ut.Add(ulb);
            ut.Add(urb);

            Assert.IsNotNull(ut.Points);
            Assert.AreEqual(8, ut.Points.Length);
            Assert.IsNull(ut.ULF);
            Assert.IsNull(ut.URF);
            Assert.IsNull(ut.ULB);
            Assert.IsNull(ut.URB);
            Assert.IsNull(ut.BLF);
            Assert.IsNull(ut.BRF);
            Assert.IsNull(ut.BLB);
            Assert.IsNull(ut.BRB);

            ut.Add(magicNumber9);

            Assert.IsNull(ut.Points);
            Assert.IsNotNull(ut.ULF);
            Assert.IsNotNull(ut.URF);
            Assert.IsNotNull(ut.ULB);
            Assert.IsNotNull(ut.URB);
            Assert.IsNotNull(ut.BLF);
            Assert.IsNotNull(ut.BRF);
            Assert.IsNotNull(ut.BLB);
            Assert.IsNotNull(ut.BRB);

            Assert.IsTrue(ut.BLF.Points.Contains(blf));
            Assert.Contains(brf, ut.BRF.Points);
            Assert.Contains(blb, ut.BLB.Points);
            Assert.Contains(brb, ut.BRB.Points);

            Assert.Contains(urf, ut.URF.Points);
            Assert.Contains(ulf, ut.ULF.Points);
            Assert.Contains(ulb, ut.ULB.Points);
            Assert.Contains(urb, ut.URB.Points);

            Assert.Contains(magicNumber9, ut.BLF.Points);
        }
        private void AddPoint(OctTree <T> blf, OctTree <T> brf, OctTree <T> blb, OctTree <T> brb, OctTree <T> tlf, OctTree <T> trf, OctTree <T> tlb, OctTree <T> trb, Point3Int <T> point, Point3Int center)
        {
            // is on right side
            var point3Int = point.Point;

            if (point3Int.X > center.X)
            {
                // is on top side
                if (point3Int.Y > center.Y)
                {
                    // is on the backside
                    if (point3Int.Z > center.Z)
                    {
                        trb.Add(point);
                    }
                    else
                    {
                        trf.Add(point);
                    }
                }
                else // is on bottom side
                {
                    // is on the backside
                    if (point3Int.Z > center.Z)
                    {
                        brb.Add(point);
                    }
                    else
                    {
                        brf.Add(point);
                    }
                }
            }
            else // is on left side
            {
                // is on top side
                if (point3Int.Y > center.Y)
                {
                    // is on the backside
                    if (point3Int.Z > center.Z)
                    {
                        tlb.Add(point);
                    }
                    else
                    {
                        tlf.Add(point);
                    }
                }
                else // is on bottom side
                {
                    // is on the backside
                    if (point3Int.Z > center.Z)
                    {
                        blb.Add(point);
                    }
                    else
                    {
                        blf.Add(point);
                    }
                }
            }
        }