mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-06-29 13:59:34 +00:00
remove FromCorners, add Contains overloads
This commit is contained in:
parent
adeda6b7d1
commit
e0d4fd2e81
|
@ -99,40 +99,6 @@ namespace OpenTK
|
||||||
return FromDimensions(position.X, position.Y, size.X, size.Y);
|
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>
|
/// <summary>
|
||||||
/// Gets a float describing the width of the Box2 structure.
|
/// Gets a float describing the width of the Box2 structure.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -144,13 +110,32 @@ namespace OpenTK
|
||||||
public float Height { get { return (float)System.Math.Abs(Bottom - Top); } }
|
public float Height { get { return (float)System.Math.Abs(Bottom - Top); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
/// <param name="point">The point to query.</param>
|
/// <param name="point">The point to query.</param>
|
||||||
/// <returns>Whether this box contains the point.</returns>
|
/// <returns>Whether this box contains the point.</returns>
|
||||||
public bool Contains(Vector2 point)
|
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>
|
/// <summary>
|
||||||
|
|
|
@ -99,40 +99,6 @@ namespace OpenTK
|
||||||
return FromDimensions(position.X, position.Y, size.X, size.Y);
|
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>
|
/// <summary>
|
||||||
/// Gets a double describing the width of the Box2d structure.
|
/// Gets a double describing the width of the Box2d structure.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -144,13 +110,32 @@ namespace OpenTK
|
||||||
public double Height { get { return (double)System.Math.Abs(Bottom - Top); } }
|
public double Height { get { return (double)System.Math.Abs(Bottom - Top); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
/// <param name="point">The point to query.</param>
|
/// <param name="point">The point to query.</param>
|
||||||
/// <returns>Whether this box contains the point.</returns>
|
/// <returns>Whether this box contains the point.</returns>
|
||||||
public bool Contains(Vector2d point)
|
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>
|
/// <summary>
|
||||||
|
|
|
@ -162,6 +162,7 @@
|
||||||
<Compile Include="..\GlobalAssemblyInfo.cs">
|
<Compile Include="..\GlobalAssemblyInfo.cs">
|
||||||
<Link>Properties\GlobalAssemblyInfo.cs</Link>
|
<Link>Properties\GlobalAssemblyInfo.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Math\Box2d.cs" />
|
||||||
<Compile Include="DisplayDevice.cs">
|
<Compile Include="DisplayDevice.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -894,8 +895,5 @@
|
||||||
</MonoDevelop>
|
</MonoDevelop>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<ItemGroup>
|
<ItemGroup />
|
||||||
<Folder Include="Platform\Linux\" />
|
|
||||||
<Folder Include="Platform\Linux\Bindings\" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in a new issue