remove FromCorners, add Contains overloads

This commit is contained in:
kevin 2016-03-06 14:01:11 -08:00
parent adeda6b7d1
commit e0d4fd2e81
3 changed files with 44 additions and 76 deletions

View file

@ -99,40 +99,6 @@ namespace OpenTK
return FromDimensions(position.X, position.Y, size.X, size.Y);
}
/// <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>
@ -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>

View file

@ -99,40 +99,6 @@ namespace OpenTK
return FromDimensions(position.X, position.Y, size.X, size.Y);
}
/// <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>
@ -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>

View file

@ -162,6 +162,7 @@
<Compile Include="..\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Math\Box2d.cs" />
<Compile Include="DisplayDevice.cs">
<SubType>Code</SubType>
</Compile>
@ -894,8 +895,5 @@
</MonoDevelop>
</ProjectExtensions>
<ItemGroup />
<ItemGroup>
<Folder Include="Platform\Linux\" />
<Folder Include="Platform\Linux\Bindings\" />
</ItemGroup>
<ItemGroup />
</Project>