2020-01-02 09:40:03 +00:00
|
|
|
|
using System;
|
2019-10-31 23:19:30 +00:00
|
|
|
|
using System.Numerics;
|
2019-10-25 19:42:39 +00:00
|
|
|
|
|
|
|
|
|
namespace MoonTools.Core.Bonk
|
|
|
|
|
{
|
2019-10-25 21:01:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A Minkowski difference between two shapes.
|
|
|
|
|
/// </summary>
|
2020-01-05 07:24:36 +00:00
|
|
|
|
public struct MinkowskiDifference<T, U> : IEquatable<MinkowskiDifference<T, U>> where T : struct, IShape2D where U : struct, IShape2D
|
2019-10-25 19:42:39 +00:00
|
|
|
|
{
|
2020-01-05 07:24:36 +00:00
|
|
|
|
private TransformedShape2D<T> ShapeA { get; }
|
|
|
|
|
private TransformedShape2D<U> ShapeB { get; }
|
2019-10-25 19:42:39 +00:00
|
|
|
|
|
2020-01-05 07:24:36 +00:00
|
|
|
|
public MinkowskiDifference(TransformedShape2D<T> shapeA, TransformedShape2D<U> shapeB)
|
2019-10-25 19:42:39 +00:00
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
ShapeA = shapeA;
|
|
|
|
|
ShapeB = shapeB;
|
2019-10-25 19:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 23:20:43 +00:00
|
|
|
|
public Vector2 Support(Vector2 direction)
|
|
|
|
|
{
|
2020-01-05 07:24:36 +00:00
|
|
|
|
return ShapeA.Support(direction) - ShapeB.Support(-direction);
|
2019-10-25 23:20:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object other)
|
|
|
|
|
{
|
2020-01-05 07:24:36 +00:00
|
|
|
|
return other is MinkowskiDifference<T, U> minkowskiDifference && Equals(minkowskiDifference);
|
2019-10-25 23:20:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-05 07:24:36 +00:00
|
|
|
|
public bool Equals(MinkowskiDifference<T, U> other)
|
2019-10-25 19:42:39 +00:00
|
|
|
|
{
|
|
|
|
|
return
|
2019-12-09 03:46:08 +00:00
|
|
|
|
ShapeA == other.ShapeA &&
|
2020-01-05 07:24:36 +00:00
|
|
|
|
ShapeB == other.ShapeB;
|
2019-10-25 19:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 23:20:43 +00:00
|
|
|
|
public override int GetHashCode()
|
2019-10-25 19:42:39 +00:00
|
|
|
|
{
|
2020-01-05 07:24:36 +00:00
|
|
|
|
return HashCode.Combine(ShapeA, ShapeB);
|
2019-10-25 23:20:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-05 07:24:36 +00:00
|
|
|
|
public static bool operator ==(MinkowskiDifference<T, U> a, MinkowskiDifference<T, U> b)
|
2019-10-25 23:20:43 +00:00
|
|
|
|
{
|
|
|
|
|
return a.Equals(b);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-05 07:24:36 +00:00
|
|
|
|
public static bool operator !=(MinkowskiDifference<T, U> a, MinkowskiDifference<T, U> b)
|
2019-10-25 23:20:43 +00:00
|
|
|
|
{
|
|
|
|
|
return !(a == b);
|
2019-10-25 19:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-02 09:40:03 +00:00
|
|
|
|
}
|