Updated libraries
This commit is contained in:
@@ -999,7 +999,7 @@ namespace FarseerPhysics.Dynamics
|
||||
if (body == null)
|
||||
throw new ArgumentNullException("body");
|
||||
if (body.World != this)
|
||||
throw new ArgumentException("You are removing a body that is not in the simulation.", "body");
|
||||
throw new ArgumentException($"You are removing a body that is not in the simulation (userdata: {body.UserData?.ToString() ?? "null"}).", "body");
|
||||
|
||||
#if USE_AWAKE_BODY_SET
|
||||
Debug.Assert(!AwakeBodySet.Contains(body));
|
||||
@@ -1034,6 +1034,7 @@ namespace FarseerPhysics.Dynamics
|
||||
body.DestroyProxies();
|
||||
for (int i = 0; i < body.FixtureList.Count; i++)
|
||||
{
|
||||
body.FixtureList[i].UserData = null;
|
||||
if (FixtureRemoved != null)
|
||||
FixtureRemoved(this, body, body.FixtureList[i]);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
// file 'LICENSE.txt', which is part of this source code package.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.Xna.Framework.Graphics
|
||||
@@ -25,6 +28,49 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
/// </summary>
|
||||
public class SpriteBatch : GraphicsResource, ISpriteBatch
|
||||
{
|
||||
public struct EffectWithParams
|
||||
{
|
||||
private static readonly Dictionary<Type, MethodInfo> parameterSetters;
|
||||
private static readonly object[] setterParams = new object[1];
|
||||
|
||||
static EffectWithParams()
|
||||
{
|
||||
parameterSetters = new Dictionary<Type, MethodInfo>();
|
||||
foreach (var method in typeof(EffectParameter).GetMethods())
|
||||
{
|
||||
if (method.Name.Equals("SetValue", StringComparison.InvariantCulture)
|
||||
&& method.GetParameters() is { Length: 1 } parameters)
|
||||
{
|
||||
var type = parameters[0].ParameterType;
|
||||
parameterSetters[type] = method;
|
||||
foreach (var derived in Assembly.GetAssembly(type).GetTypes().Where(t => t.IsSubclassOf(type)))
|
||||
{
|
||||
parameterSetters[derived] = method;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Effect Effect;
|
||||
public Dictionary<string, object> Params;
|
||||
|
||||
public EffectWithParams(Effect effect, Dictionary<string, object> parameters = null)
|
||||
{
|
||||
Effect = effect;
|
||||
Params = parameters;
|
||||
}
|
||||
|
||||
internal void Apply()
|
||||
{
|
||||
foreach (var (paramName, paramValue) in Params)
|
||||
{
|
||||
setterParams[0] = paramValue;
|
||||
parameterSetters[paramValue.GetType()].Invoke(Effect.Parameters[paramName], setterParams);
|
||||
}
|
||||
Effect.CurrentTechnique.Passes[0].Apply();
|
||||
}
|
||||
}
|
||||
|
||||
#region Private Fields
|
||||
readonly SpriteBatcher _batcher;
|
||||
|
||||
@@ -33,7 +79,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
SamplerState _samplerState;
|
||||
DepthStencilState _depthStencilState;
|
||||
RasterizerState _rasterizerState;
|
||||
Effect _effect;
|
||||
EffectWithParams _effect;
|
||||
bool _beginCalled;
|
||||
|
||||
Effect _spriteEffect;
|
||||
@@ -107,7 +153,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
_samplerState = samplerState ?? SamplerState.LinearClamp;
|
||||
_depthStencilState = depthStencilState ?? DepthStencilState.None;
|
||||
_rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise;
|
||||
_effect = effect;
|
||||
_effect = new EffectWithParams(effect);
|
||||
_matrix = transformMatrix;
|
||||
|
||||
// Setup things now so a user can change them.
|
||||
@@ -119,6 +165,11 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
_beginCalled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current effect.
|
||||
/// </summary>
|
||||
public Effect GetCurrentEffect() => _effect.Effect;
|
||||
|
||||
/// <summary>
|
||||
/// Flushes all batched text and sprites to the screen.
|
||||
/// </summary>
|
||||
@@ -133,7 +184,20 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
if (_sortMode != SpriteSortMode.Immediate)
|
||||
Setup();
|
||||
|
||||
_batcher.DrawBatch(_sortMode, _effect);
|
||||
_batcher.DrawBatch(_sortMode, _spritePass);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Swaps the current effect.
|
||||
/// </summary>
|
||||
public void SwapEffect(Effect effect = null, Dictionary<string, object> parameters = null)
|
||||
{
|
||||
_effect = new EffectWithParams(effect, parameters);
|
||||
}
|
||||
|
||||
public void SwapEffect(EffectWithParams effectWithParams)
|
||||
{
|
||||
_effect = effectWithParams;
|
||||
}
|
||||
|
||||
void Setup()
|
||||
@@ -279,6 +343,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
{
|
||||
var item = _batcher.CreateBatchItem();
|
||||
item.Texture = texture;
|
||||
item.Effect = _effect;
|
||||
|
||||
item.SortKey = sortKey;
|
||||
|
||||
@@ -315,6 +380,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
var item = _batcher.CreateBatchItem();
|
||||
item.Texture = texture;
|
||||
item.Effect = _effect;
|
||||
|
||||
// set SortKey based on SpriteSortMode.
|
||||
switch ( _sortMode )
|
||||
@@ -447,6 +513,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
var item = _batcher.CreateBatchItem();
|
||||
item.Texture = texture;
|
||||
item.Effect = _effect;
|
||||
|
||||
// set SortKey based on SpriteSortMode.
|
||||
switch ( _sortMode )
|
||||
@@ -539,7 +606,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
{
|
||||
if (_sortMode == SpriteSortMode.Immediate)
|
||||
{
|
||||
_batcher.DrawBatch(_sortMode, _effect);
|
||||
_batcher.DrawBatch(_sortMode, _spritePass);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -556,6 +623,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
var item = _batcher.CreateBatchItem();
|
||||
item.Texture = texture;
|
||||
item.Effect = _effect;
|
||||
|
||||
// set SortKey based on SpriteSortMode.
|
||||
item.SortKey = _sortMode == SpriteSortMode.Texture ? texture.SortingKey : 0;
|
||||
@@ -603,6 +671,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
var item = _batcher.CreateBatchItem();
|
||||
item.Texture = texture;
|
||||
item.Effect = _effect;
|
||||
|
||||
// set SortKey based on SpriteSortMode.
|
||||
item.SortKey = _sortMode == SpriteSortMode.Texture ? texture.SortingKey : 0;
|
||||
@@ -645,6 +714,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
var item = _batcher.CreateBatchItem();
|
||||
item.Texture = texture;
|
||||
item.Effect = _effect;
|
||||
|
||||
// set SortKey based on SpriteSortMode.
|
||||
item.SortKey = _sortMode == SpriteSortMode.Texture ? texture.SortingKey : 0;
|
||||
@@ -673,6 +743,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
var item = _batcher.CreateBatchItem();
|
||||
item.Texture = texture;
|
||||
item.Effect = _effect;
|
||||
|
||||
// set SortKey based on SpriteSortMode.
|
||||
item.SortKey = _sortMode == SpriteSortMode.Texture ? texture.SortingKey : 0;
|
||||
@@ -744,6 +815,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
var item = _batcher.CreateBatchItem();
|
||||
item.Texture = spriteFont.Texture;
|
||||
item.Effect = _effect;
|
||||
item.SortKey = sortKey;
|
||||
|
||||
_texCoordTL.X = pCurrentGlyph->BoundsInTexture.X * spriteFont.Texture.TexelWidth;
|
||||
@@ -918,6 +990,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
var item = _batcher.CreateBatchItem();
|
||||
item.Texture = spriteFont.Texture;
|
||||
item.Effect = _effect;
|
||||
item.SortKey = sortKey;
|
||||
|
||||
_texCoordTL.X = pCurrentGlyph->BoundsInTexture.X * spriteFont.Texture.TexelWidth;
|
||||
@@ -1027,6 +1100,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
var item = _batcher.CreateBatchItem();
|
||||
item.Texture = spriteFont.Texture;
|
||||
item.Effect = _effect;
|
||||
item.SortKey = sortKey;
|
||||
|
||||
_texCoordTL.X = pCurrentGlyph->BoundsInTexture.X * spriteFont.Texture.TexelWidth;
|
||||
@@ -1200,6 +1274,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
var item = _batcher.CreateBatchItem();
|
||||
item.Texture = spriteFont.Texture;
|
||||
item.Effect = _effect;
|
||||
item.SortKey = sortKey;
|
||||
|
||||
_texCoordTL.X = pCurrentGlyph->BoundsInTexture.X * (float)spriteFont.Texture.TexelWidth;
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
internal class SpriteBatchItem : IComparable<SpriteBatchItem>
|
||||
{
|
||||
public Texture2D Texture;
|
||||
public SpriteBatch.EffectWithParams Effect;
|
||||
public float SortKey;
|
||||
|
||||
public VertexPositionColorTexture vertexTL;
|
||||
|
||||
@@ -143,12 +143,8 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
/// overflow the 16 bit array indices for vertices.
|
||||
/// </summary>
|
||||
/// <param name="sortMode">The type of depth sorting desired for the rendering.</param>
|
||||
/// <param name="effect">The custom effect to apply to the drawn geometry</param>
|
||||
public unsafe void DrawBatch(SpriteSortMode sortMode, Effect effect)
|
||||
public unsafe void DrawBatch(SpriteSortMode sortMode, EffectPass defaultSpritePass)
|
||||
{
|
||||
if (effect != null && effect.IsDisposed)
|
||||
throw new ObjectDisposedException("effect");
|
||||
|
||||
// nothing to do
|
||||
if (_batchItemCount == 0)
|
||||
return;
|
||||
@@ -180,6 +176,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
var startIndex = 0;
|
||||
var index = 0;
|
||||
Texture2D tex = null;
|
||||
SpriteBatch.EffectWithParams effect = default;
|
||||
|
||||
int numBatchesToProcess = batchCount;
|
||||
if (numBatchesToProcess > MaxBatchSize)
|
||||
@@ -196,12 +193,24 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
{
|
||||
SpriteBatchItem item = _batchItemList[batchIndex];
|
||||
// if the texture changed, we need to flush and bind the new texture
|
||||
var shouldFlush = !ReferenceEquals(item.Texture, tex);
|
||||
var shouldFlush =
|
||||
!ReferenceEquals(item.Texture, tex)
|
||||
|| !ReferenceEquals(item.Effect.Effect, effect.Effect)
|
||||
|| !ReferenceEquals(item.Effect.Params, effect.Params);
|
||||
if (shouldFlush)
|
||||
{
|
||||
FlushVertexArray(startIndex, index, effect, tex);
|
||||
FlushVertexArray(startIndex, index, effect.Effect, tex);
|
||||
|
||||
tex = item.Texture;
|
||||
effect = item.Effect;
|
||||
if (effect.Effect is null || effect.Params is null)
|
||||
{
|
||||
defaultSpritePass.Apply();
|
||||
}
|
||||
else
|
||||
{
|
||||
effect.Apply();
|
||||
}
|
||||
startIndex = index = 0;
|
||||
vertexArrayPtr = vertexArrayFixedPtr;
|
||||
_device.Textures[0] = tex;
|
||||
@@ -215,10 +224,11 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
|
||||
// Release the texture.
|
||||
item.Texture = null;
|
||||
item.Effect = default;
|
||||
}
|
||||
}
|
||||
// flush the remaining vertexArray data
|
||||
FlushVertexArray(startIndex, index, effect, tex);
|
||||
FlushVertexArray(startIndex, index, effect.Effect, tex);
|
||||
// Update our batch count to continue the process of culling down
|
||||
// large batches
|
||||
batchCount -= numBatchesToProcess;
|
||||
|
||||
551
Libraries/XNATypes/RectangleF.cs
Normal file
551
Libraries/XNATypes/RectangleF.cs
Normal file
@@ -0,0 +1,551 @@
|
||||
// MIT License - Copyright (C) The Mono.Xna Team
|
||||
// This file is subject to the terms and conditions defined in
|
||||
// file 'LICENSE.txt', which is part of this source code package.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Xna.Framework
|
||||
{
|
||||
public struct RectangleF : IEquatable<RectangleF>
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static RectangleF emptyRectangle = new RectangleF();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Fields
|
||||
|
||||
/// <summary>
|
||||
/// The x coordinate of the top-left corner of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
|
||||
public float X;
|
||||
|
||||
/// <summary>
|
||||
/// The y coordinate of the top-left corner of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
|
||||
public float Y;
|
||||
|
||||
/// <summary>
|
||||
/// The width of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
|
||||
public float Width;
|
||||
|
||||
/// <summary>
|
||||
/// The height of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
|
||||
public float Height;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="RectangleF"/> with X=0, Y=0, Width=0, Height=0.
|
||||
/// </summary>
|
||||
public static RectangleF Empty
|
||||
{
|
||||
get { return emptyRectangle; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the x coordinate of the left edge of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
public float Left
|
||||
{
|
||||
get { return this.X; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the x coordinate of the right edge of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
public float Right
|
||||
{
|
||||
get { return (this.X + this.Width); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the y coordinate of the top edge of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
public float Top
|
||||
{
|
||||
get { return this.Y; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the y coordinate of the bottom edge of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
public float Bottom
|
||||
{
|
||||
get { return (this.Y + this.Height); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not this <see cref="RectangleF"/> has a <see cref="Width"/> and
|
||||
/// <see cref="Height"/> of 0, and a <see cref="Location"/> of (0, 0).
|
||||
/// </summary>
|
||||
public bool IsEmpty
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((((this.Width == 0) && (this.Height == 0)) && (this.X == 0)) && (this.Y == 0));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The top-left coordinates of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
public Vector2 Location
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2(this.X, this.Y);
|
||||
}
|
||||
set
|
||||
{
|
||||
X = value.X;
|
||||
Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The width-height coordinates of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
public Vector2 Size
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2(this.Width, this.Height);
|
||||
}
|
||||
set
|
||||
{
|
||||
Width = value.X;
|
||||
Height = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="Point"/> located in the center of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If <see cref="Width"/> or <see cref="Height"/> is an odd number,
|
||||
/// the center point will be rounded down.
|
||||
/// </remarks>
|
||||
public Vector2 Center
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2(this.X + (this.Width / 2f), this.Y + (this.Height / 2f));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Properties
|
||||
|
||||
internal string DebugDisplayString
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Concat(
|
||||
this.X, " ",
|
||||
this.Y, " ",
|
||||
this.Width, " ",
|
||||
this.Height
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="RectangleF"/> struct, with the specified
|
||||
/// position, width, and height.
|
||||
/// </summary>
|
||||
/// <param name="x">The x coordinate of the top-left corner of the created <see cref="RectangleF"/>.</param>
|
||||
/// <param name="y">The y coordinate of the top-left corner of the created <see cref="RectangleF"/>.</param>
|
||||
/// <param name="width">The width of the created <see cref="RectangleF"/>.</param>
|
||||
/// <param name="height">The height of the created <see cref="RectangleF"/>.</param>
|
||||
public RectangleF(float x, float y, float width, float height)
|
||||
{
|
||||
this.X = x;
|
||||
this.Y = y;
|
||||
this.Width = width;
|
||||
this.Height = height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="RectangleF"/> struct, with the specified
|
||||
/// location and size.
|
||||
/// </summary>
|
||||
/// <param name="location">The x and y coordinates of the top-left corner of the created <see cref="RectangleF"/>.</param>
|
||||
/// <param name="size">The width and height of the created <see cref="RectangleF"/>.</param>
|
||||
public RectangleF(Vector2 location, Vector2 size)
|
||||
{
|
||||
this.X = location.X;
|
||||
this.Y = location.Y;
|
||||
this.Width = size.X;
|
||||
this.Height = size.Y;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Compares whether two <see cref="RectangleF"/> instances are equal.
|
||||
/// </summary>
|
||||
/// <param name="a"><see cref="RectangleF"/> instance on the left of the equal sign.</param>
|
||||
/// <param name="b"><see cref="RectangleF"/> instance on the right of the equal sign.</param>
|
||||
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
|
||||
public static bool operator ==(RectangleF a, RectangleF b)
|
||||
{
|
||||
return ((a.X == b.X) && (a.Y == b.Y) && (a.Width == b.Width) && (a.Height == b.Height));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares whether two <see cref="RectangleF"/> instances are not equal.
|
||||
/// </summary>
|
||||
/// <param name="a"><see cref="RectangleF"/> instance on the left of the not equal sign.</param>
|
||||
/// <param name="b"><see cref="RectangleF"/> instance on the right of the not equal sign.</param>
|
||||
/// <returns><c>true</c> if the instances are not equal; <c>false</c> otherwise.</returns>
|
||||
public static bool operator !=(RectangleF a, RectangleF b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public static implicit operator RectangleF(Rectangle r) => new RectangleF(r.X, r.Y, r.Width, r.Height);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the provided coordinates lie within the bounds of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="x">The x coordinate of the point to check for containment.</param>
|
||||
/// <param name="y">The y coordinate of the point to check for containment.</param>
|
||||
/// <returns><c>true</c> if the provided coordinates lie inside this <see cref="RectangleF"/>; <c>false</c> otherwise.</returns>
|
||||
public bool Contains(int x, int y)
|
||||
{
|
||||
return ((((this.X <= x) && (x < (this.X + this.Width))) && (this.Y <= y)) && (y < (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the provided coordinates lie within the bounds of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="x">The x coordinate of the point to check for containment.</param>
|
||||
/// <param name="y">The y coordinate of the point to check for containment.</param>
|
||||
/// <returns><c>true</c> if the provided coordinates lie inside this <see cref="RectangleF"/>; <c>false</c> otherwise.</returns>
|
||||
public bool Contains(float x, float y)
|
||||
{
|
||||
return ((((this.X <= x) && (x < (this.X + this.Width))) && (this.Y <= y)) && (y < (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the provided <see cref="Point"/> lies within the bounds of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The coordinates to check for inclusion in this <see cref="RectangleF"/>.</param>
|
||||
/// <returns><c>true</c> if the provided <see cref="Point"/> lies inside this <see cref="RectangleF"/>; <c>false</c> otherwise.</returns>
|
||||
public bool Contains(Point value)
|
||||
{
|
||||
return ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the provided <see cref="Point"/> lies within the bounds of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The coordinates to check for inclusion in this <see cref="RectangleF"/>.</param>
|
||||
/// <param name="result"><c>true</c> if the provided <see cref="Point"/> lies inside this <see cref="RectangleF"/>; <c>false</c> otherwise. As an output parameter.</param>
|
||||
public void Contains(ref Point value, out bool result)
|
||||
{
|
||||
result = ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the provided <see cref="Vector2"/> lies within the bounds of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The coordinates to check for inclusion in this <see cref="RectangleF"/>.</param>
|
||||
/// <returns><c>true</c> if the provided <see cref="Vector2"/> lies inside this <see cref="RectangleF"/>; <c>false</c> otherwise.</returns>
|
||||
public bool Contains(Vector2 value)
|
||||
{
|
||||
return ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the provided <see cref="Vector2"/> lies within the bounds of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The coordinates to check for inclusion in this <see cref="RectangleF"/>.</param>
|
||||
/// <param name="result"><c>true</c> if the provided <see cref="Vector2"/> lies inside this <see cref="RectangleF"/>; <c>false</c> otherwise. As an output parameter.</param>
|
||||
public void Contains(ref Vector2 value, out bool result)
|
||||
{
|
||||
result = ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the provided <see cref="RectangleF"/> lies within the bounds of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="RectangleF"/> to check for inclusion in this <see cref="RectangleF"/>.</param>
|
||||
/// <returns><c>true</c> if the provided <see cref="RectangleF"/>'s bounds lie entirely inside this <see cref="RectangleF"/>; <c>false</c> otherwise.</returns>
|
||||
public bool Contains(RectangleF value)
|
||||
{
|
||||
return ((((this.X <= value.X) && ((value.X + value.Width) <= (this.X + this.Width))) && (this.Y <= value.Y)) && ((value.Y + value.Height) <= (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the provided <see cref="RectangleF"/> lies within the bounds of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="RectangleF"/> to check for inclusion in this <see cref="RectangleF"/>.</param>
|
||||
/// <param name="result"><c>true</c> if the provided <see cref="RectangleF"/>'s bounds lie entirely inside this <see cref="RectangleF"/>; <c>false</c> otherwise. As an output parameter.</param>
|
||||
public void Contains(ref RectangleF value, out bool result)
|
||||
{
|
||||
result = ((((this.X <= value.X) && ((value.X + value.Width) <= (this.X + this.Width))) && (this.Y <= value.Y)) && ((value.Y + value.Height) <= (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares whether current instance is equal to specified <see cref="Object"/>.
|
||||
/// </summary>
|
||||
/// <param name="obj">The <see cref="Object"/> to compare.</param>
|
||||
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is RectangleF) && this == ((RectangleF)obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares whether current instance is equal to specified <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="other">The <see cref="RectangleF"/> to compare.</param>
|
||||
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
|
||||
public bool Equals(RectangleF other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <returns>Hash code of this <see cref="RectangleF"/>.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hash = 17;
|
||||
hash = hash * 23 + X.GetHashCode();
|
||||
hash = hash * 23 + Y.GetHashCode();
|
||||
hash = hash * 23 + Width.GetHashCode();
|
||||
hash = hash * 23 + Height.GetHashCode();
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adjusts the edges of this <see cref="RectangleF"/> by specified horizontal and vertical amounts.
|
||||
/// </summary>
|
||||
/// <param name="horizontalAmount">Value to adjust the left and right edges.</param>
|
||||
/// <param name="verticalAmount">Value to adjust the top and bottom edges.</param>
|
||||
public void Inflate(int horizontalAmount, int verticalAmount)
|
||||
{
|
||||
X -= horizontalAmount;
|
||||
Y -= verticalAmount;
|
||||
Width += horizontalAmount * 2;
|
||||
Height += verticalAmount * 2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adjusts the edges of this <see cref="RectangleF"/> by specified horizontal and vertical amounts.
|
||||
/// </summary>
|
||||
/// <param name="horizontalAmount">Value to adjust the left and right edges.</param>
|
||||
/// <param name="verticalAmount">Value to adjust the top and bottom edges.</param>
|
||||
public void Inflate(float horizontalAmount, float verticalAmount)
|
||||
{
|
||||
X -= (float)horizontalAmount;
|
||||
Y -= (float)verticalAmount;
|
||||
Width += (float)horizontalAmount * 2;
|
||||
Height += (float)verticalAmount * 2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adjusts the edges of this <see cref="RectangleF"/> by specified horizontal and vertical amounts.
|
||||
/// </summary>
|
||||
/// <param name="amount">Value to adjust the edges.</param>
|
||||
public void Inflate(Vector2 amount)
|
||||
{
|
||||
Inflate(amount.X, amount.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the other <see cref="RectangleF"/> intersects with this rectangle.
|
||||
/// </summary>
|
||||
/// <param name="value">The other rectangle for testing.</param>
|
||||
/// <returns><c>true</c> if other <see cref="RectangleF"/> intersects with this rectangle; <c>false</c> otherwise.</returns>
|
||||
public bool Intersects(RectangleF value)
|
||||
{
|
||||
return value.Left < Right &&
|
||||
Left < value.Right &&
|
||||
value.Top < Bottom &&
|
||||
Top < value.Bottom;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the other <see cref="RectangleF"/> intersects with this rectangle.
|
||||
/// </summary>
|
||||
/// <param name="value">The other rectangle for testing.</param>
|
||||
/// <param name="result"><c>true</c> if other <see cref="RectangleF"/> intersects with this rectangle; <c>false</c> otherwise. As an output parameter.</param>
|
||||
public void Intersects(ref RectangleF value, out bool result)
|
||||
{
|
||||
result = value.Left < Right &&
|
||||
Left < value.Right &&
|
||||
value.Top < Bottom &&
|
||||
Top < value.Bottom;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="RectangleF"/> that contains overlapping region of two other rectangles.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first <see cref="RectangleF"/>.</param>
|
||||
/// <param name="value2">The second <see cref="RectangleF"/>.</param>
|
||||
/// <returns>Overlapping region of the two rectangles.</returns>
|
||||
public static RectangleF Intersect(RectangleF value1, RectangleF value2)
|
||||
{
|
||||
RectangleF rectangle;
|
||||
Intersect(ref value1, ref value2, out rectangle);
|
||||
return rectangle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="RectangleF"/> that contains overlapping region of two other rectangles.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first <see cref="RectangleF"/>.</param>
|
||||
/// <param name="value2">The second <see cref="RectangleF"/>.</param>
|
||||
/// <param name="result">Overlapping region of the two rectangles as an output parameter.</param>
|
||||
public static void Intersect(ref RectangleF value1, ref RectangleF value2, out RectangleF result)
|
||||
{
|
||||
if (value1.Intersects(value2))
|
||||
{
|
||||
float right_side = MathF.Min(value1.X + value1.Width, value2.X + value2.Width);
|
||||
float left_side = MathF.Max(value1.X, value2.X);
|
||||
float top_side = MathF.Max(value1.Y, value2.Y);
|
||||
float bottom_side = MathF.Min(value1.Y + value1.Height, value2.Y + value2.Height);
|
||||
result = new RectangleF(left_side, top_side, right_side - left_side, bottom_side - top_side);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new RectangleF(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the <see cref="Location"/> of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="offsetX">The x coordinate to add to this <see cref="RectangleF"/>.</param>
|
||||
/// <param name="offsetY">The y coordinate to add to this <see cref="RectangleF"/>.</param>
|
||||
public void Offset(int offsetX, int offsetY)
|
||||
{
|
||||
X += offsetX;
|
||||
Y += offsetY;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the <see cref="Location"/> of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="offsetX">The x coordinate to add to this <see cref="RectangleF"/>.</param>
|
||||
/// <param name="offsetY">The y coordinate to add to this <see cref="RectangleF"/>.</param>
|
||||
public void Offset(float offsetX, float offsetY)
|
||||
{
|
||||
X += (float)offsetX;
|
||||
Y += (float)offsetY;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the <see cref="Location"/> of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="amount">The x and y components to add to this <see cref="RectangleF"/>.</param>
|
||||
public void Offset(Point amount)
|
||||
{
|
||||
X += amount.X;
|
||||
Y += amount.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the <see cref="Location"/> of this <see cref="RectangleF"/>.
|
||||
/// </summary>
|
||||
/// <param name="amount">The x and y components to add to this <see cref="RectangleF"/>.</param>
|
||||
public void Offset(Vector2 amount)
|
||||
{
|
||||
X += (float)amount.X;
|
||||
Y += (float)amount.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="String"/> representation of this <see cref="RectangleF"/> in the format:
|
||||
/// {X:[<see cref="X"/>] Y:[<see cref="Y"/>] Width:[<see cref="Width"/>] Height:[<see cref="Height"/>]}
|
||||
/// </summary>
|
||||
/// <returns><see cref="String"/> representation of this <see cref="RectangleF"/>.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return "{X:" + X + " Y:" + Y + " Width:" + Width + " Height:" + Height + "}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="RectangleF"/> that completely contains two other rectangles.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first <see cref="RectangleF"/>.</param>
|
||||
/// <param name="value2">The second <see cref="RectangleF"/>.</param>
|
||||
/// <returns>The union of the two rectangles.</returns>
|
||||
public static RectangleF Union(RectangleF value1, RectangleF value2)
|
||||
{
|
||||
float x = MathF.Min(value1.X, value2.X);
|
||||
float y = MathF.Min(value1.Y, value2.Y);
|
||||
return new RectangleF(x, y,
|
||||
Math.Max(value1.Right, value2.Right) - x,
|
||||
Math.Max(value1.Bottom, value2.Bottom) - y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="RectangleF"/> that completely contains two other rectangles.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first <see cref="RectangleF"/>.</param>
|
||||
/// <param name="value2">The second <see cref="RectangleF"/>.</param>
|
||||
/// <param name="result">The union of the two rectangles as an output parameter.</param>
|
||||
public static void Union(ref RectangleF value1, ref RectangleF value2, out RectangleF result)
|
||||
{
|
||||
result.X = Math.Min(value1.X, value2.X);
|
||||
result.Y = Math.Min(value1.Y, value2.Y);
|
||||
result.Width = Math.Max(value1.Right, value2.Right) - result.X;
|
||||
result.Height = Math.Max(value1.Bottom, value2.Bottom) - result.Y;
|
||||
}
|
||||
|
||||
public void AddPoint(Point point)
|
||||
{
|
||||
if (point.X < X)
|
||||
{
|
||||
Width += X - point.X;
|
||||
X = point.X;
|
||||
}
|
||||
else if (point.X > Right)
|
||||
{
|
||||
Width += point.X - Right;
|
||||
}
|
||||
|
||||
if (point.Y < Y)
|
||||
{
|
||||
Height += Y - point.Y;
|
||||
Y = point.Y;
|
||||
}
|
||||
else if (point.Y > Bottom)
|
||||
{
|
||||
Height += point.Y - Bottom;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user