using System; using UnityEngine; namespace Framework.Support { /// Stores a range with a start value and an end value [Serializable] public struct Range { /// An empty range public static readonly Range Empty = new Range(0.0f, 0.0f); /// Position or time the interval begins at public float Start; /// Position or time the interval ends at public float End; /// Initializes a new interval from the specified end points /// Position or time at which the interval will begin /// Position or time at which the interval will end public Range(float start, float end) { this.Start = start; this.End = end; } /// Checks whether the interval contains the specified point /// Point the interval will be checked against /// True if the interval contains the specified point public bool Contains(float point) { return (point >= this.Start) && (point < this.End); } /// Checks whether the interval intersects another interval /// Other interval to check for an intersection against /// True if this interval intersects the other interval public bool Intersects(Range other) { return (this.End >= other.Start) && (other.End >= this.Start); } /// Whether the interval is flipped /// True if the interval is flipped, false otherwise public bool IsFlipped { get { return (this.End < this.Start); } } /// Locates the center of the range public float Center { get { return (this.Start + this.End) / 2.0f; } } /// Calculates the length of the range public float Length { get { return (this.End - this.Start); } } /// Returns a random point within the interval /// A random point within the interval public float Random() { return UnityEngine.Random.Range(this.Start, this.End); } /// Returns a hash code that will be match between identical instances /// A hash code for the instance public override int GetHashCode() { return this.Start.GetHashCode() ^ this.End.GetHashCode(); } /// Provides a human-readable string representation of the interval /// The string representation of the interval public override string ToString() { return "{Interval " + this.Start.ToString() + " - " + this.End.ToString() + "}"; } } } // namespace Framework.Support