Boxpublic class Box extends Object implements org.w3c.dom.svg.SVGRectThis class represents an "SVGRect" datatype, consisting of a minimum X,
minimum Y, width and height values. |
Fields Summary |
---|
public float | xThe smallest x-axis value of the rectangle | public float | yThe smallest y-axis value of the rectangle | public float | widthThe width value of the rectangle | public float | heightThe height value of the rectangle |
Constructors Summary |
---|
public Box(float x, float y, float w, float h)
this.x = x;
this.y = y;
this.width = w;
this.height = h;
| public Box(Box b)Copy constructor
this(b.x, b.y, b.width, b.height);
|
Methods Summary |
---|
public boolean | equals(java.lang.Object cmp)
if (cmp == this) {
return true;
}
if (cmp == null) {
return false;
}
if (cmp instanceof Box) {
Box b = (Box) cmp;
return b.x == x
&&
b.y == y
&&
b.width == width
&&
b.height == height;
}
return false;
| public float | getHeight()
return height;
| public float | getWidth()
return width;
| public float | getX()
return x;
| public float | getY()
return y;
| public void | setHeight(float value)
height = value;
| public void | setWidth(float value)
width = value;
| public void | setX(float value)
x = value;
| public void | setY(float value)
y = value;
| public void | snap()Snaps this Box instance to the integer grid.
float fmaxX = x + width;
float fmaxY = y + height;
// x and y need to snap to the left of the integer grid.
// We cannot simply cast as we need pixel accurate results.
// Narrowing rounds towards zero
int x = (int) this.x;
if (this.x < 0 && (this.x - x != 0)) {
x -= 1;
}
int y = (int) this.y; // Narrowing
if (this.y < 0 && (this.y - y) != 0) {
y -= 1;
}
// maxX and maxY need to snap to the right of the integer grid.
int maxX = (int) fmaxX;
if (fmaxX > 0 && (fmaxX - maxX) != 0) {
maxX += 1;
}
int maxY = (int) fmaxY;
if (fmaxY > 0 && (fmaxY - maxY) != 0) {
maxY += 1;
}
this.x = x;
this.y = y;
this.width = (maxX - x);
this.height = (maxY - y);
| public java.lang.String | toString()Debugging helper.
return "Box(" + x + ", " + y + ", " + width + ", " + height + ")";
|
|