public bool CollideBounds(RectBox size) { float radiusDouble = boundingCircleRadius * boundingCircleRadius; if (x < size.GetX() - boundingCircleRadius) { return(false); } if (x > size.GetBottom() + boundingCircleRadius) { return(false); } if (y < size.GetY() - boundingCircleRadius) { return(false); } if (y > size.GetBottom() + boundingCircleRadius) { return(false); } if (x < size.GetX() && y < size.GetY() && MathUtils.Distance(x - size.GetX(), y - size.GetY()) > radiusDouble) { return(false); } if (x > size.GetRight() && y < size.GetY() && MathUtils.Distance(x - size.GetRight(), y - size.GetY()) > radiusDouble) { return(false); } if (x < size.GetX() && y > size.GetBottom() && MathUtils.Distance(x - size.GetX(), y - size.GetBottom()) > radiusDouble) { return(false); } if (x > size.GetRight() && y > size.GetBottom() && MathUtils.Distance(x - size.GetRight(), y - size.GetBottom()) > radiusDouble) { return(false); } return(true); }
public static RectBox GetIntersection(RectBox a, RectBox b) { float a_x = a.GetX(); float a_r = a.GetRight(); float a_y = a.GetY(); float a_t = a.GetBottom(); float b_x = b.GetX(); float b_r = b.GetRight(); float b_y = b.GetY(); float b_t = b.GetBottom(); float i_x = MathUtils.Max(a_x, b_x); float i_r = MathUtils.Min(a_r, b_r); float i_y = MathUtils.Max(a_y, b_y); float i_t = MathUtils.Min(a_t, b_t); return(i_x < i_r && i_y < i_t ? new RectBox(i_x, i_y, i_r - i_x, i_t - i_y) : null); }
public static RectBox GetIntersection(RectBox a, RectBox b, RectBox result) { float a_x = a.GetX(); float a_r = a.GetRight(); float a_y = a.GetY(); float a_t = a.GetBottom(); float b_x = b.GetX(); float b_r = b.GetRight(); float b_y = b.GetY(); float b_t = b.GetBottom(); float i_x = MathUtils.Max(a_x, b_x); float i_r = MathUtils.Min(a_r, b_r); float i_y = MathUtils.Max(a_y, b_y); float i_t = MathUtils.Min(a_t, b_t); if (i_x < i_r && i_y < i_t) { result.SetBounds(i_x, i_y, i_r - i_x, i_t - i_y); return(result); } return(null); }