Package org.eclipse.gef.geometry.planar
Class Dimension
java.lang.Object
org.eclipse.gef.geometry.planar.Dimension
- All Implemented Interfaces:
Serializable,Cloneable
A
Dimension represents a width and a height in 2-dimensional space.
It provides various methods for manipulating the Dimension or
creating new derived objects.- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()booleanbooleanequals(double width, double height) Returnstrueif this Dimension's width and height are equal to the given width and height.booleanReturns whether the input Object is equivalent to this Dimension.expand(double w, double h) Expands the size of this Dimension by the specified width and height.Expands the size of this Dimension by the specified amount.getCopy()Creates and returns a copy of thisDimension.getExpanded(double w, double h) Creates and returns a new Dimension representing the sum of thisDimensionand the one specified.doubleReturns the height of this dimension.Creates and returns a new Dimension representing the intersection of this Dimension and the one specified.Creates and returns a new Dimension with negated values.getScaled(double amount) Creates a new Dimension with its width and height scaled by the specified value.getScaled(double widthFactor, double heightFactor) Creates a new Dimension with its width and height scaled by the specified values.getShrinked(double w, double h) Creates and returns a new Dimension whose size will be reduced by the given width and height.Creates and returns a new Dimension whose size will be reduced by the width and height of the given Dimension.Creates a new Dimension with its height and width swapped.Creates a new Dimension representing the union of this Dimension with the one specified.doublegetWidth()Returns the width of this dimensioninthashCode()This Dimension is intersected with the one specified.booleanisEmpty()Returnstrueif either dimension is less than or equal to 0.static Dimensionstatic Dimensionnegate()Negates the width and height of this Dimension.scale(double factor) Scales the width and height of this Dimension by the amount supplied, and returns this for convenience.scale(double widthFactor, double heightFactor) Scales the width of this Dimension by w and scales the height of this Dimension by h.setHeight(double height) Sets the height of this Rectangle to the specified one.setSize(double w, double h) Sets the size of this dimension to the specified width and height.Copies the width and height values of the input Dimension to this Dimension.setWidth(double width) Sets the width of this Rectangle to the specified one.shrink(double w, double h) Reduces the width of this Dimension by w, and reduces the height of this Dimension by h.Shrinks the size of this Dimension by the width and height values of the given Dimension.toString()Swaps the width and height of this Dimension, and returns this for convenience.Sets the width of this Dimension to the greater of this Dimension's width and d.width.
-
Field Details
-
width
public double width -
height
public double height
-
-
Constructor Details
-
Method Details
-
max
-
min
-
clone
-
contains
-
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
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. -
expand
Expands the size of this Dimension by the specified amount.- Parameters:
d- the Dimension providing the expansion width and height- Returns:
thisfor convenience
-
expand
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
Creates and returns a copy of thisDimension.- Returns:
- a copy of this Dimension
-
getExpanded
- Parameters:
d- the dimension providing the expansion width and height- Returns:
- a new dimension expanded by d
-
getExpanded
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
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
Creates and returns a new Dimension with negated values.- Returns:
- a new Dimension with negated values
-
getScaled
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
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
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
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
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
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() -
intersect
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
Negates the width and height of this Dimension.- Returns:
thisfor convenience
-
scale
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
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
Sets the height of this Rectangle to the specified one.- Parameters:
height- The new height- Returns:
- this for convenience
-
setSize
Copies the width and height values of the input Dimension to this Dimension.- Parameters:
d- the dimension supplying the values- Returns:
thisfor convenience
-
setSize
Sets the size of this dimension to the specified width and height.- Parameters:
w- The new widthh- The new height- Returns:
thisfor convenience
-
setWidth
Sets the width of this Rectangle to the specified one.- Parameters:
width- The new width- Returns:
- this for convenience
-
shrink
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
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
-
transpose
Swaps the width and height of this Dimension, and returns this for convenience. Can be useful in orientation changes.- Returns:
thisfor convenience
-
union
Sets the width of this Dimension to the greater of this Dimension's width and d.width. Likewise for this Dimension's height.- Parameters:
d- the Dimension to union with this Dimension- Returns:
thisfor convenience
-