Exemple #1
0
        public void ContainsCases(int x, int y, bool shouldPass)
        {
            var point = new Point2Int(x, y);
            var box   = new Bounding2DBox(new Point2Int(-1, -1), new Point2Int(1, 1));

            Assert.AreEqual(shouldPass, box.ContainsPoint(point));
        }
Exemple #2
0
        public void AddPointOutsideOfBoundary()
        {
            var ut    = new QuadTree(new Bounding2DBox(new Point2Int(-1, -1), new Point2Int(1, 1)), 10, new SimpleQuadTreeDivisionStrategy());
            var point = new Point2Int(10, 10);

            Assert.Throws <ArgumentOutOfRangeException>(() => ut.Add(point));
        }
Exemple #3
0
        public void SubDivide(Point2Int[] points, Point2Int newPoint, Bounding2DBox boundingBox, out QuadTree northWest, out QuadTree northEast, out QuadTree southWest, out QuadTree southEast)
        {
            int maxItems = points.Length;
            var center   = boundingBox.CenterPoint();

            var bottomLeftOfNorthWest = new Point2Int(boundingBox.LowerLeft.X, center.Y);
            var topRightOfNorthWest   = new Point2Int(center.X, boundingBox.UpperRight.Y);
            var bottomLeftOfNorthEast = center;
            var topRightOfNorthEast   = boundingBox.UpperRight;
            var bottomLeftOfSouthWest = boundingBox.LowerLeft;
            var topRightOfSouthWest   = center;
            var bottomLeftOfSouthEast = new Point2Int(center.X, boundingBox.LowerLeft.Y);
            var topRightOfSouthEast   = new Point2Int(boundingBox.UpperRight.X, center.Y);

            northWest = new QuadTree(new Bounding2DBox(bottomLeftOfNorthWest, topRightOfNorthWest), maxItems, this);
            northEast = new QuadTree(new Bounding2DBox(bottomLeftOfNorthEast, topRightOfNorthEast), maxItems, this);
            southWest = new QuadTree(new Bounding2DBox(bottomLeftOfSouthWest, topRightOfSouthWest), maxItems, this);
            southEast = new QuadTree(new Bounding2DBox(bottomLeftOfSouthEast, topRightOfSouthEast), maxItems, this);

            foreach (var point2Int in points)
            {
                AddPoint(northWest, northEast, southWest, southEast, point2Int, center);
            }

            AddPoint(northWest, northEast, southWest, southEast, newPoint, center);
        }
Exemple #4
0
        public void AssertValuesHold(int lx, int ly, int ux, int uy)
        {
            var bottomLeft = new Point2Int(lx, ly);
            var topRight   = new Point2Int(ux, uy);
            var ut         = new Bounding2DBox(bottomLeft, topRight);

            Assert.AreEqual(bottomLeft, ut.LowerLeft);
            Assert.AreEqual(topRight, ut.UpperRight);
        }
Exemple #5
0
        public void BoundaryTests(int minx, int miny, int maxx, int maxy, bool shouldPass)
        {
            var bottomLeft = new Point2Int(minx, miny);
            var topRight   = new Point2Int(maxx, maxy);

            var areaUnderTest = new Bounding2DBox(bottomLeft, topRight);
            var box           = new Bounding2DBox(new Point2Int(-1, -1), new Point2Int(1, 1));

            Assert.AreEqual(shouldPass, box.DoesBoundaryBoxIntersect(areaUnderTest));
        }
        public void CreatePoint2IntEnsureValuesCorrect()
        {
            int x = 234;
            int y = -564;

            var ut = new Point2Int(x, y);

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

                Point2Int p = (Point2Int)obj;

                return((x == p.x) && (z == p.z));
            }
Exemple #8
0
        public static Point2Int[] GetPoints(this Table table)
        {
            var points = new Point2Int[table.RowCount];

            for (int i = 0; i < table.RowCount; i++)
            {
                int x     = int.Parse(table.Rows[i]["x"]);
                int y     = int.Parse(table.Rows[i]["y"]);
                var point = new Point2Int(x, y);
                points[i] = point;
            }

            return(points);
        }
Exemple #9
0
        public void AssertThatBottomLeftisBottomLeftOfTopRight(int lx, int ly, int ux, int uy, bool expectThrow)
        {
            if (expectThrow)
            {
                var bottomLeft = new Point2Int(lx, ly);
                var topRight   = new Point2Int(ux, uy);

                // ReSharper disable once ObjectCreationAsStatement
                Assert.Throws <ArgumentOutOfRangeException>(() => new Bounding2DBox(bottomLeft, topRight));
            }
            else
            {
                AssertValuesHold(lx, ly, ux, uy);
            }
        }
Exemple #10
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;
            }
Exemple #11
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);
            }
Exemple #12
0
        public void PointInAreaAssert(
            int quadMinx, int quadMiny, int quadMaxx, int quadMaxy,
            int boundaryMinx, int boundaryMiny, int boundaryMaxx, int boundaryMaxy,
            int pointx, int pointy,
            bool expected)
        {
            var quadBoundingBox = new Bounding2DBox(new Point2Int(quadMinx, quadMiny), new Point2Int(quadMaxx, quadMaxy));
            var area            = new Bounding2DBox(new Point2Int(boundaryMinx, boundaryMiny), new Point2Int(boundaryMaxx, boundaryMaxy));

            var point = new Point2Int(pointx, pointy);

            var ut = new QuadTree(quadBoundingBox, 10, new SimpleQuadTreeDivisionStrategy());

            ut.Add(point);

            var points = new List <Point2Int>();

            ut.GetPointsInArea(area, ref points);

            Assert.AreEqual(expected, points.Contains(point));
        }
        public void CheckDefaultValuesareEmpty()
        {
            var ut = new Point2Int();

            Assert.AreEqual(Point2Int.Zero, ut);
        }
 public Point2Int(Point2Int input)
 {
     x = input.x; z = input.z;
 }
        public void WhenIAddAPointToTheQuadtreeAt(int x, int y)
        {
            var point = new Point2Int(x, y);

            _quadTree.Add(point);
        }
Exemple #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);
            }
Exemple #17
0
        public void AddMorePointsThanMaxAssertTheyEndUpInCorrectQuadrants()
        {
            var tl1 = new Point2Int(-10, 10);
            var tl2 = new Point2Int(-11, 10);
            var tl3 = new Point2Int(-12, 10);

            var tr1 = new Point2Int(10, 10);
            var tr2 = new Point2Int(10, 11);
            var tr3 = new Point2Int(10, 12);

            var bl1 = new Point2Int(-10, -10);
            var bl2 = new Point2Int(-10, -11);
            var bl3 = new Point2Int(-10, -12);

            var br1 = new Point2Int(10, -10);
            var br2 = new Point2Int(10, -11);
            var br3 = new Point2Int(10, -12);

            var number10 = new Point2Int(-10, 12);

            var ut = new QuadTree(Bounding2DBox.Max, 12, new SimpleQuadTreeDivisionStrategy());

            ut.Add(tl1);
            ut.Add(tl2);
            ut.Add(tl3);
            ut.Add(tr1);
            ut.Add(tr2);
            ut.Add(tr3);
            ut.Add(bl1);
            ut.Add(bl2);
            ut.Add(bl3);
            ut.Add(br1);
            ut.Add(br2);
            ut.Add(br3);

            Assert.IsNotNull(ut.Points);
            Assert.AreEqual(12, ut.Points.Length);
            Assert.IsNull(ut.NorthEast);
            Assert.IsNull(ut.NorthWest);
            Assert.IsNull(ut.SouthEast);
            Assert.IsNull(ut.SouthWest);

            ut.Add(number10);

            Assert.IsNull(ut.Points);
            Assert.IsNotNull(ut.NorthEast);
            Assert.IsNotNull(ut.NorthWest);
            Assert.IsNotNull(ut.SouthEast);
            Assert.IsNotNull(ut.SouthWest);

            Assert.IsTrue(ut.NorthEast.Points.Contains(tr1));
            Assert.IsTrue(ut.NorthEast.Points.Contains(tr2));
            Assert.IsTrue(ut.NorthEast.Points.Contains(tr3));

            Assert.IsTrue(ut.NorthWest.Contains(tl1));
            Assert.IsTrue(ut.NorthWest.Contains(tl2));
            Assert.IsTrue(ut.NorthWest.Contains(tl3));
            Assert.IsTrue(ut.NorthWest.Contains(number10));

            Assert.IsTrue(ut.SouthWest.Points.Contains(bl1));
            Assert.IsTrue(ut.SouthWest.Points.Contains(bl2));
            Assert.IsTrue(ut.SouthWest.Points.Contains(bl3));

            Assert.IsTrue(ut.SouthEast.Points.Contains(br1));
            Assert.IsTrue(ut.SouthEast.Points.Contains(br2));
            Assert.IsTrue(ut.SouthEast.Points.Contains(br3));
        }
Exemple #18
0
 /// <summary>
 /// Adds the point into the corrent quad
 /// </summary>
 /// <param name="northWest"></param>
 /// <param name="northEast"></param>
 /// <param name="southWest"></param>
 /// <param name="southEast"></param>
 /// <param name="point2Int"></param>
 /// <param name="center"></param>
 private static void AddPoint(QuadTree northWest, QuadTree northEast, QuadTree southWest, QuadTree southEast, Point2Int point2Int, Point2Int center)
 {
     // is point on east side
     if (point2Int.X > center.X)
     {
         // Is point on north
         if (point2Int.Y > center.Y)
         {
             northEast.Add(point2Int);
         }
         else
         {
             southEast.Add(point2Int);
         }
     }
     else
     {
         // Is point on north
         if (point2Int.Y > center.Y)
         {
             northWest.Add(point2Int);
         }
         else
         {
             southWest.Add(point2Int);
         }
     }
 }
Exemple #19
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;
                }
            }