MoonTools.Bonk/Bonk/MinkowskiDifference.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2019-10-25 19:42:39 +00:00
using System;
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;
}
public bool Equals(MinkowskiDifference other)
{
return
shapeA == other.shapeA &&
transformA.Equals(other.transformA) &&
shapeB == other.shapeB &&
transformB.Equals(other.transformB);
}
public Vector2 Support(Vector2 direction)
{
return shapeA.Support(direction, transformA) - shapeB.Support(-direction, transformB);
}
}
}