|
|
4ef489 |
using System;
|
|
|
4ef489 |
|
|
|
4ef489 |
namespace EllipseTruncate {
|
|
|
4ef489 |
public struct Rectangle {
|
|
|
4ef489 |
public double x0, y0, x1, y1;
|
|
|
4ef489 |
|
|
|
4ef489 |
public Point p0 {
|
|
|
4ef489 |
get { return new Point(x0, y0); }
|
|
|
4ef489 |
set { x0 = value.x; y0 = value.y; }
|
|
|
4ef489 |
}
|
|
|
4ef489 |
|
|
|
4ef489 |
public Point p1 {
|
|
|
4ef489 |
get { return new Point(x1, y1); }
|
|
|
4ef489 |
set { x1 = value.x; y1 = value.y; }
|
|
|
4ef489 |
}
|
|
|
4ef489 |
|
|
|
4ef489 |
public double width {
|
|
|
4ef489 |
get { return x1 - x0; }
|
|
|
4ef489 |
set { x1 = x0 + value; }
|
|
|
4ef489 |
}
|
|
|
4ef489 |
|
|
|
4ef489 |
public double height {
|
|
|
4ef489 |
get { return y1 - y0; }
|
|
|
4ef489 |
set { y1 = y0 + value; }
|
|
|
4ef489 |
}
|
|
|
4ef489 |
|
|
|
4ef489 |
public bool empty {
|
|
|
4ef489 |
get { return width <= Geometry.precision || height <= Geometry.precision; }
|
|
|
4ef489 |
}
|
|
|
4ef489 |
|
|
|
4ef489 |
public Rectangle(double x0, double y0, double x1, double y1) {
|
|
|
4ef489 |
this.x0 = x0;
|
|
|
4ef489 |
this.y0 = y0;
|
|
|
4ef489 |
this.x1 = x1;
|
|
|
4ef489 |
this.y1 = y1;
|
|
|
4ef489 |
}
|
|
|
4ef489 |
public Rectangle(double x, double y):
|
|
|
4ef489 |
this(x, y, x, y) { }
|
|
|
4ef489 |
public Rectangle(Point p):
|
|
|
4ef489 |
this(p.x, p.y) { }
|
|
|
4ef489 |
public Rectangle(Point p0, Point p1):
|
|
|
4ef489 |
this(p0.x, p0.y, p1.x, p1.y) { }
|
|
|
4ef489 |
|
|
|
4ef489 |
public Rectangle expand(Point p, double radius = 0.0) {
|
|
|
4ef489 |
return new Rectangle(
|
|
|
4ef489 |
Math.Min(x0, p.x),
|
|
|
4ef489 |
Math.Min(y0, p.y),
|
|
|
4ef489 |
Math.Max(x1, p.x),
|
|
|
4ef489 |
Math.Max(y1, p.y) );
|
|
|
4ef489 |
}
|
|
|
4ef489 |
|
|
|
4ef489 |
public Rectangle inflate(double x, double y) {
|
|
|
4ef489 |
return new Rectangle(
|
|
|
4ef489 |
x0 - x,
|
|
|
4ef489 |
y0 - y,
|
|
|
4ef489 |
x1 + x,
|
|
|
4ef489 |
y1 + y );
|
|
|
4ef489 |
}
|
|
|
4ef489 |
|
|
|
4ef489 |
public Rectangle inflate(double size) {
|
|
|
4ef489 |
return inflate(size, size);
|
|
|
4ef489 |
}
|
|
|
4ef489 |
|
|
|
4ef489 |
public static Rectangle operator| (Rectangle a, Rectangle b) {
|
|
|
4ef489 |
Rectangle rect = a.empty ? b
|
|
|
4ef489 |
: b.empty ? a
|
|
|
4ef489 |
: new Rectangle( Math.Min(a.x0, b.x0),
|
|
|
4ef489 |
Math.Min(a.y0, b.y0),
|
|
|
4ef489 |
Math.Max(a.x1, b.x1),
|
|
|
4ef489 |
Math.Max(a.y1, b.y1) );
|
|
|
4ef489 |
return rect.empty ? new Rectangle() : rect;
|
|
|
4ef489 |
}
|
|
|
4ef489 |
|
|
|
4ef489 |
public static Rectangle operator& (Rectangle a, Rectangle b) {
|
|
|
4ef489 |
Rectangle rect = a.empty ? b
|
|
|
4ef489 |
: b.empty ? a
|
|
|
4ef489 |
: new Rectangle( Math.Max(a.x0, b.x0),
|
|
|
4ef489 |
Math.Max(a.y0, b.y0),
|
|
|
4ef489 |
Math.Min(a.x1, b.x1),
|
|
|
4ef489 |
Math.Min(a.y1, b.y1) );
|
|
|
4ef489 |
return rect.empty ? new Rectangle() : rect;
|
|
|
4ef489 |
}
|
|
|
4ef489 |
}
|
|
|
4ef489 |
}
|
|
|
4ef489 |
|