Example #1
0
        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));
        }
Example #2
0
        public bool Intersects(Bound2 boundingBox, out float result)
        {
            // X
            if (Math.Abs(direction.x) < MathUtilities.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) < MathUtilities.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);
        }
Example #3
0
        public Bound2 Merge(Bound2 boundingBox2)
        {
            Bound2 result;

            if (min.x < boundingBox2.min.x)
            {
                result.min.x = min.x;
            }
            else
            {
                result.min.x = boundingBox2.min.x;
            }

            if (min.y < boundingBox2.min.y)
            {
                result.min.y = min.y;
            }
            else
            {
                result.min.y = boundingBox2.min.y;
            }

            if (max.x > boundingBox2.max.x)
            {
                result.max.x = max.x;
            }
            else
            {
                result.max.x = boundingBox2.max.x;
            }

            if (max.y > boundingBox2.max.y)
            {
                result.max.y = max.y;
            }
            else
            {
                result.max.y = boundingBox2.max.y;
            }

            return(result);
        }
        public Bound2 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 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);
 }
 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));
 }