Added ToString() method. Added documentation.

This commit is contained in:
the_fiddler 2007-11-08 15:55:38 +00:00
parent 8c65412b69
commit 8002ec7716

View file

@ -6,11 +6,36 @@ using System.Runtime.InteropServices;
namespace OpenTK.Math namespace OpenTK.Math
{ {
/// <summary> /// <summary>
/// Defines a rectangle. /// Defines a 2d box (rectangle).
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct Box2 public struct Box2
{ {
/// <summary>
/// The left boundary of the structure.
/// </summary>
public float Left;
/// <summary>
/// The right boundary of the structure.
/// </summary>
public float Right;
/// <summary>
/// The top boundary of the structure.
/// </summary>
public float Top;
/// <summary>
/// The bottom boundary of the structure.
/// </summary>
public float Bottom;
/// <summary>
/// Constructs a new Box2 with the specified dimensions.
/// </summary>
/// <param name="topLeft">An OpenTK.Math.Vector2 describing the top-left corner of the Box2.</param>
/// <param name="bottomRight">An OpenTK.Math.Vector2 describing the bottom-right corner of the Box2.</param>
public Box2(Vector2 topLeft, Vector2 bottomRight) public Box2(Vector2 topLeft, Vector2 bottomRight)
{ {
Left = topLeft.X; Left = topLeft.X;
@ -18,6 +43,14 @@ namespace OpenTK.Math
Right = topLeft.X; Right = topLeft.X;
Bottom = topLeft.Y; Bottom = topLeft.Y;
} }
/// <summary>
/// Constructs a new Box2 with the specified dimensions.
/// </summary>
/// <param name="left">The position of the left boundary.</param>
/// <param name="top">The position of the top boundary.</param>
/// <param name="right">The position of the right boundary.</param>
/// <param name="bottom">The position of the bottom boundary.</param>
public Box2(float left, float top, float right, float bottom) public Box2(float left, float top, float right, float bottom)
{ {
Left = left; Left = left;
@ -25,12 +58,33 @@ namespace OpenTK.Math
Right = right; Right = right;
Bottom = bottom; Bottom = bottom;
} }
public float Left, Right, Top, Bottom;
public float Width { get { return (float)System.Math.Abs(Right - Left); } } /// <summary>
public float Height { get { return (float)System.Math.Abs(Bottom - Top); } } /// Creates a new Box2 with the specified dimensions.
/// </summary>
/// <param name="top">The position of the top boundary.</param>
/// <param name="left">The position of the left boundary.</param>
/// <param name="right">The position of the right boundary.</param>
/// <param name="bottom">The position of the bottom boundary.</param>
/// <returns>A new OpenTK.Math.Box2 with the specfied dimensions.</returns>
public static Box2 FromTLRB(float top, float left, float right, float bottom) public static Box2 FromTLRB(float top, float left, float right, float bottom)
{ {
return new Box2(left, top, right, bottom); return new Box2(left, top, right, bottom);
} }
/// <summary>
/// Gets a float describing the width of the Box2 structure.
/// </summary>
public float Width { get { return (float)System.Math.Abs(Right - Left); } }
/// <summary>
/// Gets a float describing the height of the Box2 structure.
/// </summary>
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);
}
} }
} }