2019-09-06 08:11:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using MoonTools.Core.Structs;
|
|
|
|
|
|
|
|
|
|
namespace MoonTools.Core.Bonk
|
|
|
|
|
{
|
2019-10-25 21:01:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A Circle is a shape defined by a radius.
|
|
|
|
|
/// </summary>
|
2019-09-06 08:11:58 +00:00
|
|
|
|
public struct Circle : IShape2D, IEquatable<IShape2D>
|
|
|
|
|
{
|
|
|
|
|
public int Radius { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Circle(int radius)
|
|
|
|
|
{
|
|
|
|
|
Radius = radius;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector2 Support(Vector2 direction, Transform2D transform)
|
|
|
|
|
{
|
|
|
|
|
return Vector2.Transform(Vector2.Normalize(direction) * Radius, transform.TransformMatrix);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 00:00:43 +00:00
|
|
|
|
public AABB AABB(Transform2D transform2D)
|
2019-09-06 08:11:58 +00:00
|
|
|
|
{
|
|
|
|
|
return new AABB(
|
2019-09-19 00:00:43 +00:00
|
|
|
|
transform2D.Position.X - Radius * transform2D.Scale.X,
|
|
|
|
|
transform2D.Position.Y - Radius * transform2D.Scale.Y,
|
|
|
|
|
transform2D.Position.X + Radius * transform2D.Scale.X,
|
|
|
|
|
transform2D.Position.Y + Radius * transform2D.Scale.Y
|
2019-09-06 08:11:58 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 23:20:43 +00:00
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj is Circle other)
|
|
|
|
|
{
|
|
|
|
|
return Equals(other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 08:11:58 +00:00
|
|
|
|
public bool Equals(IShape2D other)
|
|
|
|
|
{
|
|
|
|
|
if (other is Circle circle)
|
|
|
|
|
{
|
|
|
|
|
return Radius == circle.Radius;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-10-25 23:20:43 +00:00
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
return 598075851 + Radius.GetHashCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator ==(Circle a, Circle b)
|
|
|
|
|
{
|
|
|
|
|
return a.Equals(b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator !=(Circle a, Circle b)
|
|
|
|
|
{
|
|
|
|
|
return !(a == b);
|
|
|
|
|
}
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|