public VectorPoint Mod(VectorPoint other) { var newX = Mathi.Mod(x, other.X); var newY = Mathi.Mod(y, other.Y); return(new VectorPoint(newX, newY)); }
override public FlatHexPoint RawWorldToGrid(Vector2 point) { int x = Mathi.FloorToInt((point.x + cellDimensions.x / 2) / cellDimensions.x); int y = Mathi.FloorToInt((point.y - x * cellDimensions.y / 2 + cellDimensions.y / 2) / cellDimensions.y); return(new FlatHexPoint(x, y)); }
public override LinePoint RawWorldToGrid(Vector2 worldPoint) { var point = (worldPoint + cellDimensions / 2); var m = Mathi.FloorToInt(point.x / cellDimensions.x); return(m); }
public IEnumerable <DiamondPoint> GetEdgeFaces() { var edgeAnchor = GetEdgeFaceAnchor(); int edgeIndex = Mathi.Mod(X + Y, 2); return(from faceDirection in EdgeFaceDirections[edgeIndex] select faceDirection + edgeAnchor); }
private DiamondPoint GetEdgeFaceAnchor() { /* * 0 0 -> 0 0 * 0 1 -> 0 0 * 1 0 -> 0 -1 * 1 1 -> 1 0 */ return(new DiamondPoint( Mathi.Div(X + Y, 2), Mathi.Div(Y - X, 2))); }
public override DiamondPoint RawWorldToGrid(Vector2 point) { int x = Mathi.FloorToInt((point.x + 0 * cellDimensions.x / 2) / cellDimensions.x + /*Mathi.FloorToInt(*/ (point.y + cellDimensions.y / 2) / cellDimensions.y); int y = Mathi.FloorToInt((point.y + cellDimensions.y / 2) / cellDimensions.y - (point.x + 0 * cellDimensions.x / 2) / cellDimensions.x); return(new DiamondPoint(x, y)); }
public override FlatTriPoint RawWorldToGrid(Vector2 point) { float hexSize = cellDimensions.y * 2; float y = point.x / hexSize * Mathf.Sqrt(3); float x = (point.y - cellDimensions.y / 2) / hexSize; int ti = Mathf.FloorToInt(-x + y); int tj = Mathf.FloorToInt(x + y) + 1; int tk = Mathf.FloorToInt(-2 * x); return(new FlatTriPoint(ti, -tk, Mathi.Mod(tj + tk + ti, 2))); }
public override PointyTriPoint RawWorldToGrid(Vector2 point) { float hexSize = cellDimensions.x * 2; float x = point.y / hexSize * Mathf.Sqrt(3); float y = (point.x - cellDimensions.x / 2) / hexSize /*- cellDimensions.y/2*/; int ti = Mathf.FloorToInt(x - y); int tj = Mathf.FloorToInt(x + y) + 1; int tk = Mathf.FloorToInt(-2 * y); return(new PointyTriPoint(-tk, ti, Mathi.Mod(tj + tk + ti, 2))); }
/** * Makes an edge grid for this grid. */ public IGrid <TNewCell, FlatRhombPoint> MakeEdgeGrid <TNewCell>() { var edges = this.SelectMany(x => x.GetEdges()); var storage = FlatRhombGrid <TNewCell> .CalculateStorage(edges); var offset = FlatRhombGrid <TNewCell> .GridPointFromArrayPoint(storage.offset); var oddPoint = new FlatHexPoint( Mathi.Mod(offset.X, 2), Mathi.Mod(offset.Y, 2)); var evenPoint = offset.Subtract(oddPoint); return(new FlatRhombGrid <TNewCell>(storage.dimensions.X + 2, storage.dimensions.Y + 2, IsInsideEdgeGrid, evenPoint)); }
//TODO: Fix public override FlatRhombPoint RawWorldToGrid(Vector2 point) { float hexSize = cellDimensions.y; //basePoint += new Vector2(cellDimensions.x/2, cellDimensions.y / 4); float y = (point.y - cellDimensions.y / 4) / hexSize; float x = (point.x - cellDimensions.y / 4 / Mathf.Sqrt(3)) / hexSize * Mathf.Sqrt(3); int ti = Mathf.FloorToInt(x - y); int tj = Mathf.FloorToInt(x + y); int tk = Mathf.FloorToInt(-2 * y); float hi0 = Mathf.FloorToInt((+ti + tk + 2.0f) / 3); float hj0 = Mathf.FloorToInt((+tj - tk + 1.0f) / 3); float hk0 = hi0 + hj0; float hi = -hi0; float hj = hk0; int index; if ( Mathi.Mod(tj, 3) == 0 && Mathi.Mod(tk, 3) == 1 || Mathi.Mod(tj, 3) == 1 && Mathi.Mod(tk, 3) == 2 || Mathi.Mod(tj, 3) == 2 && Mathi.Mod(tk, 3) == 0) { index = 0; } else if ( Mathi.Mod(ti, 3) == 0 && Mathi.Mod(tk, 3) == 1 || Mathi.Mod(ti, 3) == 1 && Mathi.Mod(tk, 3) == 0 || Mathi.Mod(ti, 3) == 2 && Mathi.Mod(tk, 3) == 2 ) { index = 1; } else { index = 2; } return(new FlatRhombPoint(Mathf.FloorToInt(hj), Mathf.FloorToInt(hi), index)); }
public override PointyHexPoint RawWorldToGrid(Vector2 worldPoint) { float angleRad = Mathf.Atan2(worldPoint.y - Center.y, worldPoint.x - Center.x); if (angleRad < 0) { angleRad += 2 * Mathf.PI; } float radius = (new Vector2(worldPoint.x - Center.x, worldPoint.y - Center.y)).magnitude; int n = Mathf.FloorToInt((radius - InnerRadius) / (OuterRadius - InnerRadius) * SectorsAndBands.Y); int m = Mathf.FloorToInt((angleRad - sectorAngleRad * n / 2) / sectorAngleRad); m = Mathi.Mod(m, SectorsAndBands.X); return(new PointyHexPoint(m, n)); }
public VectorPoint ScaleDown(int r) { return(new VectorPoint( Mathi.Div(x, r), Mathi.Div(y, r))); }
public static bool IsInsideCheckerBoard(RectPoint point, int width, int height, bool includesOrigin) { return (IsInsideRect(point, width, height) && (Mathi.Mod(point.X + point.Y, 2) == (includesOrigin ? 0 : 1))); }
public int GetColor(int colorCount) { return(Mathi.Mod(n, colorCount)); }
public int GetColor4() { return(Mathi.Mod(X + 3 * Y, 8)); }
public PointyRhombPoint IncIndex(int n) { return(new PointyRhombPoint(basePoint, Mathi.Mod(index + n, SpliceCount))); }
public CairoPoint IncIndex(int n) { return(new CairoPoint(basePoint, Mathi.Mod(index + n, SpliceCount))); }
public override RectPoint RawWorldToGrid(Vector2 point) { return(new RectPoint( Mathi.FloorToInt((point.x + cellDimensions.x / 2) / cellDimensions.x), Mathi.FloorToInt((point.y + cellDimensions.y / 2) / cellDimensions.y))); }
public FlatTriPoint IncIndex(int n) { return(new FlatTriPoint(basePoint, Mathi.Mod(index + n, SpliceCount))); }
public LinePoint ScaleDown(int r) { return(Mathi.Div(n, r)); }
public int GetColor1_2() { return(Mathi.Mod(X + Y, 2)); }
public LinePoint Div(LinePoint other) { return(Mathi.Div(n, other.n)); }
protected override Func <LinePoint, int> GetColorFunc(int x0, int x1, int y1) { return(point => Mathi.Mod(point, x0)); }
public LinePoint Mod(LinePoint other) { return(Mathi.Mod(n, other.n)); }