29package com.jogamp.nativewindow.util;
43 public Rectangle(
final int x,
final int y,
final int width,
final int height) {
62 }
catch (
final CloneNotSupportedException ex) {
63 throw new InternalError();
68 public final int getX() {
return x; }
70 public final int getY() {
return y; }
76 public final Rectangle set(
final int x,
final int y,
final int width,
final int height) {
86 this.width = s.getWidth();
87 this.height = s.getHeight();
100 public final Rectangle union(
final int rx1,
final int ry1,
final int rx2,
final int ry2) {
101 final int x1 = Math.min(x, rx1);
102 final int y1 = Math.min(y, ry1);
103 final int x2 = Math.max(x + width - 1, rx2);
104 final int y2 = Math.max(y + height - 1, ry2);
105 return new Rectangle(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
109 int x1=Integer.MAX_VALUE, y1=Integer.MAX_VALUE;
110 int x2=Integer.MIN_VALUE, y2=Integer.MIN_VALUE;
111 for(
int i=rectangles.size()-1; i>=0; i--) {
113 x1 = Math.min(x1, vp.
getX());
115 y1 = Math.min(y1, vp.
getY());
118 return new Rectangle(x1, y1, x2 - x1, y2 - y1);
127 final int x1 = Math.max(x, rx1);
128 final int y1 = Math.max(y, ry1);
129 final int x2 = Math.min(x + width - 1, rx2);
130 final int y2 = Math.min(y + height - 1, ry2);
131 final int ix, iy, iwidth, iheight;
137 iwidth = x2 - x1 + 1;
144 iheight = y2 - y1 + 1;
146 return new Rectangle (ix, iy, iwidth, iheight);
152 final float sqT = width*height;
158 final int x2 = x + width - 1;
159 final int y2 = y + height - 1;
160 final int rx1 = r.
getX();
161 final int ry1 = r.
getY();
162 final int rx2 = rx1 + r.
getWidth() - 1;
164 if( rx1 < x || ry1 < y ||
165 rx2 > x2 || ry2 > y2 ) {
194 x = (int)( x * sx + 0.5f );
195 y = (int)( y * sy + 0.5f );
196 width = (int)( width * sx + 0.5f );
197 height = (int)( height * sy + 0.5f );
224 x = (int)( x / sx + 0.5f );
225 y = (int)( y / sy + 0.5f );
226 width = (int)( width / sx + 0.5f );
227 height = (int)( height / sy + 0.5f );
234 final int sq = width*height;
239 }
else if(sq < xsq) {
250 }
else if(sq < xsq) {
258 public boolean equals(
final Object obj) {
259 if(
this == obj) {
return true; }
262 return (y == rect.y) && (x == rect.x) &&
263 (height == rect.height) && (width == rect.width);
270 final int sum1 = x + height;
271 final int sum2 = width + y;
272 final int val1 = sum1 * (sum1 + 1)/2 + x;
273 final int val2 = sum2 * (sum2 + 1)/2 + y;
274 final int sum3 = val1 + val2;
275 return sum3 * (sum3 + 1)/2 + val2;
280 return "[ "+x+
" / "+y+
" "+width+
" x "+height+
" ]";
Rectangle(final int x, final int y, final int width, final int height)
final Rectangle scale(final int sx, final int sy)
Scale this instance's components, i.e.
final Rectangle scaleInv(final float sx, final float sy)
Inverse scale this instance's components, i.e.
final int getX()
x-position, left of rectangle.
final float coverage(final RectangleImmutable r)
Returns the coverage of given rectangle w/ this this one, i.e.
final Rectangle scaleInv(final int sx, final int sy)
Inverse scale this instance's components, i.e.
final Rectangle setWidth(final int width)
final int getY()
y-position, top of rectangle.
final Rectangle union(final int rx1, final int ry1, final int rx2, final int ry2)
Returns a new Rectangle instance containing the union of this rectangle and the given coordinates.
Rectangle(final RectangleImmutable s)
final Rectangle intersection(final RectangleImmutable r)
Returns a new Rectangle instance containing the intersection of this rectangle and the given rectangl...
final Rectangle intersection(final int rx1, final int ry1, final int rx2, final int ry2)
Returns a new Rectangle instance containing the intersection of this rectangle and the given coordina...
final Rectangle scale(final float sx, final float sy)
Scale this instance's components, i.e.
final Rectangle setY(final int y)
int compareTo(final RectangleImmutable d)
final Rectangle union(final RectangleImmutable r)
Returns a new Rectangle instance containing the union of this rectangle and the given rectangle.
final boolean contains(final RectangleImmutable r)
final Rectangle setHeight(final int height)
boolean equals(final Object obj)
Checks whether two rect objects are equal.
final Rectangle setX(final int x)
final Rectangle union(final List< RectangleImmutable > rectangles)
Calculates the union of the given rectangles, stores it in this instance and returns this instance.
Immutable Rectangle interface, with its position on the top-left.
int getX()
x-position, left of rectangle.
int getY()
y-position, top of rectangle.