2019-10-25 19:42:39 +00:00
|
|
|
using System;
|
2019-10-25 23:20:43 +00:00
|
|
|
using System.Collections.Generic;
|
2019-10-25 19:42:39 +00:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using MoonTools.Core.Structs;
|
|
|
|
|
|
|
|
namespace MoonTools.Core.Bonk
|
|
|
|
{
|
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>
|
|
|
|
{
|
|
|
|
private IShape2D shapeA;
|
|
|
|
private Transform2D transformA;
|
|
|
|
private IShape2D shapeB;
|
|
|
|
private Transform2D transformB;
|
|
|
|
|
|
|
|
public MinkowskiDifference(IShape2D shapeA, Transform2D transformA, IShape2D shapeB, Transform2D transformB)
|
|
|
|
{
|
|
|
|
this.shapeA = shapeA;
|
|
|
|
this.transformA = transformA;
|
|
|
|
this.shapeB = shapeB;
|
|
|
|
this.transformB = transformB;
|
|
|
|
}
|
|
|
|
|
2019-10-25 23:20:43 +00:00
|
|
|
public Vector2 Support(Vector2 direction)
|
|
|
|
{
|
|
|
|
return shapeA.Support(direction, transformA) - shapeB.Support(-direction, transformB);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool Equals(object other)
|
|
|
|
{
|
|
|
|
if (other is MinkowskiDifference otherMinkowskiDifference)
|
|
|
|
{
|
|
|
|
return Equals(otherMinkowskiDifference);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-25 19:42:39 +00:00
|
|
|
public bool Equals(MinkowskiDifference other)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
shapeA == other.shapeA &&
|
2019-10-25 23:20:43 +00:00
|
|
|
transformA == other.transformA &&
|
2019-10-25 19:42:39 +00:00
|
|
|
shapeB == other.shapeB &&
|
2019-10-25 23:20:43 +00:00
|
|
|
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-10-25 23:20:43 +00:00
|
|
|
var hashCode = 974363698;
|
|
|
|
hashCode = hashCode * -1521134295 + EqualityComparer<IShape2D>.Default.GetHashCode(shapeA);
|
|
|
|
hashCode = hashCode * -1521134295 + EqualityComparer<Transform2D>.Default.GetHashCode(transformA);
|
|
|
|
hashCode = hashCode * -1521134295 + EqualityComparer<IShape2D>.Default.GetHashCode(shapeB);
|
|
|
|
hashCode = hashCode * -1521134295 + EqualityComparer<Transform2D>.Default.GetHashCode(transformB);
|
|
|
|
return hashCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|