org.eclipse.draw2d.geometry

## Class Dimension

- java.lang.Object
- - org.eclipse.draw2d.geometry.Dimension

All Implemented Interfaces:
  java.io.Serializable, java.lang.Cloneable, Translatable

Direct Known Subclasses:
  PrecisionDimension

    public class Dimension
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable, Translatable

Stores an integer width and height. This class provides various methods for manipulating this Dimension or creating new derived Objects.

See Also:
  Serialized Form

### Field Summary

Fields
`int` `height` The height.
`static Dimension` `SINGLETON` A singleton for use in short calculations.
`int` `width` The width.

### Constructor Summary

Constructors
Constructor and Description
`Dimension()` Constructs a Dimension of zero width and height.
`Dimension(Dimension d)` Constructs a Dimension with the width and height of the passed Dimension.
`Dimension(Image image)` Constructs a Dimension with the width and height of the Image supplied as input.
`Dimension(int w, int h)` Constructs a Dimension with the supplied width and height values.
`Dimension(Point p)` Constructs a Dimension where the width and height are the x and y distances of the input point from the origin.

### Method Summary

Methods
`boolean` `contains(Dimension d)` Returns `true` if the input Dimension fits into this Dimension.
`boolean` `containsProper(Dimension d)` Returns `true` if this Dimension properly contains the one specified.
`boolean` `equals(int w, int h)` 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` `expand(int w, int h)` Expands the size of this Dimension by the specified width and height.
`Dimension` `expand(Point p)` Deprecated. Use `expand(int, int)` instead.
`int` `getArea()` Returns the area of this Dimension.
`Dimension` `getCopy()` Creates and returns a copy of this Dimension.
`Dimension` `getDifference(Dimension d)` Deprecated. Use `getShrinked(Dimension)` instead.
`Dimension` `getExpanded(Dimension d)` Creates and returns a Dimension representing the sum of this Dimension and the one specified.
`Dimension` `getExpanded(double w, double h)` Creates and returns a new Dimension representing the sum of this Dimension and the one specified.
`Dimension` `getExpanded(int w, int h)` Creates and returns a new Dimension representing the sum of this Dimension and the one specified.
`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` `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 width and height of the given Dimension.
`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.
`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.
`int` `hashCode()`
`int` `height()` Returns the height of this dimension.
`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)` Creates a new Dimension representing the MAX of two provided Dimensions.
`static Dimension` `min(Dimension d1, Dimension d2)` Creates a new Dimension representing the MIN of two provided Dimensions.
`Dimension` `negate()` Negates the width and height of this Dimension.
`void` `performScale(double factor)` Scales this object by the scale factor.
`void` `performTranslate(int dx, int dy)` Translates this object horizontally by `dx` and vertically by `dy`.
`double` `preciseHeight()` Returns `double` height
`double` `preciseWidth()` Returns `double` width
`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(int height)` Sets the height of this Rectangle to the specified one.
`void` `setSize(Dimension d)` Copies the width and height values of the input Dimension to this Dimension.
`Dimension` `setSize(int w, int h)` Sets the size of this dimension to the specified width and height.
`Dimension` `setWidth(int 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.
`Dimension` `shrink(int w, int 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.
`int` `width()` Returns the width of this dimension

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### SINGLETON

    public static final Dimension SINGLETON

A singleton for use in short calculations.

#### width

    public int width

The width.

#### height

    public int height

The height.

### Constructor Detail

#### Dimension

    public Dimension()

Constructs a Dimension of zero width and height.

Since:
  2.0

#### Dimension

    public Dimension(Dimension d)

Constructs a Dimension with the width and height of the passed Dimension.

Parameters:
  `d` - the Dimension supplying the initial values
Since:
  2.0

#### Dimension

    public 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

#### Dimension

    public Dimension(Image image)

Constructs a Dimension with the width and height of the Image supplied as input.

Parameters:
  `image` - the image supplying the dimensions
Since:
  2.0

#### Dimension

    public Dimension(Point p)

Constructs 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 Detail

#### max

    public static Dimension max(Dimension d1,
                Dimension d2)

Creates 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

#### min

    public static Dimension min(Dimension d1,
                Dimension d2)

Creates 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

#### contains

    public boolean contains(Dimension d)

Returns `true` if the input Dimension fits into this Dimension. A Dimension of the same size is considered to "fit".

Parameters:
  `d` - the dimension being tested
Returns:
  `true` if this Dimension contains d
Since:
  2.0

#### containsProper

    public boolean containsProper(Dimension d)

Returns `true` if this Dimension properly contains the one specified. Proper containment is defined as containment using \"<\", instead of \"<=\".

Parameters:
  `d` - the dimension being tested
Returns:
  `true` if this Dimension properly contains the one specified
Since:
  2.0

#### equals

    public boolean equals(int w,
                 int h)

Returns `true` if this Dimension's width and height are equal to the given width and height.

Parameters:
  `w` - the width
  `h` - the height
Returns:
  `true` if this dimension's width and height are equal to those given.
Since:
  2.0

#### 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 class `java.lang.Object`
Parameters:
  `o` - the Object being tested for equality
Returns:
  `true` if the given object is equal to this dimension
Since:
  2.0

#### 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
Since:
  2.0

#### 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 increased
  `h` - Value by which the height should be increased
Returns:
  `this` for convenience
Since:
  3.8

#### expand

    public Dimension expand(int w,
                   int h)

Expands 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:
  `this` for convenience
Since:
  2.0

#### expand

    public Dimension expand(Point p)

Deprecated. Use `expand(int, int)` instead.
Expands the size of this Dimension by the specified amound.

Parameters:
  `p` - the Point supplying the dimensional values
Returns:
  `this` for convenience
Since:
  2.0

#### getArea

    public int getArea()

Returns the area of this Dimension.

Returns:
  the area
Since:
  2.0

#### getCopy

    public Dimension getCopy()

Creates and returns a copy of this Dimension.

Returns:
  a copy of this Dimension
Since:
  2.0

#### getDifference

    public Dimension getDifference(Dimension d)

Deprecated. Use `getShrinked(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

#### getExpanded

    public Dimension getExpanded(Dimension d)

Creates 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

#### getExpanded

    public Dimension getExpanded(double w,
                        double h)

Creates 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

#### getExpanded

    public Dimension getExpanded(int w,
                        int h)

Creates 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

#### 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
Since:
  2.0

#### getNegated

    public Dimension getNegated()

Creates and returns a new Dimension with negated values.

Returns:
  a new Dimension with negated values
Since:
  2.0

#### 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
Since:
  2.0

#### 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
Since:
  3.7

#### getShrinked

    public Dimension 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.

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

#### getShrinked

    public 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.

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

#### 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
Since:
  2.0

#### 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
Since:
  2.0

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `java.lang.Object`
See Also:
  `Object.hashCode()`

#### height

    public int height()

Returns the height of this dimension.

Returns:
  The current height
Since:
  3.7

#### 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
Since:
  2.0

#### isEmpty

    public boolean isEmpty()

Returns `true` if either dimension is less than or equal to 0.

Returns:
  `true` if either dimension is less than or equal to 0.
Since:
  2.0

#### negate

    public Dimension negate()

Negates the width and height of this Dimension.

Returns:
  `this` for convenience
Since:
  2.0

#### performScale

    public void performScale(double factor)

Description copied from interface: `Translatable`
Scales this object by the scale factor.

Specified by:
  `performScale` in interface `Translatable`
Parameters:
  `factor` - The scale factor
See Also:
  `Translatable.performScale(double)`

#### performTranslate

    public void performTranslate(int dx,
                        int dy)

Description copied from interface: `Translatable`
Translates this object horizontally by `dx` and vertically by `dy`.

Specified by:
  `performTranslate` in interface `Translatable`
Parameters:
  `dx` - The amount to translate horizontally
  `dy` - The amount to translate vertically
See Also:
  `Translatable.performTranslate(int, int)`

#### preciseHeight

    public double preciseHeight()

Returns `double` height

Returns:
  `double` height
Since:
  3.4

#### preciseWidth

    public double preciseWidth()

Returns `double` width

Returns:
  `double` width
Since:
  3.4

#### 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
Since:
  2.0

#### 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 scaled
  `heightFactor` - the value by which the height is to be scaled
Returns:
  `this` for convenience
Since:
  2.0

#### setHeight

    public Dimension setHeight(int height)

Sets the height of this Rectangle to the specified one.

Parameters:
  `height` - The new height
Returns:
  this for convenience
Since:
  3.7

#### setSize

    public void setSize(Dimension d)

Copies the width and height values of the input Dimension to this Dimension.

Parameters:
  `d` - the dimension supplying the values
Since:
  2.0

#### setSize

    public Dimension setSize(int w,
                    int h)

Sets the size of this dimension to the specified width and height.

Parameters:
  `w` - The new width
  `h` - The new height
Since:
  3.7

#### setWidth

    public Dimension setWidth(int width)

Sets the width of this Rectangle to the specified one.

Parameters:
  `width` - The new width
Returns:
  this for convenience
Since:
  3.7

#### 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
Since:
  3.7

#### 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 reduced
  `h` - the value by which the height is to be reduced
Returns:
  `this` for convenience
Since:
  3.8

#### shrink

    public Dimension shrink(int w,
                   int 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 reduced
  `h` - the value by which the height is to be reduced
Returns:
  `this` for convenience
Since:
  2.0

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.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
Since:
  2.0

#### union

    public Dimension union(Dimension d)

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:
  `this` for convenience
Since:
  2.0

#### width

    public int width()

Returns the width of this dimension

Returns:
  the current width of this dimension
Since:
  3.7