2019-09-06 08:11:58 +00:00
|
|
|
|
using System;
|
2019-10-31 23:19:30 +00:00
|
|
|
|
using System.Numerics;
|
2020-02-21 02:07:59 +00:00
|
|
|
|
using MoonTools.Structs;
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
2020-02-21 02:07:59 +00:00
|
|
|
|
namespace MoonTools.Bonk
|
2019-09-06 08:11:58 +00:00
|
|
|
|
{
|
2019-10-25 21:01:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A Circle is a shape defined by a radius.
|
|
|
|
|
/// </summary>
|
2019-12-09 03:46:08 +00:00
|
|
|
|
public struct Circle : IShape2D, IEquatable<Circle>
|
2019-09-06 08:11:58 +00:00
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
public int Radius { get; }
|
2019-12-30 06:19:10 +00:00
|
|
|
|
public AABB AABB { get; }
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
|
|
|
|
public Circle(int radius)
|
|
|
|
|
{
|
|
|
|
|
Radius = radius;
|
2019-12-30 06:19:10 +00:00
|
|
|
|
AABB = new AABB(-Radius, -Radius, Radius, Radius);
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector2 Support(Vector2 direction, Transform2D transform)
|
|
|
|
|
{
|
|
|
|
|
return Vector2.Transform(Vector2.Normalize(direction) * Radius, transform.TransformMatrix);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 06:19:10 +00:00
|
|
|
|
public AABB TransformedAABB(Transform2D transform2D)
|
2019-09-06 08:11:58 +00:00
|
|
|
|
{
|
2019-12-30 06:19:10 +00:00
|
|
|
|
return AABB.Transformed(AABB, transform2D);
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 23:20:43 +00:00
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
return obj is IShape2D other && Equals(other);
|
2019-10-25 23:20:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 08:11:58 +00:00
|
|
|
|
public bool Equals(IShape2D other)
|
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
return other is Circle circle && Equals(circle);
|
|
|
|
|
}
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
2019-12-09 03:46:08 +00:00
|
|
|
|
public bool Equals(Circle other)
|
|
|
|
|
{
|
|
|
|
|
return Radius == other.Radius;
|
2019-09-06 08:11:58 +00:00
|
|
|
|
}
|
2019-10-25 23:20:43 +00:00
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
return HashCode.Combine(Radius);
|
2019-10-25 23:20:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|