Class Geometry2SWT

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

public class Geometry2SWT extends Object
Utility class to support conversions between GEF's geometry API and SWT's geometry classes.
  • Method Details

    • 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 Points 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 Points 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