public DiamondShapeInfo <TCell> FatRectangle(int width, int height) { int diamondSize = width + Mathi.Div(height, 2); var storageBottomLeft = new DiamondPoint(0, 1 - width); return(Shape(diamondSize, diamondSize, p => IsInsideFatRectangle(p, width, height), storageBottomLeft)); }
/** * Gives a new point that represents the * reminder when the first point is divided * by the second point component-wise. The * division is integer division. * * @since 1.6 (Rect) * @since 1.7 (other) */ public DiamondPoint Mod(DiamondPoint otherPoint) { var x = GLMathf.Mod(X, otherPoint.X); var y = GLMathf.Mod(Y, otherPoint.Y); return(new DiamondPoint(x, y)); }
/** * Gives a new point that represents the * first point divided by the second point * component-wise. The division is integer * division. * * @since 1.6 (Rect) * @since 1.7 (other) */ public DiamondPoint Div(DiamondPoint otherPoint) { var x = Mathi.Div(X, otherPoint.X); var y = Mathi.Div(Y, otherPoint.Y); return(new DiamondPoint(x, y)); }
/** * Gives a new point that represents the * first point multiplied by the second point * component-wise. * * @since 1.6 (Rect) * @since 1.7 (other) */ public DiamondPoint Mul(DiamondPoint otherPoint) { var x = X * otherPoint.X; var y = Y * otherPoint.Y; return(new DiamondPoint(x, y)); }
private static bool IsInsideParallelogram(DiamondPoint point, int width, int height) { return (point.X >= 0 && point.X < width && point.Y >= 0 && point.Y < height); }
public DiamondShapeInfo <TCell> Rectangle(int width, int height) { //Note: this fit is not the tightest possible. int diamondSize = width + Mathi.Div(height, 2); var storageBottomLeft = new DiamondPoint(0, 1 - width); return(Shape(diamondSize, diamondSize, p => IsInsideRaggedRectangle(p, width, height), storageBottomLeft)); }
private static bool IsInsideThinRectangle(DiamondPoint point, int width, int height) { int x = Mathi.Div(point.X - point.Y, 2); int y = point.X + point.Y; return (x >= 0 && x < width - Mathi.Mod(y, 2) && y >= 0 && y < height); }
private static bool IsInsideRaggedRectangle(DiamondPoint point, int width, int height) { int x = GLMathf.Div(point.X - point.Y, 2); int y = point.X + point.Y; return (x >= 0 && x < width && y >= 0 && y < height); }
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { base.OnMouseLeftButtonUp(e); draggingStarted = false; mouseDraggedLocation = centerPoint; DiamondPoint = DiamondToolbox.CartesianToDiamond(new DoublePoint(0, 0), 100); if (JoystickMovedListeners != null) { JoystickMovedListeners(DiamondPoint); } e.Handled = true; }
public void Update() { if (Input.GetMouseButtonDown(0)) { Vector2 worldPosition = GridBuilderUtils.ScreenToWorld(root, Input.mousePosition); DiamondPoint rectPoint = map[worldPosition]; if (grid.Contains(rectPoint)) { grid[rectPoint].OnClick(); } } }
public void Update() { if (Input.GetMouseButtonDown(0)) { Vector2 worldPosition = GridBuilderUtils.ScreenToWorld(root, Input.mousePosition); DiamondPoint point = map[worldPosition]; if (grid.Contains(point)) { //Toggle the highlight grid[point].HighlightOn = !grid[point].HighlightOn; } } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (draggingStarted) { mouseDraggedLocation = e.GetPosition(this); var p = new DoublePoint( map((int)mouseDraggedLocation.X, 0, (int)ActualWidth, 100, -100), map((int)mouseDraggedLocation.Y, 0, (int)ActualHeight, 100, -100) ); DiamondPoint = DiamondToolbox.CartesianToDiamond(p, 100); if (JoystickMovedListeners != null) { JoystickMovedListeners(DiamondPoint); } e.Handled = true; } }
/** * 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 1.7 */ 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 = Mathi.FloorToInt(a); int n = Mathi.FloorToInt(b); int baseVectorX = m * u.X + n * v.X; int baseVectorY = n * u.Y + n * v.Y; int offsetX = Mathi.Mod(X - baseVectorX, ux); int offsetY = Y - baseVectorY; int colorIndex = Mathi.FloorToInt(offsetX + offsetY * ux); return(colorIndex); }
/** * @version1_11 */ public InspectableVectorPoint(DiamondPoint point) { x = point.X; y = point.Y; }
public static ArrayPoint ArrayPointFromGridPoint(DiamondPoint point) { return(new ArrayPoint(point.X, point.Y)); }
override protected ArrayPoint ArrayPointFromPoint(DiamondPoint point) { return(ArrayPointFromGridPoint(point)); }
/** * @since 1.7 */ public int Dot(DiamondPoint other) { return(x * other.X + y * other.Y); }
/** * @since 1.7 */ public int PerpDot(DiamondPoint other) { return(x * other.Y - y * other.x); }
public DiamondPoint MoveBy(DiamondPoint translation) { return(Translate(translation)); }
public DiamondPoint MoveBackBy(DiamondPoint translation) { return(Translate(translation.Negate())); }
/** * Subtracts the other point from this point, and returns the result. */ public DiamondPoint Subtract(DiamondPoint other) { return(new DiamondPoint(x - other.X, y - other.Y)); }
/** * This is a norm defined on the point, such that `p1.Difference(p2).Abs()` is equal to * `p1.DistanceFrom(p2)`. */ 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); }
/** * The lattice distance from this point to the other. */ public int DistanceFrom(DiamondPoint other) { return(Subtract(other).Magnitude()); }
/** @version1_11 */ public InspectableVectorPoint(DiamondPoint point) { x = point.X; y = point.Y; }