remove FromCorners, add Contains overloads
authorkevin <sudo@pt-get.com>
Sun, 6 Mar 2016 22:01:11 +0000 (14:01 -0800)
committerkevin <sudo@pt-get.com>
Sun, 6 Mar 2016 22:01:11 +0000 (14:01 -0800)
Source/OpenTK/Math/Box2.cs
Source/OpenTK/Math/Box2d.cs
Source/OpenTK/OpenTK.csproj

index cf2d390..7075198 100644 (file)
@@ -100,40 +100,6 @@ namespace OpenTK
         }
 
         /// <summary>
-        /// Creates a new Box2 from the specified corners.
-        /// </summary>
-        /// <param name="corner1">One of the corners of the box.</param>
-        /// <param name="corner2">The opposite corner of the box.</param>
-        /// <returns></returns>
-        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;
-        }
-
-        /// <summary>
         /// Gets a float describing the width of the Box2 structure.
         /// </summary>
         public float Width { get { return (float)System.Math.Abs(Right - Left); } }
@@ -144,13 +110,32 @@ namespace OpenTK
         public float Height { get { return (float)System.Math.Abs(Bottom - Top); } }
 
         /// <summary>
-        /// Returns whether the box contains the specified point.
+        /// Returns whether the box contains the specified point on the closed region described by this Box2.
         /// </summary>
         /// <param name="point">The point to query.</param>
         /// <returns>Whether this box contains the point.</returns>
         public bool Contains(Vector2 point)
         {
-            return (point.X >= Left != point.X > Right) && (point.Y >= Top != point.Y > Bottom);
+            return Contains(point, true);
+        }
+
+        /// <summary>
+        /// Returns whether the box contains the specified point.
+        /// </summary>
+        /// <param name="point">The point to query.</param>
+        /// <param name="closedRegion">Whether to include the box boundary in the test region.</param>
+        /// <returns>Whether this box contains the point.</returns>
+        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;
         }
 
         /// <summary>
index 5fa6059..c1f5081 100644 (file)
@@ -100,40 +100,6 @@ namespace OpenTK
         }
 
         /// <summary>
-        /// Creates a new Box2d from the specified corners.
-        /// </summary>
-        /// <param name="corner1">One of the corners of the box.</param>
-        /// <param name="corner2">The opposite corner of the box.</param>
-        /// <returns></returns>
-        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;
-        }
-
-        /// <summary>
         /// Gets a double describing the width of the Box2d structure.
         /// </summary>
         public double Width { get { return (double)System.Math.Abs(Right - Left); } }
@@ -144,13 +110,32 @@ namespace OpenTK
         public double Height { get { return (double)System.Math.Abs(Bottom - Top); } }
 
         /// <summary>
-        /// Returns whether the box contains the specified point.
+        /// Returns whether the box contains the specified point on the closed region described by this Box2.
         /// </summary>
         /// <param name="point">The point to query.</param>
         /// <returns>Whether this box contains the point.</returns>
         public bool Contains(Vector2d point)
         {
-            return (point.X >= Left != point.X > Right) && (point.Y >= Top != point.Y > Bottom);
+            return Contains(point, true);
+        }
+
+        /// <summary>
+        /// Returns whether the box contains the specified point.
+        /// </summary>
+        /// <param name="point">The point to query.</param>
+        /// <param name="closedRegion">Whether to include the box boundary in the test region.</param>
+        /// <returns>Whether this box contains the point.</returns>
+        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;
         }
 
         /// <summary>
index e5f7937..d15987e 100644 (file)
     <Compile Include="..\GlobalAssemblyInfo.cs">
       <Link>Properties\GlobalAssemblyInfo.cs</Link>
     </Compile>
+    <Compile Include="Math\Box2d.cs" />
     <Compile Include="DisplayDevice.cs">
       <SubType>Code</SubType>
     </Compile>
     </MonoDevelop>
   </ProjectExtensions>
   <ItemGroup />
-  <ItemGroup>
-    <Folder Include="Platform\Linux\" />
-    <Folder Include="Platform\Linux\Bindings\" />
-  </ItemGroup>
+  <ItemGroup />
 </Project>
\ No newline at end of file