using System;
using System.Numerics;
namespace MoonTools.Core.Bonk
{
///
/// A Minkowski difference between two shapes.
///
public struct MinkowskiDifference : IEquatable> where T : struct, IShape2D where U : struct, IShape2D
{
private TransformedShape2D ShapeA { get; }
private TransformedShape2D ShapeB { get; }
public MinkowskiDifference(TransformedShape2D shapeA, TransformedShape2D shapeB)
{
ShapeA = shapeA;
ShapeB = shapeB;
}
public Vector2 Support(Vector2 direction)
{
return ShapeA.Support(direction) - ShapeB.Support(-direction);
}
public override bool Equals(object other)
{
return other is MinkowskiDifference minkowskiDifference && Equals(minkowskiDifference);
}
public bool Equals(MinkowskiDifference other)
{
return
ShapeA == other.ShapeA &&
ShapeB == other.ShapeB;
}
public override int GetHashCode()
{
return HashCode.Combine(ShapeA, ShapeB);
}
public static bool operator ==(MinkowskiDifference a, MinkowskiDifference b)
{
return a.Equals(b);
}
public static bool operator !=(MinkowskiDifference a, MinkowskiDifference b)
{
return !(a == b);
}
}
}