2020-01-02 09:40:03 +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-10-25 19:42:39 +00:00
|
|
|
|
|
2020-02-21 02:07:59 +00:00
|
|
|
|
namespace MoonTools.Bonk
|
2019-10-25 19:42:39 +00:00
|
|
|
|
{
|
2019-10-25 21:01:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A Minkowski difference between two shapes.
|
|
|
|
|
/// </summary>
|
2019-10-25 19:42:39 +00:00
|
|
|
|
public struct MinkowskiDifference : IEquatable<MinkowskiDifference>
|
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
private IShape2D ShapeA { get; }
|
|
|
|
|
private Transform2D TransformA { get; }
|
|
|
|
|
private IShape2D ShapeB { get; }
|
|
|
|
|
private Transform2D TransformB { get; }
|
2019-10-25 19:42:39 +00:00
|
|
|
|
|
|
|
|
|
public MinkowskiDifference(IShape2D shapeA, Transform2D transformA, IShape2D shapeB, Transform2D transformB)
|
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
ShapeA = shapeA;
|
|
|
|
|
TransformA = transformA;
|
|
|
|
|
ShapeB = shapeB;
|
|
|
|
|
TransformB = transformB;
|
2019-10-25 19:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 23:20:43 +00:00
|
|
|
|
public Vector2 Support(Vector2 direction)
|
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
return ShapeA.Support(direction, TransformA) - ShapeB.Support(-direction, TransformB);
|
2019-10-25 23:20:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object other)
|
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
return other is MinkowskiDifference minkowskiDifference && Equals(minkowskiDifference);
|
2019-10-25 23:20:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 19:42:39 +00:00
|
|
|
|
public bool Equals(MinkowskiDifference other)
|
|
|
|
|
{
|
|
|
|
|
return
|
2019-12-09 03:46:08 +00:00
|
|
|
|
ShapeA == other.ShapeA &&
|
|
|
|
|
TransformA == other.TransformA &&
|
|
|
|
|
ShapeB == other.ShapeB &&
|
|
|
|
|
TransformB == other.TransformB;
|
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
|
|
|
|
{
|
2019-12-09 03:46:08 +00:00
|
|
|
|
return HashCode.Combine(ShapeA, TransformA, ShapeB, TransformB);
|
2019-10-25 23:20:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator ==(MinkowskiDifference a, MinkowskiDifference b)
|
|
|
|
|
{
|
|
|
|
|
return a.Equals(b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator !=(MinkowskiDifference a, MinkowskiDifference b)
|
|
|
|
|
{
|
|
|
|
|
return !(a == b);
|
2019-10-25 19:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-21 02:07:59 +00:00
|
|
|
|
}
|