/// <summary> /// Determines the intersection of an <see cref="IntervalCollection<T>"/>. /// </summary> /// <typeparam name="T">The value type of the intervals.</typeparam> /// <param name="collection">A collection of <see cref="Interval<T>"/>.</param> /// <returns>An <see cref="Interval<T>"/> that contains elements belonging to all intervals in the <paramref name="collection"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="collection"/> is <c>null</c>.</exception> internal static Interval <T> IntersectionOf <T>(IntervalCollection <T> collection) { if (collection == null) { throw new ArgumentNullException("collection"); } if (collection.Count == 0) { return(Interval.Empty <T>()); } var a = collection[0]; for (int i = 1; i < collection.Count; i++) { var b = collection[i]; a = Interval.IntersectionOf(a, b); } return(a); }
/// <summary> /// Determines the intersection of this instance with the <paramref name="other"/> one. /// </summary> /// <example> /// <img src="../Images/Interval/Venn_Intersection.png" alt="Intersection"/> /// </example> /// <param name="other">Another <see cref="Interval<T>"/>.</param> /// <returns>An <see cref="Interval<T>"/> that contains all elements of this instance /// that also belong to the <paramref name="other"/> one (or equivalently, all elements of the <paramref name="other"/> one /// that also belong to this instance), but no other elements.</returns> /// <seealso href="http://en.wikipedia.org/wiki/Intersection_(set_theory)">Intersection (set theory)</seealso> public Interval <T> IntersectionWith(Interval <T> other) { return(Interval.IntersectionOf(this, other)); }