Class DrawingUtilities
java.lang.Object
com.inductiveautomation.ignition.client.util.gui.DrawingUtilities
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic doubleangle(double p1x, double p1y, double p2x, double p2y, double p3x, double p3y) Uses the Math.atan2 to calculate the angle created by the three points, where p1 is the vertex near the angle to be determined.static doubleReturns the angle off horizontal created by the line connecting p1 and p2static doubleUses the Math.atan2 to calculate the angle created by the three points, where p1 is the vertex near the angle to be determined.static Point2DasPercentage(Point2D pt, Rectangle2D container, Point2D rv) static Rectangle2DasPercentage(Rectangle2D rect, Rectangle2D container, Rectangle2D rv) Calculates the position of rect inside container, returning the result as a rectangle where each value is a percentage of the container's size.static doublebottom(Rectangle2D rect) static doublebottom(Rectangle2D rect, double dY) Returns the y-position of the bottom side of the rectangle after translating it by dYstatic Point2DcenterPoint(Point2D p1, Point2D p2) Find the center point on the line segment connecting the two pointsstatic Point2DcenterPoint(Rectangle2D rect) static PointcenterPoint(Rectangle rect) static Rectangle2Dcopy(Rectangle2D rect) static doubledist(double x1, double y1, double x2, double y2) Returns the distance between two pointsstatic floatdist(float x1, float y1, float x2, float y2) Returns the distance between two pointsstatic doubleReturns the distance between two pointsstatic doubledistSquared(double x1, double y1, double x2, double y2) static doubledistSquared(Point2D a, Point2D b) static doubleThe dot-product of two vectors.static Colorstatic BufferedImagegetScaledInstance(BufferedImage img, int targetWidth, int targetHeight, Object hint, boolean higherQuality) Convenience method that returns a scaled instance of the providedBufferedImage.static Rectangle2Dinset(Rectangle2D rect, double d) Insets a rectangle by the given amount.static InsetsConverts a rectangle (x,y,w,h) into an insets that represents the coordinates of the rectangles edges (top=y, bottom=y+h, left=x, right=x+h)static Insets2Dinsets2D(Rectangle2D rect, Insets2D insets) static Point2D.Doublelocation(Rectangle2D rect) The location of the rectangle's x,y coords.static voidmakeRelative(Rectangle2D child, Rectangle2D parent) For two rectangles in the same coordinate space, make the child relative to the parent.static voidmoveRect(Rectangle2D rect, double dx, double dy) Moves a rectangle by an offset, like rect.x += dx; rect.y += dy;static booleannear(double value, double nearTo) Detects double proximity within 1 millionth, since double equality is not reliable.static booleannear(double value, double nearTo, double tolerance) Just like the other implementation of near, but with a custom specified tolerance.static booleannear(float value, float nearTo) Detects double proximity within 1 millionth, since float equality is not reliable.static booleannear(float value, float nearTo, float tolerance) Just like the other implementation of near, but with a custom specified tolerance.static booleanReturns whether or not the two points' x and y coords are near each other within the specified tolerance.static booleannear(Rectangle2D r1, Rectangle2D r2, double tolerance) Returns whether or not the rectangle's are near each other within the specified tolerance.static Point2DnearestPointInShape(Shape shape, Point2D pt) Finds the nearest point on or inside the given shape.static Point2DnearestPointOnLine(double ax, double ay, double bx, double by, double px, double py, boolean clampToSegment, Point2D dest) Finds a point on the line that passes through A (ax,ay) and B(bx,by) that is nearest to the point P (px,py).static Point2DnearestPointOnLine(Point2D a, Point2D b, Point2D p) static Point2DnearestPointOnLine(Point2D a, Point2D b, Point2D p, boolean clampToSegment) static Point2DnearestPointOnLine(Point2D a, Point2D b, Point2D p, Point2D dest) static Point2DnearestPointOnLine(Point2D a, Point2D b, Point2D p, Point2D dest, boolean clampToSegment) static Rectangle2Doutset(Rectangle2D rect, double d) static booleanpathsIntersect(Shape path1, Shape path2) Detects if the outlines of two shapes intersect or not.static Point2Dproject(Point2D pcts, Rectangle2D container, Point2D rv) static Rectangle2Dproject(Rectangle2D pcts, Rectangle2D container, Rectangle2D rv) Projects the rectangle of percentages into the container rectangle, storing the results in the rvstatic Rectangle2Drectangle(Insets2D insets, Rectangle2D r) static RectanglePerforms the inverse operation ofinsets(Rectangle, Insets).static booleanrectangleContains(Rectangle2D rectangle, Shape shape) static booleanrectangleIntersects(Rectangle2D rectangle, Shape shape) static Point2DConsider the line segment p1,p2.static doubleright(Rectangle2D rect) static doubleright(Rectangle2D rect, double dX) Returns the x-position of the right-hand side of the rectangle after translating it by dXstatic voidstatic voidstatic voidRotates the point around the anchor, storing the results by altering the pointstatic voidstatic intround(double d) Shortcut for (int)Math.round(d);static Pointstatic Rectangleround(Rectangle2D rect) static Rectangleround(Rectangle2D rect, Rectangle rv) static DimensionroundSize(Rectangle2D rect) static voidScales a point by a value.static Point2DscaleOnLine(Point2D p1, Point2D p2, double value) Returns a point on the line that joins p1 and p2.static voidsetHeight(Rectangle2D rect, double newHeight) static voidsetLocation(Rectangle2D rect, double x, double y) static voidsetWidth(Rectangle2D rect, double newWidth) static voidsetX(Rectangle2D rect, double newX) static voidsetY(Rectangle2D rect, double newY) simplifyPath(List<Point2D> points, float tolerance) Simplifies a basic poly-line to use fewer pointsstatic GeneralPathsmoothPath(List<Point2D> points, double smoothness) Turns a list of points representing a poly-line into a GeneralPath consisting of bezier curves.static GeneralPathsmoothPath(List<Point2D> points, double smoothness, boolean close) static Point2DsnapPointToAngle(Point2D center, double angle, Point2D desired) Snaps a point to a nearby point that is on a line aligned to a multiple of the given angle from the centerpoint.static Point2DsnapPointToAngle(Point2D center, Point2D horizontalReference, double angle, Point2D desired) Snaps a point to a nearby point that is on a line aligned to a multiple of the given angle from the centerpoint.static doublesq(double d) Square (d^2)static Point2Dstatic BufferedImagetoBufferedImage(Image img) static StringtoString(Rectangle2D rect) static voidUnions two rectangles, storing the result in rv, rather than creating a new rectangle
- 
Field Details- 
THIN_LINE
- 
THICK_LINE
- 
TWOPIpublic static final double TWOPI- See Also:
 
 
- 
- 
Constructor Details- 
DrawingUtilitiespublic DrawingUtilities()
 
- 
- 
Method Details- 
getScaledInstancepublic static BufferedImage getScaledInstance(BufferedImage img, int targetWidth, int targetHeight, Object hint, boolean higherQuality) Convenience method that returns a scaled instance of the providedBufferedImage. Implementation thanks to http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html- Parameters:
- img- the original image to be scaled
- targetWidth- the desired width of the scaled instance, in pixels
- targetHeight- the desired height of the scaled instance, in pixels
- hint- one of the rendering hints that corresponds to- RenderingHints.KEY_INTERPOLATION(e.g.- RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR,- RenderingHints.VALUE_INTERPOLATION_BILINEAR,- RenderingHints.VALUE_INTERPOLATION_BICUBIC)
- higherQuality- if true, this method will use a multi-step scaling technique that provides higher quality than the usual one-step technique (only useful in downscaling cases, where- targetWidthor- targetHeightis smaller than the original dimensions, and generally only when the- BILINEARhint is specified)
- Returns:
- a scaled version of the original BufferedImage
 
- 
toBufferedImage
- 
distReturns the distance between two points
- 
fade
- 
distpublic static double dist(double x1, double y1, double x2, double y2) Returns the distance between two points
- 
distpublic static float dist(float x1, float y1, float x2, float y2) Returns the distance between two points
- 
distSquared
- 
distSquaredpublic static double distSquared(double x1, double y1, double x2, double y2) 
- 
nearestPointOnLine
- 
nearestPointOnLine
- 
nearestPointOnLine
- 
nearestPointOnLine
- 
nearestPointInShapeFinds the nearest point on or inside the given shape. If the point is already in the shape, this simply sets dest to pt. If not, then it uses a flattening path iterator to find the line segment with with the closest point.
- 
nearestPointOnLinepublic static Point2D nearestPointOnLine(double ax, double ay, double bx, double by, double px, double py, boolean clampToSegment, Point2D dest) Finds a point on the line that passes through A (ax,ay) and B(bx,by) that is nearest to the point P (px,py).- Parameters:
- clampToSegment- true if you want the point to be on the segment between points A and B
 
- 
sqpublic static double sq(double d) Square (d^2)
- 
insetInsets a rectangle by the given amount. Alters the given rectangle in-place
- 
outset
- 
right
- 
rightReturns the x-position of the right-hand side of the rectangle after translating it by dX
- 
bottom
- 
bottomReturns the y-position of the bottom side of the rectangle after translating it by dY
- 
centerPoint
- 
centerPoint
- 
centerPointFind the center point on the line segment connecting the two points
- 
angleReturns the angle off horizontal created by the line connecting p1 and p2
- 
angleUses the Math.atan2 to calculate the angle created by the three points, where p1 is the vertex near the angle to be determined.
- 
anglepublic static double angle(double p1x, double p1y, double p2x, double p2y, double p3x, double p3y) Uses the Math.atan2 to calculate the angle created by the three points, where p1 is the vertex near the angle to be determined.
- 
subtract
- 
dotThe dot-product of two vectors.
- 
scaleScales a point by a value. simply multiplies the x and y location by the multiplier.
- 
scaleOnLineReturns a point on the line that joins p1 and p2. If value is 0.0, this will return p1, if value is 1.0, this will return p2.
- 
insetsConverts a rectangle (x,y,w,h) into an insets that represents the coordinates of the rectangles edges (top=y, bottom=y+h, left=x, right=x+h)- Parameters:
- rect- Must not be null.
- insets- May be null, in which case a new Insets wil be instantiated and returned.
 
- 
insets2D
- 
rectanglePerforms the inverse operation ofinsets(Rectangle, Insets). Converts an insets representing rectangle edges into a Rectangle. If the insets has been turned "inside out" (e.g. top > bottom) it will be corrected automatically.
- 
rectangle
- 
copy
- 
makeRelativeFor two rectangles in the same coordinate space, make the child relative to the parent. Like:child.x -= parent.x; child.y -= parent.y; 
- 
setX
- 
setY
- 
setWidth
- 
setHeight
- 
toString
- 
moveRectMoves a rectangle by an offset, like rect.x += dx; rect.y += dy;
- 
locationThe location of the rectangle's x,y coords.
- 
setLocation
- 
pathsIntersectDetects if the outlines of two shapes intersect or not.
- 
rectangleContains
- 
rectangleIntersects
- 
unionUnions two rectangles, storing the result in rv, rather than creating a new rectangle
- 
snapPointToAngleSnaps a point to a nearby point that is on a line aligned to a multiple of the given angle from the centerpoint.
- 
snapPointToAnglepublic static Point2D snapPointToAngle(Point2D center, Point2D horizontalReference, double angle, Point2D desired) Snaps a point to a nearby point that is on a line aligned to a multiple of the given angle from the centerpoint.
- 
nearpublic static boolean near(double value, double nearTo) Detects double proximity within 1 millionth, since double equality is not reliable. Implementation is:Math.abs(nearTo - value) < 0.000001d 
- 
nearpublic static boolean near(double value, double nearTo, double tolerance) Just like the other implementation of near, but with a custom specified tolerance.
- 
nearpublic static boolean near(float value, float nearTo) Detects double proximity within 1 millionth, since float equality is not reliable. Implementation is:Math.abs(nearTo - value) < 0.000001f 
- 
nearpublic static boolean near(float value, float nearTo, float tolerance) Just like the other implementation of near, but with a custom specified tolerance.
- 
nearReturns whether or not the two points' x and y coords are near each other within the specified tolerance.
- 
nearReturns whether or not the rectangle's are near each other within the specified tolerance.
- 
round
- 
round
- 
roundpublic static int round(double d) Shortcut for (int)Math.round(d);
- 
roundSize
- 
round
- 
asPercentageCalculates the position of rect inside container, returning the result as a rectangle where each value is a percentage of the container's size. You can re-create rect by callingproject(Rectangle2D, Rectangle2D, Rectangle)with the return value of this function.- Parameters:
- rect- The rectangle in question
- container- The reference rectangle containing rect
- rv- The return value in which to store the result. May be null.
 
- 
asPercentage
- 
projectProjects the rectangle of percentages into the container rectangle, storing the results in the rv
- 
project
- 
rotate
- 
rotateRotates the point around the anchor, storing the results by altering the point
- 
rotate
- 
rotate
- 
simplifyPathSimplifies a basic poly-line to use fewer points- Parameters:
- points- The list of points that make up the line
- tolerance- The tolerance of how "simple" to make the line. Zero means no simplification. A value in the high tens will simplify quite a bit.
 
- 
reflectConsider the line segment p1,p2. This will return a homothetical point on the reflected segment. A multiplier of 1.0 will return the symmetrical point.
- 
smoothPathTurns a list of points representing a poly-line into a GeneralPath consisting of bezier curves. Thanks to http://www.efg2.com/Lab/Graphics/Jean-YvesQueinecBezierCurves.htm- Parameters:
- smoothness- A double from zero to 1.5. Zero will make straight segments, higher numbers will make a curvier path.
 
- 
smoothPath
 
-