// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osuTK; namespace osu.Framework.Graphics.Primitives { /// /// A structure that tells how "far" along an axis /// the projection of vertices onto the axis would be. /// internal readonly struct ProjectionRange { /// /// The minimum projected value. /// public float Min { get; } /// /// The maximum projected value. /// public float Max { get; } public ProjectionRange(Vector2 axis, ReadOnlySpan vertices) { Min = 0; Max = 0; if (vertices.Length == 0) return; Min = Vector2.Dot(axis, vertices[0]); Max = Min; for (int i = 1; i < vertices.Length; i++) { float val = Vector2.Dot(axis, vertices[i]); if (val < Min) Min = val; if (val > Max) Max = val; } } /// /// Checks whether this range overlaps another range. /// /// The other range to test against. /// Whether the two ranges overlap. public bool Overlaps(ProjectionRange other) => Min <= other.Max && Max >= other.Min; } }