/// <summary> /// Tests if Min and Max intersects. /// </summary> /// <param name="inter"></param> /// <returns></returns> public bool Intersects(Interval inter) { if (_max < inter.Min) return false; if (_min > inter.Max) return false; return true; }
public static Interval Concat(Interval a, Interval b) { var min = Mathf.Min(a.Min, b.Min); var max = Mathf.Max(a.Max, b.Max); return new Interval(min, max); }
/// <summary> /// Total distance the two intervals pass. /// </summary> /// <param name="inter"></param> /// <returns></returns> public float Distance(Interval inter) { if (_max > inter.Min) return 0; if (_min < inter.Max) return 0; return Mathf.Abs(_max - inter.Min); }
/// <summary> /// Finds the mid value of the Min and Max of both intervals. /// </summary> /// <param name="inter"></param> /// <returns></returns> public float MidValue(Interval inter) { float[] arr = new float[] { _min, _max, inter.Min, inter.Max }; System.Array.Sort(arr); return (arr[2] + arr[1]) / 2.0f; }
/// <summary> /// Get the interval intersection of this and another interval. /// </summary> /// <param name="inter"></param> /// <returns></returns> public Interval Intersection(Interval inter) { if (_max < inter.Min) return new Interval(0f, 0f); if (_min > inter.Max) return new Interval(0f, 0f); return new Interval(Mathf.Max(_min, inter.Min), Mathf.Min(_max, inter.Max)); }
/// <summary> /// Appends the interval passed in. /// </summary> /// <param name="inter"></param> public void Concat(Interval inter) { var a = Mathf.Min(this.Min, inter.Min); var b = Mathf.Max(this.Max, inter.Max); this.SetExtents(a, b); }