Class Geom
- java.lang.Object
-
- org.jhotdraw.geom.Geom
-
public class Geom extends java.lang.ObjectSome geometric utilities.
-
-
Field Summary
Fields Modifier and Type Field and Description static intOUT_BOTTOMThe bitmask that indicates that a point lies below the rectangle.static intOUT_LEFTThe bitmask that indicates that a point lies to the left of the rectangle.static intOUT_RIGHTThe bitmask that indicates that a point lies to the right of the rectangle.static intOUT_TOPThe bitmask that indicates that a point lies above the rectangle.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static doubleangle(double x1, double y1, double x2, double y2)Gets the angle of the specified line.static java.awt.geom.Point2D.DoubleangleToPoint(java.awt.geom.Rectangle2D.Double r, double angle)Gets the point on a rectangle that corresponds to the given angle.static java.awt.PointangleToPoint(java.awt.Rectangle r, double angle)Gets the point on a rectangle that corresponds to the given angle.static java.awt.geom.Point2D.Doublecap(java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2, double radius)Caps the line defined by p1 and p2 by the number of units specified by radius.static java.awt.Pointcenter(java.awt.Rectangle r)static java.awt.geom.Point2D.Doublecenter(java.awt.geom.Rectangle2D.Double r)static java.awt.geom.Point2D.Doublechop(java.awt.Shape shape, java.awt.geom.Point2D.Double p)Returns a point on the edge of the shape which crosses the line from the center of the shape to the specified point.static booleancontains(java.awt.geom.Rectangle2D.Double r1, java.awt.geom.Rectangle2D.Double r2)Returns true, if rectangle 1 contains rectangle 2.static booleancontains(java.awt.geom.Rectangle2D r1, java.awt.geom.Rectangle2D r2)Returns true, if rectangle 1 contains rectangle 2.static intdirection(double x1, double y1, double x2, double y2)Returns the direction OUT_TOP, OUT_BOTTOM, OUT_LEFT, OUT_RIGHT from one point to another one.static intdirection(int x1, int y1, int x2, int y2)Returns the direction OUT_TOP, OUT_BOTTOM, OUT_LEFT, OUT_RIGHT from one point to another one.static doubledistanceFromLine(int xa, int ya, int xb, int yb, int xc, int yc)compute distance of point from line segment, or Double.MAX_VALUE if perpendicular projection is outside segment; or If pts on line are same, return distance from pointstatic java.awt.Pointeast(java.awt.Rectangle r)static java.awt.geom.Point2D.Doubleeast(java.awt.geom.Rectangle2D.Double r)static voidgrow(java.awt.geom.Rectangle2D.Double r, double h, double v)Resizes theRectangle2D.Doubleboth horizontally and vertically.static java.awt.geom.Point2D.Doubleintersect(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd)Standard line intersection algorithm Return the point of intersection if it exists, else nullstatic java.awt.geom.Point2D.Doubleintersect(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd, double limit)static java.awt.Pointintersect(int xa, int ya, int xb, int yb, int xc, int yc, int xd, int yd)Standard line intersection algorithm Return the point of intersection if it exists, else null.static doublelength(double x1, double y1, double x2, double y2)Gets the distance between to pointsstatic longlength(int x1, int y1, int x2, int y2)Gets the distance between to pointsstatic doublelength(java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2)Gets the distance between to pointsstatic doublelength2(double x1, double y1, double x2, double y2)Gets the square distance between two points.static longlength2(int x1, int y1, int x2, int y2)Gets the square distance between two points.static booleanlineContainsPoint(double x1, double y1, double x2, double y2, double px, double py, double tolerance)Tests if a point is on a line.static booleanlineContainsPoint(int x1, int y1, int x2, int y2, int px, int py)Tests if a point is on a line.static booleanlineContainsPoint(int x1, int y1, int x2, int y2, int px, int py, double tolerance)Tests if a point is on a line.static java.awt.Pointnorth(java.awt.Rectangle r)static java.awt.geom.Point2D.Doublenorth(java.awt.geom.Rectangle2D.Double r)static intoutcode(java.awt.geom.Rectangle2D.Double r1, java.awt.geom.Rectangle2D.Double r2)This method computes a binary OR of the appropriate mask values indicating, for each side of Rectangle r1, whether or not the Rectangle r2 is on the same side of the edge as the rest of this Rectangle.static intoutcode(java.awt.Rectangle r1, java.awt.Rectangle r2)This method computes a binary OR of the appropriate mask values indicating, for each side of Rectangle r1, whether or not the Rectangle r2 is on the same side of the edge as the rest of this Rectangle.static java.awt.geom.Point2D.DoubleovalAngleToPoint(java.awt.geom.Rectangle2D.Double r, double angle)Gets the point on an oval that corresponds to the given angle.static java.awt.PointovalAngleToPoint(java.awt.Rectangle r, double angle)Gets the point on an oval that corresponds to the given angle.static doublepointToAngle(java.awt.geom.Rectangle2D.Double r, java.awt.geom.Point2D.Double p)Gets the angle of a point relative to a rectangle.static doublepointToAngle(java.awt.Rectangle r, java.awt.Point p)Gets the angle of a point relative to a rectangle.static java.awt.PointpolarToPoint(double angle, double fx, double fy)Converts a polar to a pointstatic java.awt.geom.Point2D.DoublepolarToPoint2D(double angle, double fx, double fy)Converts a polar to a pointstatic doublerange(double min, double max, double value)Constains a value to the given range.static intrange(int min, int max, int value)Constains a value to the given range.static java.awt.Pointsouth(java.awt.Rectangle r)static java.awt.geom.Point2D.Doublesouth(java.awt.geom.Rectangle2D.Double r)static java.awt.Pointwest(java.awt.Rectangle r)static java.awt.geom.Point2D.Doublewest(java.awt.geom.Rectangle2D.Double r)
-
-
-
Field Detail
-
OUT_TOP
public static final int OUT_TOP
The bitmask that indicates that a point lies above the rectangle.- See Also:
- Constant Field Values
-
OUT_BOTTOM
public static final int OUT_BOTTOM
The bitmask that indicates that a point lies below the rectangle.- See Also:
- Constant Field Values
-
OUT_LEFT
public static final int OUT_LEFT
The bitmask that indicates that a point lies to the left of the rectangle.- See Also:
- Constant Field Values
-
OUT_RIGHT
public static final int OUT_RIGHT
The bitmask that indicates that a point lies to the right of the rectangle.- See Also:
- Constant Field Values
-
-
Method Detail
-
lineContainsPoint
public static boolean lineContainsPoint(int x1, int y1, int x2, int y2, int px, int py)Tests if a point is on a line.
-
lineContainsPoint
public static boolean lineContainsPoint(int x1, int y1, int x2, int y2, int px, int py, double tolerance)Tests if a point is on a line.changed Werner Randelshofer 2003-11-26
-
lineContainsPoint
public static boolean lineContainsPoint(double x1, double y1, double x2, double y2, double px, double py, double tolerance)Tests if a point is on a line.changed Werner Randelshofer 2003-11-26
-
direction
public static int direction(int x1, int y1, int x2, int y2)Returns the direction OUT_TOP, OUT_BOTTOM, OUT_LEFT, OUT_RIGHT from one point to another one.
-
direction
public static int direction(double x1, double y1, double x2, double y2)Returns the direction OUT_TOP, OUT_BOTTOM, OUT_LEFT, OUT_RIGHT from one point to another one.
-
outcode
public static int outcode(java.awt.Rectangle r1, java.awt.Rectangle r2)This method computes a binary OR of the appropriate mask values indicating, for each side of Rectangle r1, whether or not the Rectangle r2 is on the same side of the edge as the rest of this Rectangle.- Returns:
- the logical OR of all appropriate out codes OUT_RIGHT, OUT_LEFT, OUT_BOTTOM, OUT_TOP.
-
outcode
public static int outcode(java.awt.geom.Rectangle2D.Double r1, java.awt.geom.Rectangle2D.Double r2)This method computes a binary OR of the appropriate mask values indicating, for each side of Rectangle r1, whether or not the Rectangle r2 is on the same side of the edge as the rest of this Rectangle.- Returns:
- the logical OR of all appropriate out codes OUT_RIGHT, OUT_LEFT, OUT_BOTTOM, OUT_TOP.
-
south
public static java.awt.Point south(java.awt.Rectangle r)
-
south
public static java.awt.geom.Point2D.Double south(java.awt.geom.Rectangle2D.Double r)
-
center
public static java.awt.Point center(java.awt.Rectangle r)
-
center
public static java.awt.geom.Point2D.Double center(java.awt.geom.Rectangle2D.Double r)
-
chop
public static java.awt.geom.Point2D.Double chop(java.awt.Shape shape, java.awt.geom.Point2D.Double p)Returns a point on the edge of the shape which crosses the line from the center of the shape to the specified point. If no edge crosses of the shape crosses the line, the nearest control point of the shape is returned.
-
west
public static java.awt.Point west(java.awt.Rectangle r)
-
west
public static java.awt.geom.Point2D.Double west(java.awt.geom.Rectangle2D.Double r)
-
east
public static java.awt.Point east(java.awt.Rectangle r)
-
east
public static java.awt.geom.Point2D.Double east(java.awt.geom.Rectangle2D.Double r)
-
north
public static java.awt.Point north(java.awt.Rectangle r)
-
north
public static java.awt.geom.Point2D.Double north(java.awt.geom.Rectangle2D.Double r)
-
range
public static int range(int min, int max, int value)Constains a value to the given range.- Returns:
- the constrained value
-
range
public static double range(double min, double max, double value)Constains a value to the given range.- Returns:
- the constrained value
-
length2
public static long length2(int x1, int y1, int x2, int y2)Gets the square distance between two points.
-
length
public static long length(int x1, int y1, int x2, int y2)Gets the distance between to points
-
length2
public static double length2(double x1, double y1, double x2, double y2)Gets the square distance between two points.
-
length
public static double length(double x1, double y1, double x2, double y2)Gets the distance between to points
-
length
public static double length(java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2)Gets the distance between to points
-
cap
public static java.awt.geom.Point2D.Double cap(java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2, double radius)Caps the line defined by p1 and p2 by the number of units specified by radius.- Returns:
- A new end point for the line.
-
pointToAngle
public static double pointToAngle(java.awt.Rectangle r, java.awt.Point p)Gets the angle of a point relative to a rectangle.
-
pointToAngle
public static double pointToAngle(java.awt.geom.Rectangle2D.Double r, java.awt.geom.Point2D.Double p)Gets the angle of a point relative to a rectangle.
-
angle
public static double angle(double x1, double y1, double x2, double y2)Gets the angle of the specified line.
-
angleToPoint
public static java.awt.Point angleToPoint(java.awt.Rectangle r, double angle)Gets the point on a rectangle that corresponds to the given angle.
-
angleToPoint
public static java.awt.geom.Point2D.Double angleToPoint(java.awt.geom.Rectangle2D.Double r, double angle)Gets the point on a rectangle that corresponds to the given angle.
-
polarToPoint
public static java.awt.Point polarToPoint(double angle, double fx, double fy)Converts a polar to a point
-
polarToPoint2D
public static java.awt.geom.Point2D.Double polarToPoint2D(double angle, double fx, double fy)Converts a polar to a point
-
ovalAngleToPoint
public static java.awt.Point ovalAngleToPoint(java.awt.Rectangle r, double angle)Gets the point on an oval that corresponds to the given angle.
-
ovalAngleToPoint
public static java.awt.geom.Point2D.Double ovalAngleToPoint(java.awt.geom.Rectangle2D.Double r, double angle)Gets the point on an oval that corresponds to the given angle.
-
intersect
@Nullable public static java.awt.Point intersect(int xa, int ya, int xb, int yb, int xc, int yc, int xd, int yd)
Standard line intersection algorithm Return the point of intersection if it exists, else null.
-
intersect
@Nullable public static java.awt.geom.Point2D.Double intersect(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd)
Standard line intersection algorithm Return the point of intersection if it exists, else null
-
intersect
@Nullable public static java.awt.geom.Point2D.Double intersect(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd, double limit)
-
distanceFromLine
public static double distanceFromLine(int xa, int ya, int xb, int yb, int xc, int yc)compute distance of point from line segment, or Double.MAX_VALUE if perpendicular projection is outside segment; or If pts on line are same, return distance from point
-
grow
public static void grow(java.awt.geom.Rectangle2D.Double r, double h, double v)Resizes theRectangle2D.Doubleboth horizontally and vertically.This method modifies the
Rectangle2D.Doubleso that it ishunits larger on both the left and right side, andvunits larger at both the top and bottom.The new
Rectangle2D.Doublehas (x - h,y - v) as its top-left corner, a width ofwidth+2h, and a height ofheight+2v.If negative values are supplied for
handv, the size of theRectangle2D.Doubledecreases accordingly. Thegrowmethod does not check whether the resulting values ofwidthandheightare non-negative.- Parameters:
h- the horizontal expansionv- the vertical expansion
-
contains
public static boolean contains(java.awt.geom.Rectangle2D.Double r1, java.awt.geom.Rectangle2D.Double r2)Returns true, if rectangle 1 contains rectangle 2.This method is similar to Rectangle2D.contains, but also returns true, when rectangle1 contains rectangle2 and either or both of them are empty.
- Parameters:
r1- Rectangle 1.r2- Rectangle 2.- Returns:
- true if r1 contains r2.
-
contains
public static boolean contains(java.awt.geom.Rectangle2D r1, java.awt.geom.Rectangle2D r2)Returns true, if rectangle 1 contains rectangle 2.This method is similar to Rectangle2D.contains, but also returns true, when rectangle1 contains rectangle2 and either or both of them are empty.
- Parameters:
r1- Rectangle 1.r2- Rectangle 2.- Returns:
- true if r1 contains r2.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG