Overview

 
Package  Use  Tree  Deprecated  Index  Help 
Eclipse Platform
Release 3.0
 PREV CLASS   NEXT CLASS FRAMES    NO FRAMES  
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD


 

org.eclipse.jface.util
Class Geometry

java.lang.Object
  extended byorg.eclipse.jface.util.Geometry


public class Geometry
extends Object

Contains static methods for performing simple geometric operations on the SWT geometry classes.

Since:
3.0


Method Summary
static Point add(Point point1, Point point2)
          Adds two points as 2d vectors.
static Point centerPoint(Rectangle rect)
          Returns the point in the center of the given rectangle.
static Point copy(Point toCopy)
          Returns a copy of the given point
static Rectangle copy(Rectangle toCopy)
          Returns a copy of the given rectangle
static Rectangle createRectangle(Point position, Point size)
          Returns a new rectangle with the given position and dimensions, expressed as points.
static int distanceSquared(Point p1, Point p2)
          Returns the square of the distance between two points.
static int dotProduct(Point p1, Point p2)
          Returns the dot product of the given vectors (expressed as Points)
static int getClosestSide(Rectangle boundary, Point toTest)
          Returns the edge of the given rectangle is closest to the given point.
static int getDimension(Rectangle toMeasure, boolean width)
          Returns the height or width of the given rectangle.
static Point getDirectionVector(int distance, int direction)
          Returns a vector in the given direction with the given magnitude.
static int getDistanceFromEdge(Rectangle rectangle, Point testPoint, int edgeOfInterest)
          Returns the distance of the given point from a particular side of the given rectangle.
static Rectangle getExtrudedEdge(Rectangle toExtrude, int size, int orientation)
          Extrudes the given edge inward by the given distance.
static Point getLocation(Rectangle toQuery)
          Returns the x,y position of the given rectangle.
static int getOppositeSide(int swtDirectionConstant)
          Returns the opposite of the given direction.
static int getRelativePosition(Rectangle boundary, Point toTest)
          Determines where the given point lies with respect to the given rectangle.
static Point getSize(Rectangle rectangle)
          Returns the size of the rectangle, as a Point
static int getSwtHorizontalOrVerticalConstant(boolean horizontal)
          Converts the given boolean into an SWT orientation constant.
static boolean isHorizontal(int swtSideConstant)
          Returns true iff the given SWT side constant corresponds to a horizontal side of a rectangle.
static double magnitude(Point p)
          Returns the magnitude of the given 2d vector (represented as a Point)
static int magnitudeSquared(Point p)
          Returns the square of the magnitude of the given 2-space vector (represented using a point)
static Point max(Point p1, Point p2)
          Returns a new point whose coordinates are the maximum of the coordinates of the given points
static Point min(Point p1, Point p2)
          Returns a new point whose coordinates are the minimum of the coordinates of the given points
static void moveRectangle(Rectangle rect, Point delta)
          Moves the given rectangle by the given delta.
static void normalize(Rectangle rect)
          Normalizes the given rectangle.
static void setLocation(Rectangle rectangle, Point newSize)
          Sets the x,y position of the given rectangle.
static void setSize(Rectangle rectangle, Point newSize)
          Sets the size of the given rectangle to the given size
static Point subtract(Point point1, Point point2)
          Performs vector subtraction on two points.
static Rectangle toControl(Control coordinateSystem, Rectangle toConvert)
          Converts the given rectangle from display coordinates to the local coordinate system of the given object into display coordinates.
static Rectangle toDisplay(Control coordinateSystem, Rectangle toConvert)
          Converts the given rectangle from the local coordinate system of the given object into display coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

 

 

distanceSquared

public static int distanceSquared(Point p1,
                                  Point p2)

Returns the square of the distance between two points.

This is preferred over the real distance when searching for the closest point, since it avoids square roots.

Parameters:
p1 - first endpoint
p2 - second endpoint
Returns:
the square of the distance between the two points
Since:
3.0


 

 

magnitude

public static double magnitude(Point p)

Returns the magnitude of the given 2d vector (represented as a Point)

Parameters:
p - point representing the 2d vector whose magnitude is being computed
Returns:
the magnitude of the given 2d vector
Since:
3.0


 

 

magnitudeSquared

public static int magnitudeSquared(Point p)

Returns the square of the magnitude of the given 2-space vector (represented using a point)

Parameters:
p - the point whose magnitude is being computed
Returns:
the square of the magnitude of the given vector
Since:
3.0


 

 

dotProduct

public static int dotProduct(Point p1,
                             Point p2)

Returns the dot product of the given vectors (expressed as Points)

Parameters:
p1 - the first vector
p2 - the second vector
Returns:
the dot product of the two vectors
Since:
3.0


 

 

min

public static Point min(Point p1,
                        Point p2)

Returns a new point whose coordinates are the minimum of the coordinates of the given points

Parameters:
p1 - a Point
p2 - a Point
Returns:
a new point whose coordinates are the minimum of the coordinates of the given points
Since:
3.0


 

 

max

public static Point max(Point p1,
                        Point p2)

Returns a new point whose coordinates are the maximum of the coordinates of the given points

Parameters:
p1 - a Point
p2 - a Point
Returns:
point a new point whose coordinates are the maximum of the coordinates
Since:
3.0


 

 

getDirectionVector

public static Point getDirectionVector(int distance,
                                       int direction)

Returns a vector in the given direction with the given magnitude. Directions are given using SWT direction constants, and the resulting vector is in the screen's coordinate system. That is, the vector (0, 1) is down and the vector (1, 0) is right.

Parameters:
distance - magnitude of the vector
direction - one of SWT.TOP, SWT.BOTTOM, SWT.LEFT, or SWT.RIGHT
Returns:
a point representing a vector in the given direction with the given magnitude
Since:
3.0


 

 

centerPoint

public static Point centerPoint(Rectangle rect)

Returns the point in the center of the given rectangle.

Parameters:
rect - rectangle being computed
Returns:
a Point at the center of the given rectangle.
Since:
3.0


 

 

copy

public static Point copy(Point toCopy)

Returns a copy of the given point

Parameters:
toCopy - point to copy
Returns:
a copy of the given point


 

 

add

public static Point add(Point point1,
                        Point point2)

Adds two points as 2d vectors. Returns a new point whose coordinates are the sum of the original two points.

Parameters:
point1 - the first point (not null)
point2 - the second point (not null)
Returns:
a new point whose coordinates are the sum of the given points
Since:
3.0


 

 

subtract

public static Point subtract(Point point1,
                             Point point2)

Performs vector subtraction on two points. Returns a new point equal to (point1 - point2).

Parameters:
point1 - initial point
point2 - vector to subtract
Returns:
the difference (point1 - point2)
Since:
3.0


 

 

getDimension

public static int getDimension(Rectangle toMeasure,
                               boolean width)

Returns the height or width of the given rectangle.

Parameters:
toMeasure - rectangle to measure
width - returns the width if true, and the height if false
Returns:
the width or height of the given rectangle
Since:
3.0


 

 

getDistanceFromEdge

public static int getDistanceFromEdge(Rectangle rectangle,
                                      Point testPoint,
                                      int edgeOfInterest)

Returns the distance of the given point from a particular side of the given rectangle. Returns negative values for points outside the rectangle.

Parameters:
rectangle - a bounding rectangle
testPoint - a point to test
edgeOfInterest - side of the rectangle to test against
Returns:
the distance of the given point from the given edge of the rectangle
Since:
3.0


 

 

getExtrudedEdge

public static Rectangle getExtrudedEdge(Rectangle toExtrude,
                                        int size,
                                        int orientation)

Extrudes the given edge inward by the given distance. That is, if one side of the rectangle was sliced off with a given thickness, this returns the rectangle that forms the slice. Note that the returned rectangle will be inside the given rectangle if size > 0.

Parameters:
toExtrude - the rectangle to extrude. The resulting rectangle will share three sides with this rectangle.
size - distance to extrude. A negative size will extrude outwards (that is, the resulting rectangle will overlap the original iff this is positive).
orientation - the side to extrude. One of SWT.LEFT, SWT.RIGHT, SWT.TOP, or SWT.BOTTOM. The resulting rectangle will always share this side with the original rectangle.
Returns:
a rectangle formed by extruding the given side of the rectangle by the given distance.
Since:
3.0


 

 

getOppositeSide

public static int getOppositeSide(int swtDirectionConstant)

Returns the opposite of the given direction. That is, returns SWT.LEFT if given SWT.RIGHT and visa-versa.

Parameters:
swtDirectionConstant - one of SWT.LEFT, SWT.RIGHT, SWT.TOP, or SWT.BOTTOM
Returns:
one of SWT.LEFT, SWT.RIGHT, SWT.TOP, or SWT.BOTTOM
Since:
3.0


 

 

getSwtHorizontalOrVerticalConstant

public static int getSwtHorizontalOrVerticalConstant(boolean horizontal)

Converts the given boolean into an SWT orientation constant.

Parameters:
horizontal - if true, returns SWT.HORIZONTAL. If false, returns SWT.VERTICAL
Returns:
SWT.HORIZONTAL or SWT.VERTICAL.
Since:
3.0


 

 

isHorizontal

public static boolean isHorizontal(int swtSideConstant)

Returns true iff the given SWT side constant corresponds to a horizontal side of a rectangle. That is, returns true for the top and bottom but false for the left and right.

Parameters:
swtSideConstant - one of SWT.TOP, SWT.BOTTOM, SWT.LEFT, or SWT.RIGHT
Returns:
true iff the given side is horizontal.
Since:
3.0


 

 

moveRectangle

public static void moveRectangle(Rectangle rect,
                                 Point delta)

Moves the given rectangle by the given delta.

Parameters:
rect - rectangle to move (will be modified)
delta - direction vector to move the rectangle by
Since:
3.0


 

 

normalize

public static void normalize(Rectangle rect)

Normalizes the given rectangle. That is, any rectangle with negative width or height becomes a rectangle with positive width or height that extends to the upper-left of the original rectangle.

Parameters:
rect - rectangle to modify
Since:
3.0


 

 

toControl

public static Rectangle toControl(Control coordinateSystem,
                                  Rectangle toConvert)

Converts the given rectangle from display coordinates to the local coordinate system of the given object into display coordinates.

Parameters:
coordinateSystem - local coordinate system being converted to
toConvert - rectangle to convert
Returns:
a rectangle in control coordinates
Since:
3.0


 

 

toDisplay

public static Rectangle toDisplay(Control coordinateSystem,
                                  Rectangle toConvert)

Converts the given rectangle from the local coordinate system of the given object into display coordinates.

Parameters:
coordinateSystem - local coordinate system being converted from
toConvert - rectangle to convert
Returns:
a rectangle in display coordinates
Since:
3.0


 

 

getRelativePosition

public static int getRelativePosition(Rectangle boundary,
                                      Point toTest)

Determines where the given point lies with respect to the given rectangle. Returns a combination of SWT.LEFT, SWT.RIGHT, SWT.TOP, and SWT.BOTTOM, combined with bitwise or (for example, returns SWT.TOP | SWT.LEFT if the point is to the upper-left of the rectangle). Returns 0 if the point lies within the rectangle. Positions are in screen coordinates (ie: a point is to the upper-left of the rectangle if its x and y coordinates are smaller than any point in the rectangle)

Parameters:
boundary - normalized boundary rectangle
toTest - point whose relative position to the rectangle is being computed
Returns:
one of SWT.LEFT | SWT.TOP, SWT.TOP, SWT.RIGHT | SWT.TOP, SWT.LEFT, 0, SWT.RIGHT, SWT.LEFT | SWT.BOTTOM, SWT.BOTTOM, SWT.RIGHT | SWT.BOTTOM
Since:
3.0


 

 

getClosestSide

public static int getClosestSide(Rectangle boundary,
                                 Point toTest)

Returns the edge of the given rectangle is closest to the given point.

Parameters:
boundary - rectangle to test
toTest - point to compare
Returns:
one of SWT.LEFT, SWT.RIGHT, SWT.TOP, or SWT.BOTTOM
Since:
3.0


 

 

copy

public static Rectangle copy(Rectangle toCopy)

Returns a copy of the given rectangle

Parameters:
toCopy - rectangle to copy
Returns:
a copy of the given rectangle
Since:
3.0


 

 

getSize

public static Point getSize(Rectangle rectangle)

Returns the size of the rectangle, as a Point

Parameters:
rectangle - rectangle whose size is being computed
Returns:
the size of the given rectangle
Since:
3.0


 

 

setSize

public static void setSize(Rectangle rectangle,
                           Point newSize)

Sets the size of the given rectangle to the given size

Parameters:
rectangle - rectangle to modify
newSize - new size of the rectangle
Since:
3.0


 

 

setLocation

public static void setLocation(Rectangle rectangle,
                               Point newSize)

Sets the x,y position of the given rectangle. For a normalized rectangle (a rectangle with positive width and height), this will be the upper-left corner of the rectangle.

Parameters:
rectangle - rectangle to modify
newSize - new size of the rectangle
Since:
3.0


 

 

getLocation

public static Point getLocation(Rectangle toQuery)

Returns the x,y position of the given rectangle. For normalized rectangles (rectangles with positive width and height), this is the upper-left corner of the rectangle.

Parameters:
toQuery - rectangle to query
Returns:
a Point containing the x,y position of the rectangle
Since:
3.0


 

 

createRectangle

public static Rectangle createRectangle(Point position,
                                        Point size)

Returns a new rectangle with the given position and dimensions, expressed as points.

Parameters:
position - the (x,y) position of the rectangle
size - the size of the new rectangle, where (x,y) -> (width, height)
Returns:
a new Rectangle with the given position and size
Since:
3.0


 

Overview

 
Package  Use  Tree  Deprecated  Index  Help 
Eclipse Platform
Release 3.0
 PREV CLASS   NEXT CLASS FRAMES    NO FRAMES  
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD


Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2004. All rights reserved.