/** * Gets the small point that corresponds to the given normal point. */ public RectPoint GetSmallPoint(RectPoint point) { return(point.Mod(smallDimensions)); }
public static bool IsInsideFixedHeight(RectPoint point, int height, int cellCount) { return(point.Y >= 0 && point.Y < height && point.X * height + point.Y < cellCount); }
public bool Equals(RectPoint other) { bool areEqual = (x == other.X) && (y == other.Y); return(areEqual); }
protected override RectGrid <TCell> MakeShape(int x, int y, Func <RectPoint, bool> isInside, RectPoint offset) { return(new RectGrid <TCell>(x, y, isInside, offset)); }
/** * 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)) { }
/// <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)); }
/** * @version1_9 **/ private static bool IsInsideCircle(RectPoint point, int radius) { return(Mathf.Max(point.X, point.Y) < radius); }
public int PerpDot(RectPoint other) { return(x * other.Y - y * other.x); }
/// <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<TCell> 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)); }
public RectPoint MoveBackBy(RectPoint translation) { return(Translate(translation.Negate())); }
public int Dot(RectPoint other) { return(x * other.X + y * other.Y); }
public RectPoint MoveBy(RectPoint translation) { return(Translate(translation)); }
/// <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)); }
/// <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)); }
/** * 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]); }
public static ArrayPoint ArrayPointFromGridPoint(RectPoint point) { return(new ArrayPoint(point.X, point.Y)); }
/// <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)); }
//TODO do we still need these? override protected ArrayPoint ArrayPointFromPoint(RectPoint point) { return(ArrayPointFromGridPoint(point)); }
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))); }
/** * 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); }
protected override ArrayPoint ArrayPointFromGridPoint(RectPoint point) { return(RectGrid <TCell> .ArrayPointFromGridPoint(point)); }
object IGrid <RectPoint> .this[RectPoint point] { get { return(this[point]); } set { this[point] = (TCell)value; } }
/** * 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); } } } }
public RectGrid <TCell> GetSmallGrid(RectPoint bigPoint) { return(bigGrid[bigPoint]); }
public static bool IsInsideFixedWidth(RectPoint point, int width, int cellCount) { return(point.X >= 0 && point.X < width && point.Y * width + point.X < cellCount); }
/** * Gets the big point that corresponds to the given normal point. */ public RectPoint GetBigPoint(RectPoint point) { return(point.Div(smallDimensions)); }
public static bool IsInsideRect(RectPoint point, int width, int height) { return(point.X >= 0 && point.X < width && point.Y >= 0 && point.Y < height); }
/// <summary> /// The lattice distance from this point to the other. /// </summary> public int DistanceFrom(RectPoint other) { return(Subtract(other).Magnitude()); }