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.SerializableADimensionrepresents a width and a height in 2-dimensional space. It provides various methods for manipulating theDimensionor creating new derived objects.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Dimensionclone()booleancontains(Dimension d)booleanequals(double width, double height)Returnstrueif this Dimension's width and height are equal to the given width and height.booleanequals(java.lang.Object o)Returns whether the input Object is equivalent to this Dimension.Dimensionexpand(double w, double h)Expands the size of this Dimension by the specified width and height.Dimensionexpand(Dimension d)Expands the size of this Dimension by the specified amount.DimensiongetCopy()Creates and returns a copy of thisDimension.DimensiongetExpanded(double w, double h)Creates and returns a new Dimension representing the sum of thisDimensionand the one specified.DimensiongetExpanded(Dimension d)doublegetHeight()Returns the height of this dimension.DimensiongetIntersected(Dimension d)Creates and returns a new Dimension representing the intersection of this Dimension and the one specified.DimensiongetNegated()Creates and returns a new Dimension with negated values.DimensiongetScaled(double amount)Creates a new Dimension with its width and height scaled by the specified value.DimensiongetScaled(double widthFactor, double heightFactor)Creates a new Dimension with its width and height scaled by the specified values.DimensiongetShrinked(double w, double h)Creates and returns a new Dimension whose size will be reduced by the given width and height.DimensiongetShrinked(Dimension d)Creates and returns a new Dimension whose size will be reduced by the width and height of the given Dimension.DimensiongetTransposed()Creates a new Dimension with its height and width swapped.DimensiongetUnioned(Dimension d)Creates a new Dimension representing the union of this Dimension with the one specified.doublegetWidth()Returns the width of this dimensioninthashCode()Dimensionintersect(Dimension d)This Dimension is intersected with the one specified.booleanisEmpty()Returnstrueif either dimension is less than or equal to 0.static Dimensionmax(Dimension d1, Dimension d2)static Dimensionmin(Dimension d1, Dimension d2)Dimensionnegate()Negates the width and height of this Dimension.Dimensionscale(double factor)Scales the width and height of this Dimension by the amount supplied, and returns this for convenience.Dimensionscale(double widthFactor, double heightFactor)Scales the width of this Dimension by w and scales the height of this Dimension by h.DimensionsetHeight(double height)Sets the height of this Rectangle to the specified one.DimensionsetSize(double w, double h)Sets the size of this dimension to the specified width and height.DimensionsetSize(Dimension d)Copies the width and height values of the input Dimension to this Dimension.DimensionsetWidth(double width)Sets the width of this Rectangle to the specified one.Dimensionshrink(double w, double h)Reduces the width of this Dimension by w, and reduces the height of this Dimension by h.Dimensionshrink(Dimension d)Shrinks the size of this Dimension by the width and height values of the given Dimension.java.lang.StringtoString()Dimensiontranspose()Swaps the width and height of this Dimension, and returns this for convenience.Dimensionunion(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:
clonein classjava.lang.Object
-
contains
public boolean contains(Dimension d)
-
equals
public boolean equals(double width, double height)Returnstrueif this Dimension's width and height are equal to the given width and height.- Parameters:
width- the widthheight- the height- Returns:
trueif 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.trueif the Object is a Dimension and its width and height are equal to this Dimension's width and height,falseotherwise.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the Object being tested for equality- Returns:
trueif 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:
thisfor 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:
thisfor 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 thisDimensionand 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:
hashCodein 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:
thisfor convenience
-
isEmpty
public boolean isEmpty()
Returnstrueif either dimension is less than or equal to 0.- Returns:
trueif either dimension is less than or equal to 0.
-
negate
public Dimension negate()
Negates the width and height of this Dimension.- Returns:
thisfor 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:
thisfor 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:
thisfor 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:
thisfor 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:
thisfor 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:
thisfor 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:
thisfor convenience
-
toString
public java.lang.String toString()
- Overrides:
toStringin 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:
thisfor convenience
-
-