/// <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 (this.max < that.min) { return(false); } if (that.max < this.min) { return(false); } return(true); }
/// <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); }
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(); }
public Interval2DWindow(double xlo, double xhi, double ylo, double yhi, int T) { SetPercentScale(true); Interval1D xinterval = new Interval1D(xlo, xhi); Interval1D yinterval = new Interval1D(ylo, yhi); Interval2D box = new Interval2D(xinterval, yinterval) { Display = this }; box.Draw(); Counter counter = new Counter("Hits"); for (int t = 0; t < T; t++) { double x = StdRandom.Uniform(0.0, 1.0); double y = StdRandom.Uniform(0.0, 1.0); Point2D p = new Point2D(x, y) { Display = this }; if (box.Contains(p)) { counter.Increment(); } else { p.Draw(); } } Console.WriteLine(counter); Console.WriteLine("Box area = {0:F2}", box.Area()); }
/// <summary> /// Initializes a two-dimensional interval.</summary> /// <param name="x">the one-dimensional interval of x-coordinates</param> /// <param name="y">the one-dimensional interval of y-coordinates</param> /// public Interval2D(Interval1D x, Interval1D y) { this.x = x; this.y = y; }