public HexCubeCoordinates RoundCube(float x, float y, float z) { var rx = (int)Math.Round(x); var ry = (int)Math.Round(y); var rz = (int)Math.Round(z); //var zero = rx + ry + rz; var xDiff = Math.Abs(rx - x); var yDiff = Math.Abs(ry - y); var zDiff = Math.Abs(rz - z); if (xDiff > yDiff && xDiff > zDiff) { rx = -ry - rz; } else if (yDiff > zDiff) { ry = -rx - rz; } else { rz = -rx - ry; } var cube = new HexCubeCoordinates(rx, ry, rz); return(cube); }
public HexCubeCoordinates GetNeighbor(HexCubeCoordinates cube, Direction direction) { var offset = GetNeighboringCube(direction); var neighbor = cube + offset; return(neighbor); }
public Point2F FromCubeToPixel(HexCubeCoordinates cube) { var axial = CubeToAxial(cube); var pixel = FromAxialToPixel(axial); return(pixel); }
public HexAxialCoordinates CubeToAxial(HexCubeCoordinates cube) { var q = cube.X; var r = cube.Z; var axial = new HexAxialCoordinates(q, r); return(axial); }
public Point3F Lerp(HexCubeCoordinates fromCube, HexCubeCoordinates toCube, float t) { var x = t.Lerp(fromCube.X, toCube.X); var y = t.Lerp(fromCube.Y, toCube.Y); var z = t.Lerp(fromCube.Z, toCube.Z); var foo = new Point3F(x, y, z); return(foo); }
public HexCubeCoordinates AxialToCube(HexAxialCoordinates axial) { var x = axial.Q; var z = axial.R; var y = -x - z; var cube = new HexCubeCoordinates(x, y, z); return(cube); }
public int GetDistance(HexCubeCoordinates fromCube, HexCubeCoordinates toCube) { var diffX = Math.Abs(fromCube.X - toCube.X); var diffY = Math.Abs(fromCube.Y - toCube.Y); var diffZ = Math.Abs(fromCube.Z - toCube.Z); var distance1 = (diffX + diffY + diffZ) / 2; var distance2 = Math.Max(Math.Max(diffX, diffY), diffZ); if (distance1 != distance2) { throw new Exception("distance1 not equal to distance2!"); } return(distance1); }
public HexCubeCoordinates[] GetAllNeighbors(HexCubeCoordinates cube) { var neighbors = new List <HexCubeCoordinates>(); for (var i = 0; i < 8; i++) { var neighbor = GetNeighbor(cube, (Direction)i); if (neighbor != cube) { neighbors.Add(neighbor); } } return(neighbors.ToArray()); }
public List <HexCubeCoordinates> GetLine(HexCubeCoordinates fromCube, HexCubeCoordinates toCube) { var distance = GetDistance(fromCube, toCube); var results = new List <HexCubeCoordinates>(); for (var i = 0; i <= distance; i++) { var t = 1.0f / distance * i; var lerp = Lerp(fromCube, toCube, t); var hex = RoundCube(lerp.X, lerp.Y, lerp.Z); results.Add(hex); } return(results); }
public override HexOffsetCoordinates CubeToOffsetCoordinates(HexCubeCoordinates cube) { var col = cube.X; var row = cube.Z; row += OffsetCoordinatesType switch { OffsetCoordinatesType.Even => (col + (col & 1)) / 2, OffsetCoordinatesType.Odd => (col - (col & 1)) / 2, _ => throw new ArgumentOutOfRangeException(nameof(OffsetCoordinatesType), OffsetCoordinatesType, $"OffsetCoordinatesType {OffsetCoordinatesType} is not supported.") }; var offsetCoordinates = new HexOffsetCoordinates(col, row); return(offsetCoordinates); }
public override HexCubeCoordinates OffsetCoordinatesToCube(HexOffsetCoordinates offset) { var col = offset.Col; var row = offset.Row; row -= OffsetCoordinatesType switch { OffsetCoordinatesType.Even => (col + (col & 1)) / 2, OffsetCoordinatesType.Odd => (col - (col & 1)) / 2, _ => throw new ArgumentOutOfRangeException(nameof(OffsetCoordinatesType), OffsetCoordinatesType, $"OffsetCoordinatesType {OffsetCoordinatesType} is not supported.") }; var y = -col - row; var cube = new HexCubeCoordinates(col, y, row); return(cube); }
public static HexCubeCoordinates operator +(HexCubeCoordinates a, HexCubeCoordinates b) { var hexCube = new HexCubeCoordinates(a.X + b.X, a.Y + b.Y, a.Z + b.Z); return(hexCube); }
public Point3F Lerp(HexCubeCoordinates fromCube, HexCubeCoordinates toCube, float t) => _hex.Lerp(fromCube, toCube, t);
public int GetDistance(HexCubeCoordinates fromCube, HexCubeCoordinates toCube) => _hex.GetDistance(fromCube, toCube);
public Point2F FromCubeToPixel(HexCubeCoordinates cube) => _hex.FromCubeToPixel(cube);
public HexCubeCoordinates GetNeighbor(HexCubeCoordinates cube, Direction direction) => _hex.GetNeighbor(cube, direction);
public List <HexCubeCoordinates> GetLine(HexCubeCoordinates fromCube, HexCubeCoordinates toCube) => _hex.GetLine(fromCube, toCube);
public HexCubeCoordinates[] GetAllNeighbors(HexCubeCoordinates cube) => _hex.GetAllNeighbors(cube);
public HexAxialCoordinates CubeToAxial(HexCubeCoordinates cube) => _hex.CubeToAxial(cube);
public HexOffsetCoordinates CubeToOffsetCoordinates(HexCubeCoordinates cube) => _hex.CubeToOffsetCoordinates(cube);
public HexCubeCoordinates Scale(int k) { var scaledCube = new HexCubeCoordinates(X * k, Y * k, Z * k); return(scaledCube); }
public abstract HexOffsetCoordinates CubeToOffsetCoordinates(HexCubeCoordinates cube);