#region --- License --- /* Copyright (c) 2006, 2007 Stefanos Apostolopoulos * See license.txt for license info */ #endregion using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace OpenTK.Math { /// /// Defines a 2d box (rectangle). /// [StructLayout(LayoutKind.Sequential)] public struct Box2 { /// /// The left boundary of the structure. /// public float Left; /// /// The right boundary of the structure. /// public float Right; /// /// The top boundary of the structure. /// public float Top; /// /// The bottom boundary of the structure. /// public float Bottom; /// /// Constructs a new Box2 with the specified dimensions. /// /// An OpenTK.Math.Vector2 describing the top-left corner of the Box2. /// An OpenTK.Math.Vector2 describing the bottom-right corner of the Box2. public Box2(Vector2 topLeft, Vector2 bottomRight) { Left = topLeft.X; Top = topLeft.Y; Right = topLeft.X; Bottom = topLeft.Y; } /// /// Constructs a new Box2 with the specified dimensions. /// /// The position of the left boundary. /// The position of the top boundary. /// The position of the right boundary. /// The position of the bottom boundary. public Box2(float left, float top, float right, float bottom) { Left = left; Top = top; Right = right; Bottom = bottom; } /// /// Creates a new Box2 with the specified dimensions. /// /// The position of the top boundary. /// The position of the left boundary. /// The position of the right boundary. /// The position of the bottom boundary. /// A new OpenTK.Math.Box2 with the specfied dimensions. public static Box2 FromTLRB(float top, float left, float right, float bottom) { return new Box2(left, top, right, bottom); } /// /// Gets a float describing the width of the Box2 structure. /// public float Width { get { return (float)System.Math.Abs(Right - Left); } } /// /// Gets a float describing the height of the Box2 structure. /// public float Height { get { return (float)System.Math.Abs(Bottom - Top); } } public override string ToString() { return String.Format("({0},{1})-({2},{3})", Left, Top, Right, Bottom); } } }