Package org.eclipse.draw2d.geometry
Class Dimension
java.lang.Object
org.eclipse.draw2d.geometry.Dimension
- All Implemented Interfaces:
- Serializable,- Cloneable,- Translatable
- Direct Known Subclasses:
- PrecisionDimension
Stores an integer width and height. This class provides various methods for
 manipulating this Dimension or creating new derived Objects.
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs a Dimension of zero width and height.Dimension(int w, int h) Constructs a Dimension with the supplied width and height values.Constructs a Dimension with the width and height of the passed Dimension.Constructs a Dimension with the width and height of the Image supplied as input.Constructs a Dimension where the width and height are the x and y distances of the input point from the origin.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanReturnstrueif the input Dimension fits into this Dimension.booleanReturnstrueif this Dimension properly contains the one specified.booleanequals(int w, int h) 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.expand(int w, int h) Expands the size of this Dimension by the specified width and height.Expands the size of this Dimension by the specified amount.Deprecated, for removal: This API element is subject to removal in a future version.intgetArea()Returns the area of this Dimension.getCopy()Creates and returns a copy of this Dimension.Deprecated, for removal: This API element is subject to removal in a future version.UsegetShrinked(Dimension)instead.getExpanded(double w, double h) Creates and returns a new Dimension representing the sum of this Dimension and the one specified.getExpanded(int w, int h) Creates and returns a new Dimension representing the sum of this Dimension and the one specified.Creates and returns a Dimension representing the sum of this Dimension and the one specified.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.getShrinked(double w, double h) Creates and returns a new Dimension whose size will be reduced by the width and height of the given Dimension.getShrinked(int w, int h) Creates and returns a new Dimension whose size will be reduced by the width and height of the given Dimension.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.getUnioned(int w, int h) Creates a new Dimension representing the union of this Dimension with width and height specified.Creates a new Dimension representing the union of this Dimension with the one specified.inthashCode()intheight()Returns the height of this dimension.This Dimension is intersected with the one specified.booleanisEmpty()Returnstrueif either dimension is less than or equal to 0.static DimensionCreates a new Dimension representing the MAX of two provided Dimensions.static DimensionCreates a new Dimension representing the MIN of two provided Dimensions.negate()Negates the width and height of this Dimension.voidperformScale(double factor) Scales this object by the scale factor.voidperformTranslate(int dx, int dy) Translates this object horizontally bydxand vertically bydy.doubleReturnsdoubleheightdoubleReturnsdoublewidthscale(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(int height) Sets the height of this Rectangle to the specified one.setSize(int w, int h) Sets the size of this dimension to the specified width and height.voidCopies the width and height values of the input Dimension to this Dimension.setWidth(int 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.shrink(int w, int 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.union(int w, int h) Sets the width of this Dimension to the greater of this Dimension's width and width.Sets the width of this Dimension to the greater of this Dimension's width and d.width.intwidth()Returns the width of this dimensionMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.draw2d.geometry.TranslatableperformTranslate, performTranslate, performTranslate
- 
Field Details- 
SINGLETONA singleton for use in short calculations.
- 
widthpublic int widthThe width.
- 
heightpublic int heightThe height.
 
- 
- 
Constructor Details- 
Dimensionpublic Dimension()Constructs a Dimension of zero width and height.- Since:
- 2.0
 
- 
DimensionConstructs a Dimension with the width and height of the passed Dimension.- Parameters:
- d- the Dimension supplying the initial values
- Since:
- 2.0
 
- 
Dimensionpublic Dimension(int w, int h) Constructs a Dimension with the supplied width and height values.- Parameters:
- w- the width
- h- the height
- Since:
- 2.0
 
- 
DimensionConstructs a Dimension with the width and height of the Image supplied as input.- Parameters:
- image- the image supplying the dimensions
- Since:
- 2.0
 
- 
DimensionConstructs a Dimension where the width and height are the x and y distances of the input point from the origin.- Parameters:
- p- the Point supplying the initial values
- Since:
- 2.0
 
 
- 
- 
Method Details- 
maxCreates a new Dimension representing the MAX of two provided Dimensions.- Parameters:
- d1- first dimension
- d2- second dimension
- Returns:
- A new Dimension representing the Max()
- Since:
- 3.7
 
- 
minCreates a new Dimension representing the MIN of two provided Dimensions.- Parameters:
- d1- first dimension
- d2- second dimension
- Returns:
- A new Dimension representing the Min()
- Since:
- 3.7
 
- 
containsReturnstrueif the input Dimension fits into this Dimension. A Dimension of the same size is considered to "fit".- Parameters:
- d- the dimension being tested
- Returns:
- trueif this Dimension contains d
- Since:
- 2.0
 
- 
containsProperReturnstrueif this Dimension properly contains the one specified. Proper containment is defined as containment using \"<\", instead of \"<=\".- Parameters:
- d- the dimension being tested
- Returns:
- trueif this Dimension properly contains the one specified
- Since:
- 2.0
 
- 
equalspublic boolean equals(int w, int h) Returnstrueif this Dimension's width and height are equal to the given width and height.- Parameters:
- w- the width
- h- the height
- Returns:
- trueif this dimension's width and height are equal to those given.
- Since:
- 2.0
 
- 
equalsReturns 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.
- 
expandExpands the size of this Dimension by the specified amount.- Parameters:
- d- the Dimension providing the expansion width and height
- Returns:
- thisfor convenience
- Since:
- 2.0
 
- 
expandExpands the size of this Dimension by the specified width and height.- Parameters:
- w- Value by which the width should be increased
- h- Value by which the height should be increased
- Returns:
- thisfor convenience
- Since:
- 3.8
 
- 
expandExpands the size of this Dimension by the specified width and height.- Parameters:
- w- Value by which the width should be increased
- h- Value by which the height should be increased
- Returns:
- thisfor convenience
- Since:
- 2.0
 
- 
expandDeprecated, for removal: This API element is subject to removal in a future version.Useexpand(int, int)instead.Expands the size of this Dimension by the specified amound.- Parameters:
- p- the Point supplying the dimensional values
- Returns:
- thisfor convenience
- Since:
- 2.0
- @noreference
- This method is not intended to be referenced by clients.
 
- 
getAreapublic int getArea()Returns the area of this Dimension.- Returns:
- the area
- Since:
- 2.0
 
- 
getCopyCreates and returns a copy of this Dimension.- Returns:
- a copy of this Dimension
- Since:
- 2.0
 
- 
getDifferenceDeprecated, for removal: This API element is subject to removal in a future version.UsegetShrinked(Dimension)instead.Creates and returns a new Dimension representing the difference between this Dimension and the one specified.- Parameters:
- d- the dimension being compared
- Returns:
- a new dimension representing the difference
- Since:
- 2.0
- @noreference
- This method is not intended to be referenced by clients.
 
- 
getExpandedCreates and returns a Dimension representing the sum of this Dimension and the one specified.- Parameters:
- d- the dimension providing the expansion width and height
- Returns:
- a new dimension expanded by d
- Since:
- 2.0
 
- 
getExpandedCreates and returns a new Dimension representing the sum of this Dimension and the one specified.- Parameters:
- w- value by which the width of this is to be expanded
- h- value by which the height of this is to be expanded
- Returns:
- a new Dimension expanded by the given values
- Since:
- 3.8
 
- 
getExpandedCreates and returns a new Dimension representing the sum of this Dimension and the one specified.- Parameters:
- w- value by which the width of this is to be expanded
- h- value by which the height of this is to be expanded
- Returns:
- a new Dimension expanded by the given values
- Since:
- 2.0
 
- 
getIntersectedCreates 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
- Since:
- 2.0
 
- 
getNegatedCreates and returns a new Dimension with negated values.- Returns:
- a new Dimension with negated values
- Since:
- 2.0
 
- 
getScaledCreates 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
- Since:
- 2.0
 
- 
getShrinkedCreates 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
- Since:
- 3.7
 
- 
getShrinkedCreates and returns a new Dimension whose size will be reduced by the width and height of the given Dimension.- Parameters:
- w- the value by which the width is to be reduced
- h- the value by which the height is to be reduced
- Returns:
- a new dimension representing the difference
- Since:
- 3.8
 
- 
getShrinkedCreates and returns a new Dimension whose size will be reduced by the width and height of the given Dimension.- Parameters:
- w- the value by which the width is to be reduced
- h- the value by which the height is to be reduced
- Returns:
- a new dimension representing the difference
- Since:
- 3.7
 
- 
getTransposedCreates a new Dimension with its height and width swapped. Useful in orientation change calculations.- Returns:
- a new Dimension with its height and width swapped
- Since:
- 2.0
 
- 
getUnionedCreates 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
- Since:
- 2.0
 
- 
getUnionedCreates a new Dimension representing the union of this Dimension with width and height specified. Union is defined as the max() of the values from each Dimension.- Parameters:
- w- the value by which the width is to be unioned
- h- the value by which the height is to be unioned
- Returns:
- a new Dimension
- Since:
- 3.13
 
- 
hashCodepublic int hashCode()
- 
heightpublic int height()Returns the height of this dimension.- Returns:
- The current height
- Since:
- 3.7
 
- 
intersectThis 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
- Since:
- 2.0
 
- 
isEmptypublic boolean isEmpty()Returnstrueif either dimension is less than or equal to 0.- Returns:
- trueif either dimension is less than or equal to 0.
- Since:
- 2.0
 
- 
negateNegates the width and height of this Dimension.- Returns:
- thisfor convenience
- Since:
- 2.0
 
- 
performScalepublic void performScale(double factor) Description copied from interface:TranslatableScales this object by the scale factor.- Specified by:
- performScalein interface- Translatable
- Parameters:
- factor- The scale factor
- See Also:
 
- 
performTranslatepublic void performTranslate(int dx, int dy) Description copied from interface:TranslatableTranslates this object horizontally bydxand vertically bydy.- Specified by:
- performTranslatein interface- Translatable
- Parameters:
- dx- The amount to translate horizontally
- dy- The amount to translate vertically
- See Also:
 
- 
preciseHeightpublic double preciseHeight()Returnsdoubleheight- Returns:
- doubleheight
- Since:
- 3.4
 
- 
preciseWidthpublic double preciseWidth()Returnsdoublewidth- Returns:
- doublewidth
- Since:
- 3.4
 
- 
scaleScales 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
- Since:
- 2.0
 
- 
scaleScales 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 scaled
- heightFactor- the value by which the height is to be scaled
- Returns:
- thisfor convenience
- Since:
- 2.0
 
- 
setHeightSets the height of this Rectangle to the specified one.- Parameters:
- height- The new height
- Returns:
- this for convenience
- Since:
- 3.7
 
- 
setSizeCopies the width and height values of the input Dimension to this Dimension.- Parameters:
- d- the dimension supplying the values
- Since:
- 2.0
 
- 
setSizeSets the size of this dimension to the specified width and height.- Parameters:
- w- The new width
- h- The new height
- Since:
- 3.7
 
- 
setWidthSets the width of this Rectangle to the specified one.- Parameters:
- width- The new width
- Returns:
- this for convenience
- Since:
- 3.7
 
- 
shrinkShrinks 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
- Since:
- 3.7
 
- 
shrinkReduces 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 reduced
- h- the value by which the height is to be reduced
- Returns:
- thisfor convenience
- Since:
- 3.8
 
- 
shrinkReduces 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 reduced
- h- the value by which the height is to be reduced
- Returns:
- thisfor convenience
- Since:
- 2.0
 
- 
toString
- 
transposeSwaps the width and height of this Dimension, and returns this for convenience. Can be useful in orientation changes.- Returns:
- thisfor convenience
- Since:
- 2.0
 
- 
unionSets 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
- Since:
- 2.0
 
- 
unionSets the width of this Dimension to the greater of this Dimension's width and width. Likewise for this Dimension's height.- Parameters:
- w- the value by which the width is to be unioned
- h- the value by which the height is to be unioned
- Returns:
- a new Dimension
- Since:
- 3.13
 
- 
widthpublic int width()Returns the width of this dimension- Returns:
- the current width of this dimension
- Since:
- 3.7
 
 
- 
expand(int, int)instead.