|
Eclipse Platform Release 3.1 |
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.jface.util.Geometry
Contains static methods for performing simple geometric operations on the SWT geometry classes.
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 Point |
divide(Point toDivide,
int scalar)
Divides both coordinates of the given point by the given scalar. |
static int |
dotProduct(Point p1,
Point p2)
Returns the dot product of the given vectors (expressed as Points) |
static void |
expand(Rectangle rect,
int left,
int right,
int top,
int bottom)
Moves each edge of the given rectangle outward by the given amount. |
static void |
flipXY(Point toFlip)
Swaps the X and Y coordinates of the given point. |
static void |
flipXY(Rectangle toFlip)
Swaps the X and Y coordinates of the given rectangle, along with the height and width. |
static int |
getClosestSide(Rectangle boundary,
Point toTest)
Returns the edge of the given rectangle is closest to the given point. |
static int |
getCoordinate(Point toMeasure,
boolean width)
Returns the x or y coordinates of the given point. |
static int |
getCoordinate(Rectangle toMeasure,
boolean width)
Returns the x or y coordinates of the given rectangle. |
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 |
getDistanceFrom(Rectangle boundary,
Point toTest)
Returns the distance from the point to the nearest edge of the given rectangle. |
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 |
set(Point result,
Point toCopy)
Sets result equal to toCopy |
static void |
set(Rectangle result,
Rectangle toCopy)
Sets result equal to toCopy |
static void |
setCoordinate(Point toSet,
boolean width,
int newCoordinate)
Sets one coordinate of the given point. |
static void |
setCoordinate(Rectangle toSet,
boolean width,
int newCoordinate)
Sets one coordinate of the given rectangle. |
static void |
setDimension(Rectangle toSet,
boolean width,
int newCoordinate)
Sets one dimension of 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 |
public static int distanceSquared(Point p1, Point p2)
This is preferred over the real distance when searching for the closest point, since it avoids square roots.
p1
- first endpointp2
- second endpoint
public static double magnitude(Point p)
p
- point representing the 2d vector whose magnitude is being computed
public static int magnitudeSquared(Point p)
p
- the point whose magnitude is being computed
public static int dotProduct(Point p1, Point p2)
p1
- the first vectorp2
- the second vector
public static Point min(Point p1, Point p2)
p1
- a Pointp2
- a Point
public static Point max(Point p1, Point p2)
p1
- a Pointp2
- a Point
public static Point getDirectionVector(int distance, int direction)
distance
- magnitude of the vectordirection
- one of SWT.TOP, SWT.BOTTOM, SWT.LEFT, or SWT.RIGHT
public static Point centerPoint(Rectangle rect)
rect
- rectangle being computed
public static Point copy(Point toCopy)
toCopy
- point to copy
public static void set(Point result, Point toCopy)
result
- object that will be modifiedtoCopy
- object that will be copiedpublic static void set(Rectangle result, Rectangle toCopy)
result
- object that will be modifiedtoCopy
- object that will be copiedpublic static Point add(Point point1, Point point2)
point1
- the first point (not null)point2
- the second point (not null)
public static Point divide(Point toDivide, int scalar)
toDivide
- point to dividescalar
- denominator
public static Point subtract(Point point1, Point point2)
point1
- initial pointpoint2
- vector to subtract
public static void flipXY(Point toFlip)
toFlip
- modifies this pointpublic static void flipXY(Rectangle toFlip)
toFlip
- modifies this rectanglepublic static int getDimension(Rectangle toMeasure, boolean width)
toMeasure
- rectangle to measurewidth
- returns the width if true, and the height if false
public static int getCoordinate(Point toMeasure, boolean width)
toMeasure
- point being measuredwidth
- if true, returns x. Otherwise, returns y.
public static int getCoordinate(Rectangle toMeasure, boolean width)
toMeasure
- rectangle being measuredwidth
- if true, returns x. Otherwise, returns y.
public static void setDimension(Rectangle toSet, boolean width, int newCoordinate)
toSet
- rectangle to modifywidth
- if true, the width is modified. If false, the height is modified.newCoordinate
- new value of the width or heightpublic static void setCoordinate(Rectangle toSet, boolean width, int newCoordinate)
toSet
- rectangle to modifywidth
- if true, the x coordinate is modified. If false, the y coordinate is modified.newCoordinate
- new value of the x or y coordinatespublic static void setCoordinate(Point toSet, boolean width, int newCoordinate)
toSet
- point to modifywidth
- if true, the x coordinate is modified. If false, the y coordinate is modified.newCoordinate
- new value of the x or y coordinatespublic static int getDistanceFromEdge(Rectangle rectangle, Point testPoint, int edgeOfInterest)
rectangle
- a bounding rectangletestPoint
- a point to testedgeOfInterest
- side of the rectangle to test against
public static Rectangle getExtrudedEdge(Rectangle toExtrude, int size, int orientation)
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.
public static int getOppositeSide(int swtDirectionConstant)
swtDirectionConstant
- one of SWT.LEFT, SWT.RIGHT, SWT.TOP, or SWT.BOTTOM
public static int getSwtHorizontalOrVerticalConstant(boolean horizontal)
horizontal
- if true, returns SWT.HORIZONTAL. If false, returns SWT.VERTICAL
public static boolean isHorizontal(int swtSideConstant)
swtSideConstant
- one of SWT.TOP, SWT.BOTTOM, SWT.LEFT, or SWT.RIGHT
public static void moveRectangle(Rectangle rect, Point delta)
rect
- rectangle to move (will be modified)delta
- direction vector to move the rectangle bypublic static void expand(Rectangle rect, int left, int right, int top, int bottom)
rect
- normalized rectangle to modifyleft
- distance to move the left edge outward (negative values move the edge inward)right
- distance to move the right edge outward (negative values move the edge inward)top
- distance to move the top edge outward (negative values move the edge inward)bottom
- distance to move the bottom edge outward (negative values move the edge inward)public static void normalize(Rectangle rect)
rect
- rectangle to modifypublic static Rectangle toControl(Control coordinateSystem, Rectangle toConvert)
coordinateSystem
- local coordinate system being converted totoConvert
- rectangle to convert
public static Rectangle toDisplay(Control coordinateSystem, Rectangle toConvert)
coordinateSystem
- local coordinate system being converted fromtoConvert
- rectangle to convert
public static int getRelativePosition(Rectangle boundary, Point toTest)
boundary
- normalized boundary rectangletoTest
- point whose relative position to the rectangle is being computed
public static int getDistanceFrom(Rectangle boundary, Point toTest)
boundary
- rectangle to testtoTest
- point to test
public static int getClosestSide(Rectangle boundary, Point toTest)
boundary
- rectangle to testtoTest
- point to compare
public static Rectangle copy(Rectangle toCopy)
toCopy
- rectangle to copy
public static Point getSize(Rectangle rectangle)
rectangle
- rectangle whose size is being computed
public static void setSize(Rectangle rectangle, Point newSize)
rectangle
- rectangle to modifynewSize
- new size of the rectanglepublic static void setLocation(Rectangle rectangle, Point newSize)
rectangle
- rectangle to modifynewSize
- new size of the rectanglepublic static Point getLocation(Rectangle toQuery)
toQuery
- rectangle to query
public static Rectangle createRectangle(Point position, Point size)
position
- the (x,y) position of the rectanglesize
- the size of the new rectangle, where (x,y) -> (width, height)
|
Eclipse Platform Release 3.1 |
|||||||||||
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, 2005. All rights reserved.