mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-25 08:22:15 +00:00
swaps EllipseF to use a struct, as well as implementing IEquatable, and IShapeF - this resolves #703
This commit is contained in:
@@ -1,20 +1,29 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace MonoGame.Extended
|
||||
{
|
||||
public class EllipseF
|
||||
[DataContract]
|
||||
public struct EllipseF : IEquatable<EllipseF>, IEquatableByRef<EllipseF>, IShapeF
|
||||
{
|
||||
[DataMember] public Vector2 Center { get; set; }
|
||||
[DataMember] public float RadiusX { get; set; }
|
||||
[DataMember] public float RadiusY { get; set; }
|
||||
|
||||
public Point2 Position
|
||||
{
|
||||
get => Center;
|
||||
set => Center = value;
|
||||
}
|
||||
|
||||
public EllipseF(Vector2 center, float radiusX, float radiusY)
|
||||
{
|
||||
Center = center;
|
||||
RadiusX = radiusX;
|
||||
RadiusY = radiusY;
|
||||
}
|
||||
|
||||
public Vector2 Center { get; set; }
|
||||
public float RadiusX { get; set; }
|
||||
public float RadiusY { get; set; }
|
||||
|
||||
public float Left => Center.X - RadiusX;
|
||||
public float Top => Center.Y - RadiusY;
|
||||
public float Right => Center.X + RadiusX;
|
||||
@@ -44,5 +53,28 @@ namespace MonoGame.Extended
|
||||
{
|
||||
return Contains(point.X, point.Y);
|
||||
}
|
||||
|
||||
public bool Equals(EllipseF ellispse)
|
||||
{
|
||||
return Equals(ref ellispse);
|
||||
}
|
||||
|
||||
public bool Equals(ref EllipseF ellispse)
|
||||
{
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
return ellispse.Center == Center
|
||||
&& ellispse.RadiusX == RadiusX
|
||||
&& ellispse.RadiusY == RadiusY;
|
||||
}
|
||||
|
||||
public static bool operator ==(EllipseF first, EllipseF second)
|
||||
{
|
||||
return first.Equals(ref second);
|
||||
}
|
||||
|
||||
public static bool operator !=(EllipseF first, EllipseF second)
|
||||
{
|
||||
return !(first == second);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user