Package com.jogamp.nativewindow.util
Class Rectangle
- java.lang.Object
-
- com.jogamp.nativewindow.util.Rectangle
-
- All Implemented Interfaces:
WriteCloneable
,RectangleImmutable
,Cloneable
,Comparable<RectangleImmutable>
public class Rectangle extends Object implements Cloneable, RectangleImmutable
-
-
Constructor Summary
Constructors Constructor Description Rectangle()
Rectangle(int x, int y, int width, int height)
Rectangle(RectangleImmutable s)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
cloneMutable()
int
compareTo(RectangleImmutable d)
Compares square of size 1st, if equal the square of position.boolean
contains(RectangleImmutable r)
float
coverage(RectangleImmutable r)
Returns the coverage of given rectangle w/ this this one, i.e.boolean
equals(Object obj)
Checks whether two rect objects are equal.int
getHeight()
int
getWidth()
int
getX()
x-position, left of rectangle.int
getY()
y-position, top of rectangle.int
hashCode()
Rectangle
intersection(int rx1, int ry1, int rx2, int ry2)
Returns a newRectangle
instance containing the intersection of this rectangle and the given coordinates.Rectangle
intersection(RectangleImmutable r)
Returns a newRectangle
instance containing the intersection of this rectangle and the given rectangle.Rectangle
scale(float sx, float sy)
Scale this instance's components, i.e.Rectangle
scale(int sx, int sy)
Scale this instance's components, i.e.Rectangle
scaleInv(float sx, float sy)
Inverse scale this instance's components, i.e.Rectangle
scaleInv(int sx, int sy)
Inverse scale this instance's components, i.e.Rectangle
set(int x, int y, int width, int height)
Rectangle
set(RectangleImmutable s)
Rectangle
setHeight(int height)
Rectangle
setWidth(int width)
Rectangle
setX(int x)
Rectangle
setY(int y)
String
toString()
Rectangle
union(int rx1, int ry1, int rx2, int ry2)
Returns a newRectangle
instance containing the union of this rectangle and the given coordinates.Rectangle
union(RectangleImmutable r)
Returns a newRectangle
instance containing the union of this rectangle and the given rectangle.Rectangle
union(List<RectangleImmutable> rectangles)
Calculates the union of the given rectangles, stores it in this instance and returns this instance.
-
-
-
Constructor Detail
-
Rectangle
public Rectangle()
-
Rectangle
public Rectangle(int x, int y, int width, int height)
-
Rectangle
public Rectangle(RectangleImmutable s)
-
-
Method Detail
-
cloneMutable
public Object cloneMutable()
- Specified by:
cloneMutable
in interfaceWriteCloneable
-
getX
public final int getX()
Description copied from interface:RectangleImmutable
x-position, left of rectangle.- Specified by:
getX
in interfaceRectangleImmutable
-
getY
public final int getY()
Description copied from interface:RectangleImmutable
y-position, top of rectangle.- Specified by:
getY
in interfaceRectangleImmutable
-
getWidth
public final int getWidth()
- Specified by:
getWidth
in interfaceRectangleImmutable
-
getHeight
public final int getHeight()
- Specified by:
getHeight
in interfaceRectangleImmutable
-
set
public final Rectangle set(int x, int y, int width, int height)
-
set
public final Rectangle set(RectangleImmutable s)
-
setX
public final Rectangle setX(int x)
-
setY
public final Rectangle setY(int y)
-
setWidth
public final Rectangle setWidth(int width)
-
setHeight
public final Rectangle setHeight(int height)
-
union
public final Rectangle union(RectangleImmutable r)
Description copied from interface:RectangleImmutable
Returns a newRectangle
instance containing the union of this rectangle and the given rectangle.- Specified by:
union
in interfaceRectangleImmutable
-
union
public final Rectangle union(int rx1, int ry1, int rx2, int ry2)
Description copied from interface:RectangleImmutable
Returns a newRectangle
instance containing the union of this rectangle and the given coordinates.- Specified by:
union
in interfaceRectangleImmutable
-
union
public final Rectangle union(List<RectangleImmutable> rectangles)
Description copied from interface:RectangleImmutable
Calculates the union of the given rectangles, stores it in this instance and returns this instance.- Specified by:
union
in interfaceRectangleImmutable
- Parameters:
rectangles
- given list of rectangles- Returns:
- this instance holding the union of given rectangles.
-
intersection
public final Rectangle intersection(RectangleImmutable r)
Description copied from interface:RectangleImmutable
Returns a newRectangle
instance containing the intersection of this rectangle and the given rectangle.- Specified by:
intersection
in interfaceRectangleImmutable
-
intersection
public final Rectangle intersection(int rx1, int ry1, int rx2, int ry2)
Description copied from interface:RectangleImmutable
Returns a newRectangle
instance containing the intersection of this rectangle and the given coordinates.- Specified by:
intersection
in interfaceRectangleImmutable
-
coverage
public final float coverage(RectangleImmutable r)
Description copied from interface:RectangleImmutable
Returns the coverage of given rectangle w/ this this one, i.e. between0.0
and1.0
.Coverage is computed by:
isect = this.intersection(r); coverage = area( isect ) / area( this ) ;
- Specified by:
coverage
in interfaceRectangleImmutable
-
contains
public final boolean contains(RectangleImmutable r)
- Specified by:
contains
in interfaceRectangleImmutable
-
scale
public final Rectangle scale(int sx, int sy)
Scale this instance's components, i.e. multiply them by the given scale factors.- Parameters:
sx
- scale factor for xsy
- scale factor for y- Returns:
- this instance for scaling
-
scale
public final Rectangle scale(float sx, float sy)
Scale this instance's components, i.e. multiply them by the given scale factors (rounded).- Parameters:
sx
- scale factor for xsy
- scale factor for y- Returns:
- this instance for scaling
-
scaleInv
public final Rectangle scaleInv(int sx, int sy)
Inverse scale this instance's components, i.e. divide them by the given scale factors.- Parameters:
sx
- inverse scale factor for xsy
- inverse scale factor for y- Returns:
- this instance for scaling
-
scaleInv
public final Rectangle scaleInv(float sx, float sy)
Inverse scale this instance's components, i.e. divide them by the given scale factors (rounded).- Parameters:
sx
- inverse scale factor for xsy
- inverse scale factor for y- Returns:
- this instance for scaling
-
compareTo
public int compareTo(RectangleImmutable d)
Description copied from interface:RectangleImmutable
Compares square of size 1st, if equal the square of position.
- Specified by:
compareTo
in interfaceComparable<RectangleImmutable>
- Specified by:
compareTo
in interfaceRectangleImmutable
-
equals
public boolean equals(Object obj)
Description copied from interface:RectangleImmutable
Checks whether two rect objects are equal. Two instances ofRectangle
are equal if the four integer values of the fieldsy
,x
,height
, andwidth
are all equal.- Specified by:
equals
in interfaceRectangleImmutable
- Overrides:
equals
in classObject
- Returns:
true
if the two rectangles are equal; otherwisefalse
.
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceRectangleImmutable
- Overrides:
hashCode
in classObject
-
-