private HasSeparatingAxisTo ( |
||
other | The other Polygon. | |
minOverlap | float | The MinimumOverlap. |
axis | Vector2 | The Axis. |
return | bool |
/// <summary> /// Checks if this Polygon intersects with another Polygon. /// </summary> /// <param name="other">The other Polygon.</param> /// <param name="minimumTranslationVector"> /// Returns a vector with which the Polygon has to be translated at minimum to not /// collide with the second Polygon. /// </param> /// <returns>True of intersecting.</returns> public bool Intersects(Polygon other, out Vector2 minimumTranslationVector) { if (!IsValid || !other.IsValid) { throw new InvalidOperationException(); } minimumTranslationVector = default(Vector2); float minOverlap = float.MaxValue; if (HasSeparatingAxisTo(other, ref minOverlap, ref minimumTranslationVector)) { return(false); } if (other.HasSeparatingAxisTo(this, ref minOverlap, ref minimumTranslationVector)) { return(false); } Vector2 d = Center - other.Center; if (Vector2.Dot(d, minimumTranslationVector) > 0) { minimumTranslationVector = -minimumTranslationVector; } minimumTranslationVector *= minOverlap; return(true); }
/// <summary> /// Checks if this Polygon intersects with another Polygon. /// </summary> /// <param name="other">The other Polygon.</param> /// <param name="minimumTranslationVector"> /// Returns a vector with which the Polygon has to be translated at minimum to not /// collide with the second Polygon. /// </param> /// <returns>True of intersecting.</returns> public bool Intersects(Polygon other, out Vector2 minimumTranslationVector) { if (!IsValid || !other.IsValid) throw new InvalidOperationException(); minimumTranslationVector = default(Vector2); float minOverlap = float.MaxValue; if (HasSeparatingAxisTo(other, ref minOverlap, ref minimumTranslationVector)) return false; if (other.HasSeparatingAxisTo(this, ref minOverlap, ref minimumTranslationVector)) return false; Vector2 d = Center - other.Center; if (Vector2.Dot(d, minimumTranslationVector) > 0) minimumTranslationVector = -minimumTranslationVector; minimumTranslationVector *= minOverlap; return true; }