bool SAT(Polygon other, ref Vector2 resolution) { float overlap = float.MaxValue; Vector2 smallest = new Vector2(); Vector2[] axesA = GetAxes(); Vector2[] axesB = other.GetAxes(); for (int i = 0; i < axesA.Length; i++) { Vector2 axis = axesA[i]; _projection pa = Project(axis); _projection pb = other.Project(axis); if (!pa.Overlap(pb)) { return(false); } float o = pa.GetOverlap(pb); if (o < overlap) { overlap = o; smallest = axis; } } for (int i = 0; i < axesB.Length; i++) { Vector2 axis = axesB[i]; _projection pa = Project(axis); _projection pb = other.Project(axis); if (!pa.Overlap(pb)) { return(false); } float o = pa.GetOverlap(pb); if (o < overlap) { overlap = o; smallest = axis; } } if ((other.location - location).DotProduct(smallest) < 0) { smallest *= -1; } resolution = smallest * -overlap; return(true); }
set => SetProperty(ref _projection, value);
public float GetOverlap(_projection other) => Math.Min(max, other.max) - Math.Max(min, other.min);
public bool Overlap(_projection other) => max > other.min && min < other.max;