Package org.eclipse.gef.geometry.convert.swt

## Class Geometry2SWT

- java.lang.Object
- - org.eclipse.gef.geometry.convert.swt.Geometry2SWT

    public class Geometry2SWT
    extends java.lang.Object

Utility class to support conversions between GEF's geometry API and SWT's geometry classes.

### Method Summary

All Methods Static Methods Concrete Methods
`static PathData` `toSWTPathData​(Path p)` Converts the given path into an SWT `PathData` representation.
`static Point` `toSWTPoint​(Point p)` Creates a new SWT `Point` from this Point.
`static int[]` `toSWTPointArray​(Line l)` Returns an integer array of dimension 4, whose values represent the integer-based coordinates of this `Line`'s start and end point.
`static int[]` `toSWTPointArray​(Polygon p)` Returns an integer array, which represents the sequence of coordinates of the `Point`s that make up this `Polygon`.
`static int[]` `toSWTPointArray​(Polyline p)` Returns an integer array, which represents the sequence of coordinates of the `Point`s that make up this `Polyline`.
`static Rectangle` `toSWTRectangle​(Rectangle r)` Converts a `Rectangle` into an `Rectangle`.
`static Region` `toSWTRegion​(Region r)` Constructs a new `Region` that covers the same area as this `Region`.
`static Region` `toSWTRegion​(Ring r)` Constructs a new `Region` from this `Ring`.

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### toSWTPathData

    public static final PathData toSWTPathData​(Path p)

Converts the given path into an SWT `PathData` representation.

Parameters:
  `p` - the `Path` to convert
Returns:
  The `PathData` representing this path.

#### toSWTPoint

    public static final Point toSWTPoint​(Point p)

Creates a new SWT `Point` from this Point.

Parameters:
  `p` - the `Point` to convert
Returns:
  A new SWT Point

#### toSWTPointArray

    public static final int[] toSWTPointArray​(Line l)

Returns an integer array of dimension 4, whose values represent the integer-based coordinates of this `Line`'s start and end point.

Parameters:
  `l` - the `Line` to convert
Returns:
  an array containing integer values, which are obtained by casting x1, y1, x2, y2

#### toSWTPointArray

    public static final int[] toSWTPointArray​(Polygon p)

Returns an integer array, which represents the sequence of coordinates of the `Point`s that make up this `Polygon`. The x and y coordinate values are transfered to integer values by either applying `Math.floor(double)` or `Math.ceil(double)` to them, dependent on their relative position to the centroid of this `Polygon` (see `AbstractPointListBasedGeometry.getCentroid()`).

If the x coordinate of a `Point` is smaller than the x coordinate of the centroid, then the x coordinate of that `Point` is rounded down. Otherwise it is rounded up. Accordingly, if the y coordinate of a `Point` is smaller than the y coordinate of the centroid, it is rounded down. Otherwise, it is rounded up.

Parameters:
  `p` - the `Polygon` to convert
Returns:
  an integer array of the x and y coordinates of this `Polygon`

#### toSWTPointArray

    public static final int[] toSWTPointArray​(Polyline p)

Returns an integer array, which represents the sequence of coordinates of the `Point`s that make up this `Polyline`. The x and y coordinate values are transfered to integer values by either applying `Math.floor(double)` or `Math.ceil(double)` to them, dependent on their relative position to the centroid of this `Polyline` (see `AbstractPointListBasedGeometry.getCentroid()`).

If the x coordinate of a `Point` is smaller than the x coordinate of the centroid, then the x coordinate of that `Point` is rounded down. Otherwise it is rounded up. Accordingly, if the y coordinate of a `Point` is smaller than the y coordinate of the centroid, it is rounded down. Otherwise, it is rounded up.

Parameters:
  `p` - the `Polyline` to convert
Returns:
  an integer array of the x and y coordinates of this `Polyline`

#### toSWTRectangle

    public static final Rectangle toSWTRectangle​(Rectangle r)

Converts a `Rectangle` into an `Rectangle`. Note that as `Rectangle` is integer-based, this implies a loss of precision. The returned rectangle is the smallest integer-precision representation that fully contains this `Rectangle`.

Parameters:
  `r` - the `Rectangle` to convert
Returns:
  An `Rectangle` representation of this `Rectangle`.

#### toSWTRegion

    public static final Region toSWTRegion​(Region r)

Constructs a new `Region` that covers the same area as this `Region`. This is to ease the use of a `Region` for clipping:

`gc.setClipping(region.toSWTRegion());`

Parameters:
  `r` - the `Region` to convert
Returns:
  a new `Region` that covers the same area as this `Region`

#### toSWTRegion

    public static Region toSWTRegion​(Ring r)

Constructs a new `Region` from this `Ring`. The SWT `Region` can be used as a clipping area as follows: `gc.setClipping(ring.toSWTRegion());`

Parameters:
  `r` - the `Region` to convert
Returns:
  SWT `Region` representation of this `Ring`