Exemplo n.º 1
0
 /// <summary>Returns a new BoundingBox bounding a single point.</summary>
 public static BoundingBoxD FromPoint(double x, double y)
 {
     BoundingBoxD box = new BoundingBoxD();
     box.Xmin = box.Xmax = x;
     box.Ymin = box.Ymax = y;
     return box;
 }
Exemplo n.º 2
0
 /// <summary>Returns a new BoundingBox bounding a single point.</summary>
 public static BoundingBoxD FromPoint(ref PointD pt)
 {
     BoundingBoxD box = new BoundingBoxD();
     box.Xmin = box.Xmax = pt.X;
     box.Ymin = box.Ymax = pt.Y;
     return box;
 }
Exemplo n.º 3
0
 /// <summary>Returns a new BoundingBox bounding the two points specified.</summary>
 public static BoundingBoxD FromPoint(PointD pt1, PointD pt2)
 {
     BoundingBoxD box = new BoundingBoxD();
     if (pt1.X > pt2.X) { box.Xmin = pt2.X; box.Xmax = pt1.X; }
     else { box.Xmin = pt1.X; box.Xmax = pt2.X; }
     if (pt1.Y > pt2.Y) { box.Ymin = pt2.Y; box.Ymax = pt1.Y; }
     else { box.Ymin = pt1.Y; box.Ymax = pt2.Y; }
     return box;
 }
Exemplo n.º 4
0
 /// <summary>Returns a new BoundingBox bounding the two points specified.</summary>
 public static BoundingBoxD FromPoint(double x1, double y1, double x2, double y2)
 {
     BoundingBoxD box = new BoundingBoxD();
     if (x1 > x2) { box.Xmin = x2; box.Xmax = x1; }
     else         { box.Xmin = x1; box.Xmax = x2; }
     if (y1 > y2) { box.Ymin = y2; box.Ymax = y1; }
     else         { box.Ymin = y1; box.Ymax = y2; }
     return box;
 }
Exemplo n.º 5
0
 /// <summary>Returns a new BoundingBox bounding the specified circle.</summary>
 public static BoundingBoxD FromCircle(ref PointD center, double radius)
 {
     BoundingBoxD box = new BoundingBoxD();
     box.Xmin = center.X - radius;
     box.Xmax = center.X + radius;
     box.Ymin = center.Y - radius;
     box.Ymax = center.Y + radius;
     return box;
 }
Exemplo n.º 6
0
 /// <summary>Returns a new BoundingBox bounding all the points specified.</summary>
 public static BoundingBoxD FromPoint(IEnumerable<PointD> sites)
 {
     var result = new BoundingBoxD();
     result.AddPoint(sites);
     return result;
 }
Exemplo n.º 7
0
 /// <summary>Updates the bounding box by extending the bounds, if necessary, to include the specified bounding box.</summary>
 public void AddBoundingBox(BoundingBoxD box)
 {
     AddPoint(box.Xmin, box.Ymin);
     AddPoint(box.Xmax, box.Ymin);
     AddPoint(box.Xmax, box.Ymax);
     AddPoint(box.Xmin, box.Ymax);
 }
Exemplo n.º 8
0
 /// <summary>Returns true if this bounding box intersects with the specified bounding box.</summary>
 public bool IntersectsWithBoundingBox(BoundingBoxD box)
 {
     return Intersect.BoundingBoxWithBoundingBox(ref this, ref box);
 }
Exemplo n.º 9
0
 static BoundingBoxD()
 {
     Empty = new BoundingBoxD();
     Empty.Xmin = Empty.Xmax = Empty.Ymin = Empty.Ymax = double.NaN;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Fills a rectangle using the specified brush. The bounding box defines the coordinates.
 /// </summary>
 public void FillRectangle(Brush brush, ref BoundingBoxD box)
 {
     Graphics.FillRectangle(brush, SX(box.Xmin), sTop(box.Ymin, box.Ymax), SW(box.Xmax - box.Xmin) + 1, SH(box.Ymax - box.Ymin) + 1);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Draws a rectangle using the specified pen. The bounding box defines the coordinates.
 /// </summary>
 public void DrawRectangle(Pen pen, ref BoundingBoxD box)
 {
     Graphics.DrawRectangle(pen, SX(box.Xmin), sTop(box.Ymin, box.Ymax), SW(box.Xmax - box.Xmin) + 1, SH(box.Ymax - box.Ymin) + 1);
 }
Exemplo n.º 12
0
 /// <summary>
 ///     Checks for intersections between the two bounding boxes specified by the coordinates. Returns true if there is
 ///     at least one intersection.</summary>
 public static bool BoundingBoxWithBoundingBox(ref BoundingBoxD box1, ref BoundingBoxD box2)
 {
     return !((box2.Xmin > box1.Xmax && box2.Xmax > box1.Xmax) || (box2.Xmin < box1.Xmin && box2.Xmax < box1.Xmin)
           || (box2.Ymin > box1.Ymax && box2.Ymax > box1.Ymax) || (box2.Ymin < box1.Ymin && box2.Ymax < box1.Ymin));
 }
Exemplo n.º 13
0
        /// <summary>
        ///     Checks for intersections between a ray and a bounding box. Returns true if there is at least one intersection.</summary>
        public static bool RayWithBoundingBox(ref EdgeD ray, ref BoundingBoxD box)
        {
            double dx = ray.End.X - ray.Start.X;
            double dy = ray.End.Y - ray.Start.Y;
            double k, c;  // temporaries

            // Check intersection with horizontal bounds
            if (dy != 0)
            {
                // Upper line
                k = (box.Ymax - ray.Start.Y) / dy;
                if (k >= 0)
                {
                    c = ray.Start.X + k * dx;
                    if (c >= box.Xmin && c <= box.Xmax)
                        return true;
                }
                // Lower line
                k = (box.Ymin - ray.Start.Y) / dy;
                if (k >= 0)
                {
                    c = ray.Start.X + k * dx;
                    if (c >= box.Xmin && c <= box.Xmax)
                        return true;
                }
            }
            // Check intersection with vertical bounds
            if (dx != 0)
            {
                // Rightmost line
                k = (box.Xmax - ray.Start.X) / dx;
                if (k >= 0)
                {
                    c = ray.Start.Y + k * dy;
                    if (c >= box.Ymin && c <= box.Ymax)
                        return true;
                }
                // Leftmost line
                k = (box.Xmin - ray.Start.X) / dx;
                if (k >= 0)
                {
                    c = ray.Start.Y + k * dy;
                    if (c >= box.Ymin && c <= box.Ymax)
                        return true;
                }
            }

            return false;
        }