public DiamondShapeInfo <TCell> FatRectangle(int width, int height) { int diamondSize = width + GLMathf.FloorDiv(height, 2); var storageBottomLeft = new DiamondPoint(0, 1 - width); return(Shape(diamondSize, diamondSize, p => IsInsideFatRectangle(p, width, height), storageBottomLeft)); }
/// <summary> /// Gives a new point that represents the /// first point multiplied by the second point /// component-wise. /// /// Since version 1.6 (Rect) /// Since version 1.7 (other) /// </summary> public DiamondPoint Mul(DiamondPoint otherPoint) { var x = X * otherPoint.X; var y = Y * otherPoint.Y; return(new DiamondPoint(x, y)); }
/// <summary> /// Gives a new point that represents the /// first point divided by the second point /// component-wise. The division is integer /// division. /// /// Since version 1.6 (Rect) /// Since version 1.7 (other) /// </summary> public DiamondPoint Div(DiamondPoint otherPoint) { var x = GLMathf.FloorDiv(X, otherPoint.X); var y = GLMathf.FloorDiv(Y, otherPoint.Y); return(new DiamondPoint(x, y)); }
public IEnumerable <DiamondPoint> GetSpiralIterator(DiamondPoint origin, int ringCount) { var point = origin; if (Contains(point)) { yield return(point); } for (var k = 1; k < ringCount; k++) { point += DiamondPoint.North; for (var i = 0; i < 4; i++) { for (var j = 0; j < 2 * k; j++) { point += SpiralIteratorDirections[i]; if (Contains(point)) { yield return(point); } } } } }
private static bool IsInsideParallelogram(DiamondPoint point, int width, int height) { return (point.X >= 0 && point.X < width && point.Y >= 0 && point.Y < height); }
public IEnumerable <DiamondPoint> GetEdges() { DiamondPoint edgeAnchor = GetEdgeAnchor(); return (from edgeDirection in EdgeDirections select edgeDirection + edgeAnchor); }
public DiamondShapeInfo <TCell> Rectangle(int width, int height) { //Note: this fit is not the tightest possible. int diamondSize = width + GLMathf.FloorDiv(height, 2); var storageBottomLeft = new DiamondPoint(0, 1 - width); return(Shape(diamondSize, diamondSize, p => IsInsideRaggedRectangle(p, width, height), storageBottomLeft)); }
public static bool DefaultContains(DiamondPoint point, int width, int height) { ArrayPoint storagePoint = ArrayPointFromGridPoint(point); return (storagePoint.X >= 0 && storagePoint.X < width && storagePoint.Y >= 0 && storagePoint.Y < height); }
private static bool IsInsideThinRectangle(DiamondPoint point, int width, int height) { int x = GLMathf.FloorDiv(point.X - point.Y, 2); int y = point.X + point.Y; return (x >= 0 && x < width - GLMathf.FloorMod(y, 2) && y >= 0 && y < height); }
/// <summary> /// Gives a coloring of the grid such that /// if a point p has color k, then all points /// p + m[ux, 0] + n[vx, vy] have the same color /// for any integers a and b. /// /// More information anout grid colorings: /// http://gamelogic.co.za/2013/12/18/what-are-grid-colorings/ /// /// Since version 1.7 /// </summary> public int __GetColor__ReferenceImplementation(int ux, int vx, int vy) { var u = new DiamondPoint(ux, 0); var v = new DiamondPoint(vx, vy); int colorCount = u.PerpDot(v); float a = PerpDot(v) / (float)colorCount; float b = -PerpDot(u) / (float)colorCount; int m = Mathf.FloorToInt(a); int n = Mathf.FloorToInt(b); int baseVectorX = m * u.X + n * v.X; int baseVectorY = n * u.Y + n * v.Y; int offsetX = GLMathf.FloorMod(X - baseVectorX, ux); int offsetY = Y - baseVectorY; int colorIndex = Mathf.FloorToInt(offsetX + offsetY * ux); return(colorIndex); }
public DiamondPoint MoveBy(DiamondPoint translation) { return(Translate(translation)); }
/** * 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{cs} * public DiamondShapeInfo<TCell> MyShape() * { * Shape(stargeRectangleWidth, storageRectangleHeight, isInsideMyShape, storageRectangleBottomleft); * } * \endcode * * \param width The widh of the storage rectangle * \param height The height of the storage rectangle * \param isInside A function that returns true if a passed point lies inside the shape being defined * \param bottomLeftCorner The grid-space coordinate of the bottom left corner of the storage rect. * */ public DiamondShapeInfo <TCell> Shape(int width, int height, Func <DiamondPoint, bool> isInside, DiamondPoint bottomLeftCorner) { var shapeInfo = MakeShapeStorageInfo <DiamondPoint>(width, height, x => isInside(x + bottomLeftCorner)); return(new DiamondShapeInfo <TCell>(shapeInfo).Translate(bottomLeftCorner)); }
public InspectableVectorPoint(DiamondPoint point) { x = point.X; y = point.Y; }
/** * A test function that returns true if the point for which the given * vertexPoint is a vertex, is inside this grid. */ private bool IsInsideVertexGrid(DiamondPoint vertexPoint) { var faces = (vertexPoint as IVertex <DiamondPoint>).GetVertexFaces(); return(faces.Any(Contains)); }
protected override DiamondGrid <TCell> MakeShape(int x, int y, Func <DiamondPoint, bool> isInside, DiamondPoint offset) { return(new DiamondGrid <TCell>(x, y, isInside, offset)); }
public static ArrayPoint ArrayPointFromGridPoint(DiamondPoint point) { return(new ArrayPoint(point.X, point.Y)); }
/** * 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 DiamondGrid(int width, int height, Func <DiamondPoint, bool> isInside, DiamondPoint offset) : this(width, height, isInside, x => x.MoveBy(offset), x => x.MoveBackBy(offset), DiamondPoint.MainDirections) { }
/// <summary> /// Subtracts the other point from this point, and returns the result. /// </summary> public DiamondPoint Subtract(DiamondPoint other) { return(new DiamondPoint(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 DiamondPoint Translate(DiamondPoint translation) { return(new DiamondPoint(x + translation.X, y + translation.Y)); }
public bool Equals(DiamondPoint other) { bool areEqual = (x == other.X) && (y == other.Y); return(areEqual); }
/// <summary> /// The lattice distance from this point to the other. /// </summary> public int DistanceFrom(DiamondPoint other) { return(Subtract(other).Magnitude()); }
protected override ArrayPoint ArrayPointFromGridPoint(DiamondPoint point) { return(DiamondGrid <TCell> .ArrayPointFromGridPoint(point)); }
public DiamondPoint MoveBackBy(DiamondPoint translation) { return(Translate(translation.Negate())); }
protected override ArrayPoint ArrayPointFromPoint(DiamondPoint point) { return(ArrayPointFromGridPoint(point)); }
public int Dot(DiamondPoint other) { return(x * other.X + y * other.Y); }
public int PerpDot(DiamondPoint other) { return(x * other.Y - y * other.x); }
/** * A test function that returns true if the point for which the given * vertexPoint is a vertex, is inside this grid. */ private bool IsInsideEdgeGrid(DiamondPoint edgePoint) { var faces = (edgePoint as IEdge <RectPoint>).GetEdgeFaces(); return(faces.Any(Contains)); }