public static bool BoxVSCircle(Vector2 posA, float radiusSqr, Vector2 min, Vector2 max) { float deltaX = posA.x - Maths.Clamp(posA.x, min.x, max.x); float deltaY = posA.y - Maths.Clamp(posA.y, min.y, max.y); return((deltaX * deltaX) + (deltaY * deltaY) <= radiusSqr); }
private void AddToNode(Vector2 posMin, Vector2 posMax) { posMin /= CellSize; posMax /= CellSize; int maxX = Maths.Clamp((int)posMax.x, 0, girdX - 1); int maxY = Maths.Clamp((int)posMax.y, 0, girdY - 1); int minX = Maths.Clamp((int)posMin.x, 0, girdX - 1); int minY = Maths.Clamp((int)posMin.y, 0, girdY - 1); int aabbMax = GetIndex1D(maxX, maxY); int aabbMin = GetIndex1D(minX, minY); _tempNodes.Add(aabbMin); if (aabbMin != aabbMax) { _tempNodes.Add(aabbMax); int lenX = maxX - minX + 1; int lenY = maxY - minY + 1; for (int x = 0; x < lenX; x++) { for (int y = 0; y < lenY; y++) { if ((x == 0 && y == 0) || (x == lenX - 1 && y == lenY - 1)) { continue; } _tempNodes.Add(GetIndex1D(x, y) + aabbMin); } } } }