Ejemplo n.º 1
0
 /// <summary>
 /// Returns true if this interval intersects the specified interval.</summary>
 /// <param name="that">the other interval</param>
 /// <returns><c>true</c> if this interval intersects the argument interval;
 ///        <c>false</c> otherwise</returns>
 ///
 public bool Intersects(Interval1D that)
 {
     if (that == null)
     {
         throw new ArgumentNullException(nameof(that));
     }
     if (this.max < that.min)
     {
         return(false);
     }
     if (that.max < this.min)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Compares this transaction to the specified object.</summary>
        /// <param name="other">the other interval</param>
        /// <returns><c>true</c> if this interval equals the other interval;
        ///        <c>false</c> otherwise</returns>
        ///
        public override bool Equals(object other)
        {
            if (other == this)
            {
                return(true);
            }
            if (other == null)
            {
                return(false);
            }
            if (other.GetType() != this.GetType())
            {
                return(false);
            }
            Interval1D that = (Interval1D)other;

            return(this.min == that.min && this.max == that.max);
        }
Ejemplo n.º 3
0
        public static void MainTest(string[] args)
        {
            Interval1D[] intervals = new Interval1D[4];
            intervals[0] = new Interval1D(15.0, 33.0);
            intervals[1] = new Interval1D(45.0, 60.0);
            intervals[2] = new Interval1D(20.0, 70.0);
            intervals[3] = new Interval1D(46.0, 55.0);

            Console.WriteLine("Unsorted");
            for (int i = 0; i < intervals.Length; i++)
            {
                Console.WriteLine(intervals[i]);
            }
            Console.WriteLine();

            Console.WriteLine("Sort by min endpoint");
            Array.Sort(intervals, Interval1D.MIN_ENDPOINT_ORDER);
            for (int i = 0; i < intervals.Length; i++)
            {
                Console.WriteLine(intervals[i]);
            }
            Console.WriteLine();

            Console.WriteLine("Sort by max endpoint");
            Array.Sort(intervals, Interval1D.MAX_ENDPOINT_ORDER);
            for (int i = 0; i < intervals.Length; i++)
            {
                Console.WriteLine(intervals[i]);
            }
            Console.WriteLine();

            Console.WriteLine("Sort by length");
            Array.Sort(intervals, Interval1D.LENGTH_ORDER);
            for (int i = 0; i < intervals.Length; i++)
            {
                Console.WriteLine(intervals[i]);
            }
            Console.WriteLine();
        }