namespace Orvid.Graphics { /// /// The class that defines a bounding box. /// public class BoundingBox { /// /// The right side of the BoundingBox. /// public int Right; /// /// The left side of the BoundingBox. /// public int Left; /// /// The top of the BoundingBox. /// public int Top; /// /// The bottom of the BoundingBox. /// public int Bottom; /// /// Gets the Width of the BoundingBox. /// public int Width { get { return Right - Left; } } /// /// Gets the Height of the BoundingBox. /// public int Height { get { return Top - Bottom; } } /// /// The default constructor. /// /// The farthest left side of the bounding box. /// The farthest right side of the bounding box. /// The farthest up side of the bounding box. /// The farthest down side of the bounding box. public BoundingBox(int ileft, int iright, int itop, int ibottom) { this.Left = ileft; this.Right = iright; this.Top = itop; this.Bottom = ibottom; } /// /// Returns true if the given point is inside the bounding box. /// /// The point to check. /// True if the specified point is inside the bounding box. public bool Contains(Vec2 p) { return IsInBounds(p); } /// /// Returns true if the given point is inside the bounding box. /// /// X location. /// Y location. /// True if the given point is inside the bounding box. public bool Contains(int x, int y) { return IsInBounds(new Vec2(x, y)); } /// /// Returns true if the given point is inside the bounding box. /// /// X location. /// Y location. /// True if the given point is inside the bounding box. public bool IsInBounds(int x, int y) { return IsInBounds(new Vec2(x, y)); } /// /// Returns true if the given point is inside the bounding box. /// /// The point to check. /// True if the specified point is inside the bounding box. public bool IsInBounds(Vec2 p) { //throw new Exception(); return ((p.X < Right && p.X > Left) && (p.Y < Top && p.Y > Bottom)); } /// /// Lowers all values in the BoundingBox by the specified Vec2. /// public static BoundingBox operator -(BoundingBox b, Vec2 v) { return new BoundingBox(b.Left - v.X, b.Right - v.X, b.Top - v.Y, b.Bottom - v.Y); } } }