Beispiel #1
0
        /**
         *      Gets the small point that corresponds to the given normal point.
         */

        public RectPoint GetSmallPoint(RectPoint point)
        {
            return(point.Mod(smallDimensions));
        }
Beispiel #2
0
 public static bool IsInsideFixedHeight(RectPoint point, int height, int cellCount)
 {
     return(point.Y >= 0 && point.Y < height && point.X * height + point.Y < cellCount);
 }
Beispiel #3
0
        public bool Equals(RectPoint other)
        {
            bool areEqual = (x == other.X) && (y == other.Y);

            return(areEqual);
        }
Beispiel #4
0
 protected override RectGrid <TCell> MakeShape(int x, int y, Func <RectPoint, bool> isInside, RectPoint offset)
 {
     return(new RectGrid <TCell>(x, y, isInside, offset));
 }
Beispiel #5
0
 /**
  *      Construct a new grid whose cells are determined by the given test function.
  *
  *      The function should only return true for points within the bounds of the rectangle when
  *      the given transforms are applied to them.
  *
  *      Normally, the static factory methods or shape building methods should be used to create grids.
  *      These constructors are provided for advanced usage.
  *
  *      @link_constructing_grids
  */
 public RectGrid(int width, int height, Func <RectPoint, bool> isInside, RectPoint offset) :
     this(width, height, isInside, x => x.MoveBy(offset), x => x.MoveBackBy(offset))
 {
 }
Beispiel #6
0
        /// <summary>
        /// A test function that returns true if the point for which the given
        ///	vertexPoint is a vertex, is inside this grid.
        /// </summary>
        private bool IsInsideEdgeGrid(RectPoint edgePoint)
        {
            var faces = (edgePoint as IEdge <DiamondPoint>).GetEdgeFaces();

            return(faces.Any(Contains));
        }
Beispiel #7
0
 /**
  *      @version1_9
  **/
 private static bool IsInsideCircle(RectPoint point, int radius)
 {
     return(Mathf.Max(point.X, point.Y) < radius);
 }
Beispiel #8
0
 public int PerpDot(RectPoint other)
 {
     return(x * other.Y - y * other.x);
 }
Beispiel #9
0
        /// <summary>
        /// Use this function to create shapes to ensure they fit into memory.
        ///
        /// The test function can test shapes anywhere in space.If you specify the bottom corner
        /// (in terms of the storage rectangle), the shape is automatically translated in memory
        /// to fit, assuming memory width and height is big enough.
        ///
        /// Strategy for implementing new shapes:
        ///		- First, determine the test function.
        ///		- Next, draw a storage rectangle that contains the shape.
        ///		- Determine the storgae rectangle width and height.
        ///		- Finally, determine the grid-space coordinate of the left bottom corner of the storage rectangle.
        ///
        /// Then define your function as follows:
        ///
        /// <code>
        /// public RectShapeInfo&lt;TCell&gt; MyShape()
        /// {
        ///		Shape(stargeRectangleWidth, storageRectangleHeight, isInsideMyShape, storageRectangleBottomleft);
        /// }
        /// </code>
        /// </summary>
        /// <param name="width">The widh of the storage rectangle</param>
        /// <param name="height">The height of the storage rectangle</param>
        /// <param name="isInside">A function that returns true if a passed point lies inside the shape being defined</param>
        /// <param name="bottomLeftCorner">The grid-space coordinate of the bottom left corner of the storage rect.</param>
        public RectShapeInfo <TCell> Shape(int width, int height, Func <RectPoint, bool> isInside, RectPoint bottomLeftCorner)
        {
            var shapeInfo = MakeShapeStorageInfo <RectPoint>(width, height, x => isInside(x + bottomLeftCorner));

            return(new RectShapeInfo <TCell>(shapeInfo).Translate(bottomLeftCorner));
        }
Beispiel #10
0
 public RectPoint MoveBackBy(RectPoint translation)
 {
     return(Translate(translation.Negate()));
 }
Beispiel #11
0
 public int Dot(RectPoint other)
 {
     return(x * other.X + y * other.Y);
 }
Beispiel #12
0
 public RectPoint MoveBy(RectPoint translation)
 {
     return(Translate(translation));
 }
Beispiel #13
0
 /// <summary>
 /// Subtracts the other point from this point, and returns the result.
 /// </summary>
 public RectPoint Subtract(RectPoint other)
 {
     return(new RectPoint(x - other.X, y - other.Y));
 }
Beispiel #14
0
 /// <summary>
 /// This is a norm defined on the point, such that `p1.Difference(p2).Abs()` is equal to
 ///	`p1.DistanceFrom(p2)`.
 /// </summary>
 public RectPoint Translate(RectPoint translation)
 {
     return(new RectPoint(x + translation.X, y + translation.Y));
 }
Beispiel #15
0
        /**
         *      Get the value at the given big point and small point within the cell
         *      at the big point.
         */

        public TCell GetValue(RectPoint bigPoint, RectPoint smallPoint)
        {
            return(bigGrid[bigPoint][smallPoint]);
        }
Beispiel #16
0
 public static ArrayPoint ArrayPointFromGridPoint(RectPoint point)
 {
     return(new ArrayPoint(point.X, point.Y));
 }
Beispiel #17
0
        /// <summary>
        /// A test function that returns true if the point for which the given
        ///	vertexPoint is a vertex, is inside this grid.
        /// </summary>
        private bool IsInsideVertexGrid(RectPoint vertexPoint)
        {
            var faces = (vertexPoint as IVertex <RectPoint>).GetVertexFaces();

            return(faces.Any(Contains));
        }
Beispiel #18
0
 //TODO do we still need these?
 override protected ArrayPoint ArrayPointFromPoint(RectPoint point)
 {
     return(ArrayPointFromGridPoint(point));
 }
Beispiel #19
0
 public static bool IsInsideCheckerBoard(RectPoint point, int width, int height, bool includesOrigin)
 {
     return
         (IsInsideRect(point, width, height) &&
          (GLMathf.Mod(point.X + point.Y, 2) == (includesOrigin ? 0 : 1)));
 }
Beispiel #20
0
        /**
         *      Gets the normal point that corresponds with the given big point and small point.
         */

        public RectPoint CombinePoints(RectPoint bigPoint, RectPoint smallPoint)
        {
            return(bigPoint.Mul(smallDimensions) + smallPoint);
        }
Beispiel #21
0
 protected override ArrayPoint ArrayPointFromGridPoint(RectPoint point)
 {
     return(RectGrid <TCell> .ArrayPointFromGridPoint(point));
 }
Beispiel #22
0
 object IGrid <RectPoint> .this[RectPoint point]
 {
     get { return(this[point]); }
     set { this[point] = (TCell)value; }
 }
Beispiel #23
0
        /**
         *      Returns the points in a grid neighborhood around the given center.
         *
         *      @version1_8
         */
        public static IEnumerable <RectPoint> GetNeighborHood <T>(this RectGrid <T> grid, RectPoint center, int radius)
        {
            for (int i = center.X - radius; i <= center.X + radius; i++)
            {
                for (int j = center.Y - radius; j <= center.Y + radius; j++)
                {
                    var neighborhoodPoint = new RectPoint(i, j);

                    if (grid.Contains(neighborhoodPoint))
                    {
                        yield return(neighborhoodPoint);
                    }
                }
            }
        }
Beispiel #24
0
 public RectGrid <TCell> GetSmallGrid(RectPoint bigPoint)
 {
     return(bigGrid[bigPoint]);
 }
Beispiel #25
0
 public static bool IsInsideFixedWidth(RectPoint point, int width, int cellCount)
 {
     return(point.X >= 0 && point.X < width && point.Y * width + point.X < cellCount);
 }
Beispiel #26
0
        /**
         *      Gets the big point that corresponds to the given normal point.
         */

        public RectPoint GetBigPoint(RectPoint point)
        {
            return(point.Div(smallDimensions));
        }
Beispiel #27
0
 public static bool IsInsideRect(RectPoint point, int width, int height)
 {
     return(point.X >= 0 && point.X < width && point.Y >= 0 && point.Y < height);
 }
Beispiel #28
0
 /// <summary>
 /// The lattice distance from this point to the other.
 /// </summary>
 public int DistanceFrom(RectPoint other)
 {
     return(Subtract(other).Magnitude());
 }