public bool Intersects(Bound2 boundingBox) { Vec2 clampedLocation; if (center.x > boundingBox.max.x) { clampedLocation.x = boundingBox.max.x; } else if (center.x < boundingBox.min.x) { clampedLocation.x = boundingBox.min.x; } else { clampedLocation.x = center.x; } if (center.y > boundingBox.max.y) { clampedLocation.y = boundingBox.max.y; } else if (center.y < boundingBox.min.y) { clampedLocation.y = boundingBox.min.y; } else { clampedLocation.y = center.y; } return(clampedLocation.DistanceSquared(center) <= (radius * radius)); }
public bool Intersects(Bound2 boundingBox, out float result) { // X if (Math.Abs(direction.x) < MathTools.epsilon && (origin.x < boundingBox.min.x || origin.x > boundingBox.max.x)) { //If the ray isn't pointing along the axis at all, and is outside of the box's interval, then it can't be intersecting. result = 0; return(false); } float tmin = 0, tmax = float.MaxValue; float inverseDirection = 1 / direction.x; float t1 = (boundingBox.min.x - origin.x) * inverseDirection; float t2 = (boundingBox.max.x - origin.x) * inverseDirection; if (t1 > t2) { float temp = t1; t1 = t2; t2 = temp; } tmin = Math.Max(tmin, t1); tmax = Math.Min(tmax, t2); if (tmin > tmax) { result = 0; return(false); } // Y if (Math.Abs(direction.y) < MathTools.epsilon && (origin.y < boundingBox.min.y || origin.y > boundingBox.max.y)) { //If the ray isn't pointing along the axis at all, and is outside of the box's interval, then it can't be intersecting. result = 0; return(false); } inverseDirection = 1 / direction.y; t1 = (boundingBox.min.y - origin.y) * inverseDirection; t2 = (boundingBox.max.y - origin.y) * inverseDirection; if (t1 > t2) { float temp = t1; t1 = t2; t2 = temp; } tmin = Math.Max(tmin, t1); tmax = Math.Min(tmax, t2); if (tmin > tmax) { result = 0; return(false); } result = tmin; return(true); }
public Bound3 Merge(Bound2 boundingBox) { var result = this; if (result.min.x < boundingBox.min.x) { result.min.x = boundingBox.min.x; } if (result.max.x > boundingBox.max.x) { result.max.x = boundingBox.max.x; } if (result.min.y < boundingBox.min.y) { result.min.y = boundingBox.min.y; } if (result.max.y > boundingBox.max.y) { result.max.y = boundingBox.max.y; } return(result); }
public bool Intersects(Bound2 boundingBox) { return (!(boundingBox.min.x > max.x || boundingBox.min.y > max.y || min.x > boundingBox.max.x || min.y > boundingBox.max.y)); }
public void Intersects(Bound2 boundingBox, out bool result) { result = x >= boundingBox.left && x <= boundingBox.right && y >= boundingBox.bottom && y <= boundingBox.top; }
public bool Intersects(Bound2 boundingBox) { return(x >= boundingBox.left && x <= boundingBox.right && y >= boundingBox.bottom && y <= boundingBox.top); }