From 3008a25ef3a2f2cba79ada1d3cfc586589a67b22 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 2 Mar 2016 18:56:43 -0800 Subject: [PATCH 1/7] add more functionality to Box2 --- Source/OpenTK/Math/Box2.cs | 135 ++++++++++++++++++++++++++++++++++--- 1 file changed, 127 insertions(+), 8 deletions(-) diff --git a/Source/OpenTK/Math/Box2.cs b/Source/OpenTK/Math/Box2.cs index 4c54b622..a3dbf254 100644 --- a/Source/OpenTK/Math/Box2.cs +++ b/Source/OpenTK/Math/Box2.cs @@ -5,15 +5,13 @@ #endregion using System; -using System.Collections.Generic; -using System.Text; using System.Runtime.InteropServices; namespace OpenTK { - /// - /// Defines a 2d box (rectangle). - /// - [StructLayout(LayoutKind.Sequential)] + /// + /// Defines a 2d box (rectangle). + /// + [StructLayout(LayoutKind.Sequential)] public struct Box2 { /// @@ -39,7 +37,7 @@ namespace OpenTK /// /// Constructs a new Box2 with the specified dimensions. /// - /// AnOpenTK.Vector2 describing the top-left corner of the Box2. + /// An OpenTK.Vector2 describing the top-left corner of the Box2. /// An OpenTK.Vector2 describing the bottom-right corner of the Box2. public Box2(Vector2 topLeft, Vector2 bottomRight) { @@ -77,6 +75,64 @@ namespace OpenTK return new Box2(left, top, right, bottom); } + /// + /// Creates a new Box2 with the specified dimensions. + /// + /// The position of the top boundary. + /// The position of the left boundary. + /// The width of the box. + /// The height of the box. + /// A new OpenTK.Box2 with the specfied dimensions. + public static Box2 FromDimensions(float left, float top, float width, float height) + { + return new Box2(left, top, left + width, top + height); + } + + /// + /// Creates a new Box2 with the specified dimensions. + /// + /// The position of the top left corner. + /// The size of the box. + /// A new OpenTK.Box2 with the specfied dimensions. + public static Box2 FromDimensions(Vector2 position, Vector2 size) + { + return FromDimensions(position.X, position.Y, size.X, size.Y); + } + + /// + /// Creates a new Box2 from the specified corners. + /// + /// One of the corners of the box. + /// The opposite corner of the box. + /// + public static Box2 FromCorners(Vector2 corner1, Vector2 corner2) + { + Box2 box; + if (corner1.X < corner2.X) + { + box.Left = corner1.X; + box.Right = corner2.X; + } + else + { + box.Left = corner2.X; + box.Right = corner1.X; + } + + if (corner1.Y < corner2.Y) + { + box.Top = corner1.Y; + box.Bottom = corner2.Y; + } + else + { + box.Top = corner2.Y; + box.Bottom = corner1.Y; + } + + return box; + } + /// /// Gets a float describing the width of the Box2 structure. /// @@ -87,13 +143,76 @@ namespace OpenTK /// public float Height { get { return (float)System.Math.Abs(Bottom - Top); } } + /// + /// Returns whether the box contains the specified point. + /// + /// The point to query. + /// Whether this box contains the point. + public bool Contains(Vector2 point) + { + return (point.X >= Left != point.X > Right) && (point.Y >= Top != point.Y > Bottom); + } + + /// + /// Returns a Box2 translated by the given amount. + /// + /// + /// + public Box2 Translate(Vector2 point) + { + return new Box2(Left + point.X, Top + point.Y, Right + point.X, Bottom + point.Y); + } + + /// + /// Equality comparator. + /// + public static bool operator ==(Box2 left, Box2 right) + { + return left.Bottom == right.Bottom && left.Top == right.Top && + left.Left == right.Left && left.Right == right.Right; + } + + /// + /// Inequality comparator. + /// + public static bool operator !=(Box2 left, Box2 right) + { + return !(left == right); + } + + /// + /// Functional equality comparator. + /// + public bool Equals(Box2 other) + { + return this == other; + } + + /// + /// Implements Object.Equals. + /// + public override bool Equals(object obj) + { + return obj is Box2 && Equals((Box2) obj); + } + + /// + /// Gets the hash code for this Box2. + /// + /// + public override int GetHashCode() + { + return Left.GetHashCode() ^ Right.GetHashCode() ^ Top.GetHashCode() ^ Bottom.GetHashCode(); + } + + private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator; /// /// Returns a describing the current instance. /// /// public override string ToString() { - return String.Format("({0},{1})-({2},{3})", Left, Top, Right, Bottom); + return String.Format("({0}{4} {1}) - ({2}{4} {3})", Left, Top, Right, Bottom, listSeparator); } } } From 9a923954f65215c368706880b3b03c13b6d61d3c Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 2 Mar 2016 20:22:52 -0800 Subject: [PATCH 2/7] add double precision Box2 --- Source/OpenTK/Math/Box2d.cs | 218 ++++++++++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 Source/OpenTK/Math/Box2d.cs diff --git a/Source/OpenTK/Math/Box2d.cs b/Source/OpenTK/Math/Box2d.cs new file mode 100644 index 00000000..eae7f46e --- /dev/null +++ b/Source/OpenTK/Math/Box2d.cs @@ -0,0 +1,218 @@ +#region --- License --- +/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos + * See license.txt for license info + */ +#endregion + +using System; +using System.Runtime.InteropServices; +namespace OpenTK +{ + /// + /// Defines a 2d box (rectangle). + /// + [StructLayout(LayoutKind.Sequential)] + public struct Box2d + { + /// + /// The left boundary of the structure. + /// + public double Left; + + /// + /// The right boundary of the structure. + /// + public double Right; + + /// + /// The top boundary of the structure. + /// + public double Top; + + /// + /// The bottom boundary of the structure. + /// + public double Bottom; + + /// + /// Constructs a new Box2d with the specified dimensions. + /// + /// An OpenTK.Vector2d describing the top-left corner of the Box2d. + /// An OpenTK.Vector2d describing the bottom-right corner of the Box2d. + public Box2d(Vector2d topLeft, Vector2d bottomRight) + { + Left = topLeft.X; + Top = topLeft.Y; + Right = bottomRight.X; + Bottom = bottomRight.Y; + } + + /// + /// Constructs a new Box2d 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 Box2d(double left, double top, double right, double bottom) + { + Left = left; + Top = top; + Right = right; + Bottom = bottom; + } + + /// + /// Creates a new Box2d 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.Box2d with the specfied dimensions. + public static Box2d FromTLRB(double top, double left, double right, double bottom) + { + return new Box2d(left, top, right, bottom); + } + + /// + /// Creates a new Box2d with the specified dimensions. + /// + /// The position of the top boundary. + /// The position of the left boundary. + /// The width of the box. + /// The height of the box. + /// A new OpenTK.Box2d with the specfied dimensions. + public static Box2d FromDimensions(double left, double top, double width, double height) + { + return new Box2d(left, top, left + width, top + height); + } + + /// + /// Creates a new Box2d with the specified dimensions. + /// + /// The position of the top left corner. + /// The size of the box. + /// A new OpenTK.Box2d with the specfied dimensions. + public static Box2d FromDimensions(Vector2d position, Vector2d size) + { + return FromDimensions(position.X, position.Y, size.X, size.Y); + } + + /// + /// Creates a new Box2d from the specified corners. + /// + /// One of the corners of the box. + /// The opposite corner of the box. + /// + public static Box2d FromCorners(Vector2d corner1, Vector2d corner2) + { + Box2d box; + if (corner1.X < corner2.X) + { + box.Left = corner1.X; + box.Right = corner2.X; + } + else + { + box.Left = corner2.X; + box.Right = corner1.X; + } + + if (corner1.Y < corner2.Y) + { + box.Top = corner1.Y; + box.Bottom = corner2.Y; + } + else + { + box.Top = corner2.Y; + box.Bottom = corner1.Y; + } + + return box; + } + + /// + /// Gets a double describing the width of the Box2d structure. + /// + public double Width { get { return (double)System.Math.Abs(Right - Left); } } + + /// + /// Gets a double describing the height of the Box2d structure. + /// + public double Height { get { return (double)System.Math.Abs(Bottom - Top); } } + + /// + /// Returns whether the box contains the specified point. + /// + /// The point to query. + /// Whether this box contains the point. + public bool Contains(Vector2d point) + { + return (point.X >= Left != point.X > Right) && (point.Y >= Top != point.Y > Bottom); + } + + /// + /// Returns a Box2d translated by the given amount. + /// + /// + /// + public Box2d Translate(Vector2d point) + { + return new Box2d(Left + point.X, Top + point.Y, Right + point.X, Bottom + point.Y); + } + + /// + /// Equality comparator. + /// + public static bool operator ==(Box2d left, Box2d right) + { + return left.Bottom == right.Bottom && left.Top == right.Top && + left.Left == right.Left && left.Right == right.Right; + } + + /// + /// Inequality comparator. + /// + public static bool operator !=(Box2d left, Box2d right) + { + return !(left == right); + } + + /// + /// Functional equality comparator. + /// + public bool Equals(Box2d other) + { + return this == other; + } + + /// + /// Implements Object.Equals. + /// + public override bool Equals(object obj) + { + return obj is Box2d && Equals((Box2d) obj); + } + + /// + /// Gets the hash code for this Box2d. + /// + /// + public override int GetHashCode() + { + return Left.GetHashCode() ^ Right.GetHashCode() ^ Top.GetHashCode() ^ Bottom.GetHashCode(); + } + + private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator; + /// + /// Returns a describing the current instance. + /// + /// + public override string ToString() + { + return String.Format("({0}{4} {1}) - ({2}{4} {3})", Left, Top, Right, Bottom, listSeparator); + } + } +} From 1e81187aeb4d7922e7c13e8a3ea63361790cc8ab Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 2 Mar 2016 20:27:03 -0800 Subject: [PATCH 3/7] normalize indentation --- Source/OpenTK/Math/Box2.cs | 198 ++++++++++++++++++------------------ Source/OpenTK/Math/Box2d.cs | 198 ++++++++++++++++++------------------ 2 files changed, 198 insertions(+), 198 deletions(-) diff --git a/Source/OpenTK/Math/Box2.cs b/Source/OpenTK/Math/Box2.cs index a3dbf254..0abfa8ce 100644 --- a/Source/OpenTK/Math/Box2.cs +++ b/Source/OpenTK/Math/Box2.cs @@ -8,10 +8,10 @@ using System; using System.Runtime.InteropServices; namespace OpenTK { - /// - /// Defines a 2d box (rectangle). - /// - [StructLayout(LayoutKind.Sequential)] + /// + /// Defines a 2d box (rectangle). + /// + [StructLayout(LayoutKind.Sequential)] public struct Box2 { /// @@ -75,62 +75,62 @@ namespace OpenTK return new Box2(left, top, right, bottom); } - /// + /// /// Creates a new Box2 with the specified dimensions. /// /// The position of the top boundary. /// The position of the left boundary. - /// The width of the box. - /// The height of the box. + /// The width of the box. + /// The height of the box. /// A new OpenTK.Box2 with the specfied dimensions. - public static Box2 FromDimensions(float left, float top, float width, float height) - { - return new Box2(left, top, left + width, top + height); - } + public static Box2 FromDimensions(float left, float top, float width, float height) + { + return new Box2(left, top, left + width, top + height); + } - /// + /// /// Creates a new Box2 with the specified dimensions. /// /// The position of the top left corner. /// The size of the box. /// A new OpenTK.Box2 with the specfied dimensions. - public static Box2 FromDimensions(Vector2 position, Vector2 size) - { - return FromDimensions(position.X, position.Y, size.X, size.Y); - } + public static Box2 FromDimensions(Vector2 position, Vector2 size) + { + return FromDimensions(position.X, position.Y, size.X, size.Y); + } - /// - /// Creates a new Box2 from the specified corners. - /// - /// One of the corners of the box. - /// The opposite corner of the box. - /// + /// + /// Creates a new Box2 from the specified corners. + /// + /// One of the corners of the box. + /// The opposite corner of the box. + /// public static Box2 FromCorners(Vector2 corner1, Vector2 corner2) { - Box2 box; - if (corner1.X < corner2.X) - { - box.Left = corner1.X; - box.Right = corner2.X; - } - else - { - box.Left = corner2.X; - box.Right = corner1.X; - } + Box2 box; + if (corner1.X < corner2.X) + { + box.Left = corner1.X; + box.Right = corner2.X; + } + else + { + box.Left = corner2.X; + box.Right = corner1.X; + } - if (corner1.Y < corner2.Y) - { - box.Top = corner1.Y; - box.Bottom = corner2.Y; - } - else - { - box.Top = corner2.Y; - box.Bottom = corner1.Y; - } + if (corner1.Y < corner2.Y) + { + box.Top = corner1.Y; + box.Bottom = corner2.Y; + } + else + { + box.Top = corner2.Y; + box.Bottom = corner1.Y; + } - return box; + return box; } /// @@ -143,67 +143,67 @@ namespace OpenTK /// public float Height { get { return (float)System.Math.Abs(Bottom - Top); } } - /// - /// Returns whether the box contains the specified point. - /// - /// The point to query. - /// Whether this box contains the point. - public bool Contains(Vector2 point) - { - return (point.X >= Left != point.X > Right) && (point.Y >= Top != point.Y > Bottom); - } + /// + /// Returns whether the box contains the specified point. + /// + /// The point to query. + /// Whether this box contains the point. + public bool Contains(Vector2 point) + { + return (point.X >= Left != point.X > Right) && (point.Y >= Top != point.Y > Bottom); + } - /// - /// Returns a Box2 translated by the given amount. - /// - /// - /// - public Box2 Translate(Vector2 point) - { - return new Box2(Left + point.X, Top + point.Y, Right + point.X, Bottom + point.Y); - } + /// + /// Returns a Box2 translated by the given amount. + /// + /// + /// + public Box2 Translate(Vector2 point) + { + return new Box2(Left + point.X, Top + point.Y, Right + point.X, Bottom + point.Y); + } - /// - /// Equality comparator. - /// - public static bool operator ==(Box2 left, Box2 right) - { - return left.Bottom == right.Bottom && left.Top == right.Top && - left.Left == right.Left && left.Right == right.Right; - } + /// + /// Equality comparator. + /// + public static bool operator ==(Box2 left, Box2 right) + { + return left.Bottom == right.Bottom && left.Top == right.Top && + left.Left == right.Left && left.Right == right.Right; + } - /// - /// Inequality comparator. - /// - public static bool operator !=(Box2 left, Box2 right) - { - return !(left == right); - } + /// + /// Inequality comparator. + /// + public static bool operator !=(Box2 left, Box2 right) + { + return !(left == right); + } - /// - /// Functional equality comparator. - /// - public bool Equals(Box2 other) - { - return this == other; - } + /// + /// Functional equality comparator. + /// + public bool Equals(Box2 other) + { + return this == other; + } - /// - /// Implements Object.Equals. - /// - public override bool Equals(object obj) - { - return obj is Box2 && Equals((Box2) obj); - } + /// + /// Implements Object.Equals. + /// + public override bool Equals(object obj) + { + return obj is Box2 && Equals((Box2) obj); + } - /// - /// Gets the hash code for this Box2. - /// - /// - public override int GetHashCode() - { - return Left.GetHashCode() ^ Right.GetHashCode() ^ Top.GetHashCode() ^ Bottom.GetHashCode(); - } + /// + /// Gets the hash code for this Box2. + /// + /// + public override int GetHashCode() + { + return Left.GetHashCode() ^ Right.GetHashCode() ^ Top.GetHashCode() ^ Bottom.GetHashCode(); + } private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator; /// diff --git a/Source/OpenTK/Math/Box2d.cs b/Source/OpenTK/Math/Box2d.cs index eae7f46e..6ae120fe 100644 --- a/Source/OpenTK/Math/Box2d.cs +++ b/Source/OpenTK/Math/Box2d.cs @@ -8,10 +8,10 @@ using System; using System.Runtime.InteropServices; namespace OpenTK { - /// - /// Defines a 2d box (rectangle). - /// - [StructLayout(LayoutKind.Sequential)] + /// + /// Defines a 2d box (rectangle). + /// + [StructLayout(LayoutKind.Sequential)] public struct Box2d { /// @@ -75,62 +75,62 @@ namespace OpenTK return new Box2d(left, top, right, bottom); } - /// + /// /// Creates a new Box2d with the specified dimensions. /// /// The position of the top boundary. /// The position of the left boundary. - /// The width of the box. - /// The height of the box. + /// The width of the box. + /// The height of the box. /// A new OpenTK.Box2d with the specfied dimensions. - public static Box2d FromDimensions(double left, double top, double width, double height) - { - return new Box2d(left, top, left + width, top + height); - } + public static Box2d FromDimensions(double left, double top, double width, double height) + { + return new Box2d(left, top, left + width, top + height); + } - /// + /// /// Creates a new Box2d with the specified dimensions. /// /// The position of the top left corner. /// The size of the box. /// A new OpenTK.Box2d with the specfied dimensions. - public static Box2d FromDimensions(Vector2d position, Vector2d size) - { - return FromDimensions(position.X, position.Y, size.X, size.Y); - } + public static Box2d FromDimensions(Vector2d position, Vector2d size) + { + return FromDimensions(position.X, position.Y, size.X, size.Y); + } - /// - /// Creates a new Box2d from the specified corners. - /// - /// One of the corners of the box. - /// The opposite corner of the box. - /// + /// + /// Creates a new Box2d from the specified corners. + /// + /// One of the corners of the box. + /// The opposite corner of the box. + /// public static Box2d FromCorners(Vector2d corner1, Vector2d corner2) { - Box2d box; - if (corner1.X < corner2.X) - { - box.Left = corner1.X; - box.Right = corner2.X; - } - else - { - box.Left = corner2.X; - box.Right = corner1.X; - } + Box2d box; + if (corner1.X < corner2.X) + { + box.Left = corner1.X; + box.Right = corner2.X; + } + else + { + box.Left = corner2.X; + box.Right = corner1.X; + } - if (corner1.Y < corner2.Y) - { - box.Top = corner1.Y; - box.Bottom = corner2.Y; - } - else - { - box.Top = corner2.Y; - box.Bottom = corner1.Y; - } + if (corner1.Y < corner2.Y) + { + box.Top = corner1.Y; + box.Bottom = corner2.Y; + } + else + { + box.Top = corner2.Y; + box.Bottom = corner1.Y; + } - return box; + return box; } /// @@ -143,67 +143,67 @@ namespace OpenTK /// public double Height { get { return (double)System.Math.Abs(Bottom - Top); } } - /// - /// Returns whether the box contains the specified point. - /// - /// The point to query. - /// Whether this box contains the point. - public bool Contains(Vector2d point) - { - return (point.X >= Left != point.X > Right) && (point.Y >= Top != point.Y > Bottom); - } + /// + /// Returns whether the box contains the specified point. + /// + /// The point to query. + /// Whether this box contains the point. + public bool Contains(Vector2d point) + { + return (point.X >= Left != point.X > Right) && (point.Y >= Top != point.Y > Bottom); + } - /// - /// Returns a Box2d translated by the given amount. - /// - /// - /// - public Box2d Translate(Vector2d point) - { - return new Box2d(Left + point.X, Top + point.Y, Right + point.X, Bottom + point.Y); - } + /// + /// Returns a Box2d translated by the given amount. + /// + /// + /// + public Box2d Translate(Vector2d point) + { + return new Box2d(Left + point.X, Top + point.Y, Right + point.X, Bottom + point.Y); + } - /// - /// Equality comparator. - /// - public static bool operator ==(Box2d left, Box2d right) - { - return left.Bottom == right.Bottom && left.Top == right.Top && - left.Left == right.Left && left.Right == right.Right; - } + /// + /// Equality comparator. + /// + public static bool operator ==(Box2d left, Box2d right) + { + return left.Bottom == right.Bottom && left.Top == right.Top && + left.Left == right.Left && left.Right == right.Right; + } - /// - /// Inequality comparator. - /// - public static bool operator !=(Box2d left, Box2d right) - { - return !(left == right); - } + /// + /// Inequality comparator. + /// + public static bool operator !=(Box2d left, Box2d right) + { + return !(left == right); + } - /// - /// Functional equality comparator. - /// - public bool Equals(Box2d other) - { - return this == other; - } + /// + /// Functional equality comparator. + /// + public bool Equals(Box2d other) + { + return this == other; + } - /// - /// Implements Object.Equals. - /// - public override bool Equals(object obj) - { - return obj is Box2d && Equals((Box2d) obj); - } + /// + /// Implements Object.Equals. + /// + public override bool Equals(object obj) + { + return obj is Box2d && Equals((Box2d) obj); + } - /// - /// Gets the hash code for this Box2d. - /// - /// - public override int GetHashCode() - { - return Left.GetHashCode() ^ Right.GetHashCode() ^ Top.GetHashCode() ^ Bottom.GetHashCode(); - } + /// + /// Gets the hash code for this Box2d. + /// + /// + public override int GetHashCode() + { + return Left.GetHashCode() ^ Right.GetHashCode() ^ Top.GetHashCode() ^ Bottom.GetHashCode(); + } private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator; /// From adeda6b7d12698d302faba4be0f1703b19265b22 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 2 Mar 2016 20:35:20 -0800 Subject: [PATCH 4/7] distinguish between Translate and Translated --- Source/OpenTK/Math/Box2.cs | 15 ++++++++++++--- Source/OpenTK/Math/Box2d.cs | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Source/OpenTK/Math/Box2.cs b/Source/OpenTK/Math/Box2.cs index 0abfa8ce..cf2d3906 100644 --- a/Source/OpenTK/Math/Box2.cs +++ b/Source/OpenTK/Math/Box2.cs @@ -156,13 +156,22 @@ namespace OpenTK /// /// Returns a Box2 translated by the given amount. /// - /// - /// - public Box2 Translate(Vector2 point) + public Box2 Translated(Vector2 point) { return new Box2(Left + point.X, Top + point.Y, Right + point.X, Bottom + point.Y); } + /// + /// Translates this Box2 by the given amount. + /// + public void Translate(Vector2 point) + { + Left += point.X; + Right += point.X; + Top += point.Y; + Bottom += point.Y; + } + /// /// Equality comparator. /// diff --git a/Source/OpenTK/Math/Box2d.cs b/Source/OpenTK/Math/Box2d.cs index 6ae120fe..5fa6059c 100644 --- a/Source/OpenTK/Math/Box2d.cs +++ b/Source/OpenTK/Math/Box2d.cs @@ -156,13 +156,22 @@ namespace OpenTK /// /// Returns a Box2d translated by the given amount. /// - /// - /// - public Box2d Translate(Vector2d point) + public Box2d Translated(Vector2d point) { return new Box2d(Left + point.X, Top + point.Y, Right + point.X, Bottom + point.Y); } + /// + /// Translates this Box2d by the given amount. + /// + public void Translate(Vector2d point) + { + Left += point.X; + Right += point.X; + Top += point.Y; + Bottom += point.Y; + } + /// /// Equality comparator. /// From e0d4fd2e817ee984b38e53230cc3cf1707e0e204 Mon Sep 17 00:00:00 2001 From: kevin Date: Sun, 6 Mar 2016 14:01:11 -0800 Subject: [PATCH 5/7] remove FromCorners, add Contains overloads --- Source/OpenTK/Math/Box2.cs | 57 ++++++++++++++----------------------- Source/OpenTK/Math/Box2d.cs | 57 ++++++++++++++----------------------- Source/OpenTK/OpenTK.csproj | 6 ++-- 3 files changed, 44 insertions(+), 76 deletions(-) diff --git a/Source/OpenTK/Math/Box2.cs b/Source/OpenTK/Math/Box2.cs index cf2d3906..70751981 100644 --- a/Source/OpenTK/Math/Box2.cs +++ b/Source/OpenTK/Math/Box2.cs @@ -99,40 +99,6 @@ namespace OpenTK return FromDimensions(position.X, position.Y, size.X, size.Y); } - /// - /// Creates a new Box2 from the specified corners. - /// - /// One of the corners of the box. - /// The opposite corner of the box. - /// - public static Box2 FromCorners(Vector2 corner1, Vector2 corner2) - { - Box2 box; - if (corner1.X < corner2.X) - { - box.Left = corner1.X; - box.Right = corner2.X; - } - else - { - box.Left = corner2.X; - box.Right = corner1.X; - } - - if (corner1.Y < corner2.Y) - { - box.Top = corner1.Y; - box.Bottom = corner2.Y; - } - else - { - box.Top = corner2.Y; - box.Bottom = corner1.Y; - } - - return box; - } - /// /// Gets a float describing the width of the Box2 structure. /// @@ -144,13 +110,32 @@ namespace OpenTK public float Height { get { return (float)System.Math.Abs(Bottom - Top); } } /// - /// Returns whether the box contains the specified point. + /// Returns whether the box contains the specified point on the closed region described by this Box2. /// /// The point to query. /// Whether this box contains the point. public bool Contains(Vector2 point) { - return (point.X >= Left != point.X > Right) && (point.Y >= Top != point.Y > Bottom); + return Contains(point, true); + } + + /// + /// Returns whether the box contains the specified point. + /// + /// The point to query. + /// Whether to include the box boundary in the test region. + /// Whether this box contains the point. + public bool Contains(Vector2 point, bool closedRegion) + { + bool xOK = (closedRegion == Left <= Right) ? + (point.X >= Left != point.X > Right) : + (point.X > Left != point.X >= Right); + + bool yOK = (closedRegion == Top <= Bottom) ? + (point.Y >= Top != point.Y > Bottom) : + (point.Y > Top != point.Y >= Bottom); + + return xOK && yOK; } /// diff --git a/Source/OpenTK/Math/Box2d.cs b/Source/OpenTK/Math/Box2d.cs index 5fa6059c..c1f50818 100644 --- a/Source/OpenTK/Math/Box2d.cs +++ b/Source/OpenTK/Math/Box2d.cs @@ -99,40 +99,6 @@ namespace OpenTK return FromDimensions(position.X, position.Y, size.X, size.Y); } - /// - /// Creates a new Box2d from the specified corners. - /// - /// One of the corners of the box. - /// The opposite corner of the box. - /// - public static Box2d FromCorners(Vector2d corner1, Vector2d corner2) - { - Box2d box; - if (corner1.X < corner2.X) - { - box.Left = corner1.X; - box.Right = corner2.X; - } - else - { - box.Left = corner2.X; - box.Right = corner1.X; - } - - if (corner1.Y < corner2.Y) - { - box.Top = corner1.Y; - box.Bottom = corner2.Y; - } - else - { - box.Top = corner2.Y; - box.Bottom = corner1.Y; - } - - return box; - } - /// /// Gets a double describing the width of the Box2d structure. /// @@ -144,13 +110,32 @@ namespace OpenTK public double Height { get { return (double)System.Math.Abs(Bottom - Top); } } /// - /// Returns whether the box contains the specified point. + /// Returns whether the box contains the specified point on the closed region described by this Box2. /// /// The point to query. /// Whether this box contains the point. public bool Contains(Vector2d point) { - return (point.X >= Left != point.X > Right) && (point.Y >= Top != point.Y > Bottom); + return Contains(point, true); + } + + /// + /// Returns whether the box contains the specified point. + /// + /// The point to query. + /// Whether to include the box boundary in the test region. + /// Whether this box contains the point. + public bool Contains(Vector2d point, bool closedRegion) + { + bool xOK = (closedRegion == Left <= Right) ? + (point.X >= Left != point.X > Right) : + (point.X > Left != point.X >= Right); + + bool yOK = (closedRegion == Top <= Bottom) ? + (point.Y >= Top != point.Y > Bottom) : + (point.Y > Top != point.Y >= Bottom); + + return xOK && yOK; } /// diff --git a/Source/OpenTK/OpenTK.csproj b/Source/OpenTK/OpenTK.csproj index e5f7937a..d15987e7 100644 --- a/Source/OpenTK/OpenTK.csproj +++ b/Source/OpenTK/OpenTK.csproj @@ -162,6 +162,7 @@ Properties\GlobalAssemblyInfo.cs + Code @@ -894,8 +895,5 @@ - - - - + \ No newline at end of file From 01bbb0ef3488a516e337dc579c69e48c5ca1227e Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 7 Mar 2016 12:42:33 -0800 Subject: [PATCH 6/7] update license text for Box2* --- Source/OpenTK/Math/Box2.cs | 24 +++++++++++++++++++++--- Source/OpenTK/Math/Box2d.cs | 24 +++++++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Source/OpenTK/Math/Box2.cs b/Source/OpenTK/Math/Box2.cs index 70751981..5dcb899e 100644 --- a/Source/OpenTK/Math/Box2.cs +++ b/Source/OpenTK/Math/Box2.cs @@ -1,7 +1,25 @@ #region --- License --- -/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos - * See license.txt for license info - */ +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ #endregion using System; diff --git a/Source/OpenTK/Math/Box2d.cs b/Source/OpenTK/Math/Box2d.cs index c1f50818..ab6b72f1 100644 --- a/Source/OpenTK/Math/Box2d.cs +++ b/Source/OpenTK/Math/Box2d.cs @@ -1,7 +1,25 @@ #region --- License --- -/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos - * See license.txt for license info - */ +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ #endregion using System; From 44adf713d2c1024c12d56ae7752c09b19177e191 Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 7 Mar 2016 13:03:03 -0800 Subject: [PATCH 7/7] update license headers --- Source/OpenTK/Math/Box2.cs | 24 +++--------------------- Source/OpenTK/Math/Box2d.cs | 24 +++--------------------- 2 files changed, 6 insertions(+), 42 deletions(-) diff --git a/Source/OpenTK/Math/Box2.cs b/Source/OpenTK/Math/Box2.cs index 5dcb899e..418a7c7a 100644 --- a/Source/OpenTK/Math/Box2.cs +++ b/Source/OpenTK/Math/Box2.cs @@ -1,25 +1,7 @@ #region --- License --- -/* -Copyright (c) 2006 - 2008 The Open Toolkit library. - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +// Copyright (c) Open Toolkit library. +// This file is subject to the terms and conditions defined in +// file 'License.txt', which is part of this source code package. #endregion using System; diff --git a/Source/OpenTK/Math/Box2d.cs b/Source/OpenTK/Math/Box2d.cs index ab6b72f1..78fe467c 100644 --- a/Source/OpenTK/Math/Box2d.cs +++ b/Source/OpenTK/Math/Box2d.cs @@ -1,25 +1,7 @@ #region --- License --- -/* -Copyright (c) 2006 - 2008 The Open Toolkit library. - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +// Copyright (c) Open Toolkit library. +// This file is subject to the terms and conditions defined in +// file 'License.txt', which is part of this source code package. #endregion using System;