public bool Intersects(GridBounds2D bounds) { GridPoint2D otherMin = bounds.Min; GridPoint2D otherMax = bounds.Max; return(!(Min.X > otherMax.X || Min.Y > otherMax.Y || Max.X < otherMin.X || Max.Y < otherMin.Y)); }
public GridCoord2D(GridSize2D size, int index) { Index = index; int x = (index % size.X); index /= size.X; int y = index; Point = new GridPoint2D(x, y); }
public bool Contains(GridPoint2D point, bool inclusive = false) { if (Min.X <= point.X && Min.Y <= point.Y) { if (inclusive) { return(Max.X >= point.X && Max.Y >= point.Y); } return(Max.X > point.X && Max.Y > point.Y); } return(false); }
public static int Raycast(float startX, float startY, float directionX, float directionY, GridHit2D[] hitBuffer) { int stepX = Math.Sign(directionX); int stepY = Math.Sign(directionY); if (stepX == 0 && stepY == 0) { return(0); } int bufferSize = hitBuffer.Length; int currentX = (int)Math.Floor(startX); int currentY = (int)Math.Floor(startY); currentX = Math.Max(currentX, 0); currentY = Math.Max(currentY, 0); float nextBoundX = CalculateBound(currentX, startX, stepX); float nextBoundY = CalculateBound(currentY, startY, stepY); float deltaX = (1f / directionX) * stepX; float deltaY = (1f / directionY) * stepY; float travelX = nextBoundX / directionX; float travelY = nextBoundY / directionY; int iterator = 0; EDirection2D xExitFace = (stepX > 0 ? EDirection2D.Left : EDirection2D.Right); EDirection2D yExitFace = (stepY > 0 ? EDirection2D.Down : EDirection2D.Up); EDirection2D selectedFace; float startDecimalX = startX - (float)Math.Truncate(startX); float startDecimalY = startY - (float)Math.Truncate(startY); if (startDecimalX < startDecimalY) { selectedFace = (directionX > 0 ? EDirection2D.Left : EDirection2D.Right); } else { selectedFace = (directionY > 0 ? EDirection2D.Down : EDirection2D.Up); } while (iterator < bufferSize) { GridPoint2D point = new GridPoint2D(currentX, currentY); if (travelX < travelY) { hitBuffer[iterator++] = new GridHit2D(point, selectedFace); selectedFace = xExitFace; currentX += stepX; travelX += deltaX; } else { hitBuffer[iterator++] = new GridHit2D(point, selectedFace); selectedFace = yExitFace; currentY += stepY; travelY += deltaY; } } return(iterator); }
public bool Contains(GridPoint2D point) { return(point.X < X && point.Y < Y && point.X >= 0 && point.Y >= 0); }
public GridBounds2D(GridSize2D size) { Min = new GridPoint2D(0, 0); Max = new GridPoint2D(size.X, size.Y); }
public GridBounds2D(GridPoint2D min, GridPoint2D max) { Min = min; Max = max; }
public GridBounds2D(int minX, int minY, int maxX, int maxY) { Min = new GridPoint2D(minX, minY); Max = new GridPoint2D(maxX, maxY); }
public GridBounds2D(int maxX, int maxY) { Min = new GridPoint2D(0, 0); Max = new GridPoint2D(maxX, maxY); }
public GridHit2D(GridPoint2D point, EDirection2D face) { Point = point; Face = face; }
public static GridCoord2D Create(GridSize2D size, GridAxes2D axes, int a, int b) { GridPoint2D point = GridPoint2D.Create(axes, a, b); return(new GridCoord2D(size, point)); }
public GridCoord2D(GridSize2D size, GridPoint2D point) { Point = point; Index = (point.Y * size.X) + point.X; }
public GridCoord2D(GridPoint2D point, int index) { Point = point; Index = index; }