Package org.eclipse.gef.geometry.planar
Class Dimension
- java.lang.Object
-
- org.eclipse.gef.geometry.planar.Dimension
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class Dimension extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable
ADimension
represents a width and a height in 2-dimensional space. It provides various methods for manipulating theDimension
or creating new derived objects.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Dimension
clone()
boolean
contains(Dimension d)
boolean
equals(double width, double height)
Returnstrue
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(double w, double h)
Expands the size of this Dimension by the specified width and height.Dimension
expand(Dimension d)
Expands the size of this Dimension by the specified amount.Dimension
getCopy()
Creates and returns a copy of thisDimension
.Dimension
getExpanded(double w, double h)
Creates and returns a new Dimension representing the sum of thisDimension
and the one specified.Dimension
getExpanded(Dimension d)
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(double w, double h)
Creates and returns a new Dimension whose size will be reduced by the given width and height.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
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 dimensionint
hashCode()
Dimension
intersect(Dimension d)
This Dimension is intersected with the one specified.boolean
isEmpty()
Returnstrue
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(double w, double h)
Sets the size of this dimension to the specified width and height.Dimension
setSize(Dimension d)
Copies the width and height values of the input Dimension to this Dimension.Dimension
setWidth(double width)
Sets the width of this Rectangle to the specified one.Dimension
shrink(double w, double h)
Reduces the width of this Dimension by w, and reduces the height of this Dimension by h.Dimension
shrink(Dimension d)
Shrinks the size of this Dimension by the width and height values of the given Dimension.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.
-
-
-
Method Detail
-
clone
public Dimension clone()
- Overrides:
clone
in classjava.lang.Object
-
contains
public boolean contains(Dimension d)
-
equals
public boolean equals(double width, double height)
Returnstrue
if this Dimension's width and height are equal to the given width and height.- Parameters:
width
- the widthheight
- the height- Returns:
true
if this dimension's width and height are equal to those given.
-
equals
public boolean equals(java.lang.Object o)
Returns whether the input Object is equivalent to this Dimension.true
if the Object is a Dimension and its width and height are equal to this Dimension's width and height,false
otherwise.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- the Object being tested for equality- Returns:
true
if the given object is equal to this dimension
-
expand
public Dimension expand(Dimension d)
Expands the size of this Dimension by the specified amount.- Parameters:
d
- the Dimension providing the expansion width and height- Returns:
this
for convenience
-
expand
public Dimension expand(double w, double h)
Expands the size of this Dimension by the specified width and height.- Parameters:
w
- Value by which the width should be increasedh
- Value by which the height should be increased- Returns:
this
for convenience
-
getCopy
public Dimension getCopy()
Creates and returns a copy of thisDimension
.- Returns:
- a copy of this Dimension
-
getExpanded
public Dimension getExpanded(Dimension d)
- Parameters:
d
- the dimension providing the expansion width and height- Returns:
- a new dimension expanded by d
-
getExpanded
public Dimension getExpanded(double w, double h)
Creates and returns a new Dimension representing the sum of thisDimension
and the one specified.- Parameters:
w
- value by which the width of this is to be expandedh
- value by which the height of this is to be expanded- Returns:
- a new Dimension expanded by the given values
-
getHeight
public double getHeight()
Returns the height of this dimension.- Returns:
- The current height
-
getIntersected
public Dimension getIntersected(Dimension d)
Creates and returns a new Dimension representing the intersection of this Dimension and the one specified.- Parameters:
d
- the Dimension to intersect with- Returns:
- A new Dimension representing the intersection
-
getNegated
public Dimension getNegated()
Creates and returns a new Dimension with negated values.- Returns:
- a new Dimension with negated values
-
getScaled
public Dimension getScaled(double amount)
Creates a new Dimension with its width and height scaled by the specified value.- Parameters:
amount
- Value by which the width and height are scaled- Returns:
- a new dimension with the scale applied
-
getScaled
public Dimension getScaled(double widthFactor, double heightFactor)
Creates a new Dimension with its width and height scaled by the specified values.- Parameters:
widthFactor
- the value by which the width is to be scaledheightFactor
- the value by which the height is to be scaled- Returns:
- a new dimension with the scale applied
-
getShrinked
public Dimension getShrinked(Dimension d)
Creates and returns a new Dimension whose size will be reduced by the width and height of the given Dimension.- Parameters:
d
- the dimension whose width and height values will be considered- Returns:
- a new dimension representing the difference
-
getShrinked
public Dimension getShrinked(double w, double h)
Creates and returns a new Dimension whose size will be reduced by the given width and height.- Parameters:
w
- the value by which the width is to be reducedh
- the value by which the height is to be reduced- Returns:
- a new dimension representing the difference
-
getTransposed
public Dimension getTransposed()
Creates a new Dimension with its height and width swapped. Useful in orientation change calculations.- Returns:
- a new Dimension with its height and width swapped
-
getUnioned
public Dimension getUnioned(Dimension d)
Creates a new Dimension representing the union of this Dimension with the one specified. Union is defined as the max() of the values from each Dimension.- Parameters:
d
- the Dimension to be unioned- Returns:
- a new Dimension
-
getWidth
public double getWidth()
Returns the width of this dimension- Returns:
- the current width of this dimension
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
- See Also:
Object.hashCode()
-
intersect
public Dimension intersect(Dimension d)
This Dimension is intersected with the one specified. Intersection is performed by taking the min() of the values from each dimension.- Parameters:
d
- the Dimension used to perform the min()- Returns:
this
for convenience
-
isEmpty
public boolean isEmpty()
Returnstrue
if either dimension is less than or equal to 0.- Returns:
true
if either dimension is less than or equal to 0.
-
negate
public Dimension negate()
Negates the width and height of this Dimension.- Returns:
this
for convenience
-
scale
public Dimension scale(double factor)
Scales the width and height of this Dimension by the amount supplied, and returns this for convenience.- Parameters:
factor
- value by which this Dimension's width and height are to be scaled- Returns:
this
for convenience
-
scale
public Dimension scale(double widthFactor, double heightFactor)
Scales the width of this Dimension by w and scales the height of this Dimension by h. Returns this for convenience.- Parameters:
widthFactor
- the value by which the width is to be scaledheightFactor
- the value by which the height is to be scaled- Returns:
this
for convenience
-
setHeight
public Dimension setHeight(double height)
Sets the height of this Rectangle to the specified one.- Parameters:
height
- The new height- Returns:
- this for convenience
-
setSize
public Dimension setSize(Dimension d)
Copies the width and height values of the input Dimension to this Dimension.- Parameters:
d
- the dimension supplying the values- Returns:
this
for convenience
-
setSize
public Dimension setSize(double w, double h)
Sets the size of this dimension to the specified width and height.- Parameters:
w
- The new widthh
- The new height- Returns:
this
for convenience
-
setWidth
public Dimension setWidth(double width)
Sets the width of this Rectangle to the specified one.- Parameters:
width
- The new width- Returns:
- this for convenience
-
shrink
public Dimension shrink(Dimension d)
Shrinks the size of this Dimension by the width and height values of the given Dimension.- Parameters:
d
- The dimension whose width and height values are to be used- Returns:
this
for convenience
-
shrink
public Dimension shrink(double w, double h)
Reduces the width of this Dimension by w, and reduces the height of this Dimension by h. Returns this for convenience.- Parameters:
w
- the value by which the width is to be reducedh
- the value by which the height is to be reduced- Returns:
this
for convenience
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- See Also:
Object.toString()
-
transpose
public Dimension transpose()
Swaps the width and height of this Dimension, and returns this for convenience. Can be useful in orientation changes.- Returns:
this
for convenience
-
-