public class Dimension
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
Dimension
represents a width and a height in 2-dimensional space.
It provides various methods for manipulating the Dimension
or
creating new derived objects.Modifier and Type | Field and Description |
---|---|
double |
height
This
Dimension 's height. |
double |
width
This
Dimension 's width. |
Constructor and Description |
---|
Dimension()
Constructs a
Dimension of zero width and height. |
Dimension(Dimension d)
|
Dimension(double w,
double h)
Constructs a
Dimension with the supplied width and height values. |
Modifier and Type | Method and Description |
---|---|
Dimension |
clone() |
boolean |
contains(Dimension d)
|
boolean |
equals(double width,
double height)
Returns
true if this Dimension's width and height are equal
to the given width and height. |
boolean |
equals(java.lang.Object o)
Returns whether the input Object is equivalent to this Dimension.
|
Dimension |
expand(Dimension d)
Expands the size of this Dimension by the specified amount.
|
Dimension |
expand(double w,
double h)
Expands the size of this Dimension by the specified width and height.
|
Dimension |
getCopy()
Creates and returns a copy of this
Dimension . |
Dimension |
getExpanded(Dimension d)
|
Dimension |
getExpanded(double w,
double h)
Creates and returns a new Dimension representing the sum of this
Dimension and the one specified. |
double |
getHeight()
Returns the height of this dimension.
|
Dimension |
getIntersected(Dimension d)
Creates and returns a new Dimension representing the intersection of this
Dimension and the one specified.
|
Dimension |
getNegated()
Creates and returns a new Dimension with negated values.
|
Dimension |
getScaled(double amount)
Creates a new Dimension with its width and height scaled by the specified
value.
|
Dimension |
getScaled(double widthFactor,
double heightFactor)
Creates a new Dimension with its width and height scaled by the specified
values.
|
Dimension |
getShrinked(Dimension d)
Creates and returns a new Dimension whose size will be reduced by the
width and height of the given Dimension.
|
Dimension |
getShrinked(double w,
double h)
Creates and returns a new Dimension whose size will be reduced by the
given width and height.
|
Dimension |
getTransposed()
Creates a new Dimension with its height and width swapped.
|
Dimension |
getUnioned(Dimension d)
Creates a new Dimension representing the union of this Dimension with the
one specified.
|
double |
getWidth()
Returns the width of this dimension
|
int |
hashCode() |
Dimension |
intersect(Dimension d)
This Dimension is intersected with the one specified.
|
boolean |
isEmpty()
Returns
true if either dimension is less than or equal to 0. |
static Dimension |
max(Dimension d1,
Dimension d2)
|
static Dimension |
min(Dimension d1,
Dimension d2)
|
Dimension |
negate()
Negates the width and height of this Dimension.
|
Dimension |
scale(double factor)
Scales the width and height of this Dimension by the amount supplied, and
returns this for convenience.
|
Dimension |
scale(double widthFactor,
double heightFactor)
Scales the width of this Dimension by w and scales the height of
this Dimension by h.
|
Dimension |
setHeight(double height)
Sets the height of this Rectangle to the specified one.
|
Dimension |
setSize(Dimension d)
Copies the width and height values of the input Dimension to this
Dimension.
|
Dimension |
setSize(double w,
double h)
Sets the size of this dimension to the specified width and height.
|
Dimension |
setWidth(double width)
Sets the width of this Rectangle to the specified one.
|
Dimension |
shrink(Dimension d)
Shrinks the size of this Dimension by the width and height values of the
given Dimension.
|
Dimension |
shrink(double w,
double h)
Reduces the width of this Dimension by w, and reduces the height
of this Dimension by h.
|
java.lang.String |
toString() |
Dimension |
transpose()
Swaps the width and height of this Dimension, and returns this for
convenience.
|
Dimension |
union(Dimension d)
Sets the width of this Dimension to the greater of this Dimension's width
and d.width.
|
public Dimension()
Dimension
of zero width and height.public Dimension(Dimension d)
d
- the Dimension
supplying the initial width and height
valuespublic Dimension clone()
clone
in class java.lang.Object
public boolean contains(Dimension d)
public boolean equals(double width, double height)
true
if this Dimension's width and height are equal
to the given width and height.width
- the widthheight
- the heighttrue
if this dimension's width and height are equal
to those given.public boolean equals(java.lang.Object o)
true
if the Object is a Dimension and its width and height
are equal to this Dimension's width and height, false
otherwise.equals
in class java.lang.Object
o
- the Object being tested for equalitytrue
if the given object is equal to this dimensionpublic Dimension expand(Dimension d)
d
- the Dimension providing the expansion width and heightthis
for conveniencepublic Dimension expand(double w, double h)
w
- Value by which the width should be increasedh
- Value by which the height should be increasedthis
for conveniencepublic Dimension getCopy()
Dimension
.public Dimension getExpanded(Dimension d)
d
- the dimension providing the expansion width and heightpublic Dimension getExpanded(double w, double h)
Dimension
and the one specified.w
- value by which the width of this is to be expandedh
- value by which the height of this is to be expandedpublic double getHeight()
public Dimension getIntersected(Dimension d)
d
- the Dimension to intersect withpublic Dimension getNegated()
public Dimension getScaled(double amount)
amount
- Value by which the width and height are scaledpublic Dimension getScaled(double widthFactor, double heightFactor)
widthFactor
- the value by which the width is to be scaledheightFactor
- the value by which the height is to be scaledpublic Dimension getShrinked(Dimension d)
d
- the dimension whose width and height values will be consideredpublic Dimension getShrinked(double w, double h)
w
- the value by which the width is to be reducedh
- the value by which the height is to be reducedpublic Dimension getTransposed()
public Dimension getUnioned(Dimension d)
d
- the Dimension to be unionedpublic double getWidth()
public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public Dimension intersect(Dimension d)
d
- the Dimension used to perform the min()this
for conveniencepublic boolean isEmpty()
true
if either dimension is less than or equal to 0.true
if either dimension is less than or equal to 0.public Dimension negate()
this
for conveniencepublic Dimension scale(double factor)
factor
- value by which this Dimension's width and height are to be
scaledthis
for conveniencepublic Dimension scale(double widthFactor, double heightFactor)
widthFactor
- the value by which the width is to be scaledheightFactor
- the value by which the height is to be scaledthis
for conveniencepublic Dimension setHeight(double height)
height
- The new heightpublic Dimension setSize(Dimension d)
d
- the dimension supplying the valuesthis
for conveniencepublic Dimension setSize(double w, double h)
w
- The new widthh
- The new heightthis
for conveniencepublic Dimension setWidth(double width)
width
- The new widthpublic Dimension shrink(Dimension d)
d
- The dimension whose width and height values are to be usedthis
for conveniencepublic Dimension shrink(double w, double h)
w
- the value by which the width is to be reducedh
- the value by which the height is to be reducedthis
for conveniencepublic java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public Dimension transpose()
this
for convenienceCopyright (c) 2014 itemis AG, and others. All rights reserved.