Пример #1
0
 /// <summary>
 /// Does this two-dimensional interval intersect that two-dimensional interval?</summary>
 /// <param name="that">the other two-dimensional interval</param>
 /// <returns>true if this two-dimensional interval intersects
 ///   that two-dimensional interval; false otherwise</returns>
 ///
 public bool Intersects(Interval2D that)
 {
     if (!this.x.Intersects(that.x))
     {
         return(false);
     }
     if (!this.y.Intersects(that.y))
     {
         return(false);
     }
     return(true);
 }
Пример #2
0
        /// <summary>
        /// Does this interval equal the other interval?</summary>
        /// <param name="other">the other interval</param>
        /// <returns>true if this interval equals the other interval; false 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);
            }
            Interval2D that = (Interval2D)other;

            return(this.x.Equals(that.x) && this.y.Equals(that.y));
        }
Пример #3
0
            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());
            }