Package net.sf.jaxodraw.util
Class JaxoGeometry
java.lang.Object
net.sf.jaxodraw.util.JaxoGeometry
Utility methods for Java2D geometry.
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
add
(Rectangle2D r, Rectangle2D s) Add 's' to 'r', but respect isEmpty: is 's' is empty, do nothing; if 'r' is empty, 'r' is set to 's'.static void
static double
bezierLength
(Point2D[] p, double error) Returns the approximate length of a Bezier curve.static Point2D
bezierPoint
(Point2D[] p, double u) Returns a point of a Bezier curve at parameter u.static double
bezierSlope
(Point2D[] p, double u) Returns the first derivative of a Bezier curve at parameter u.static void
bezierSplit
(Point2D[] controlPoints, Point2D[] left, Point2D[] right) Splits a Bezier into half and calculates the control points of the two parts.static void
clear
(Rectangle2D r) Clear: Ensure 'r.isEmpty()'.static double
curveParameter
(double u) Checks that a curve parameter value is in range, within errors.static Rectangle
getBounds
(Collection<?> objects) Bounding box of a Collection of Shapes.static void
Increase the Dimension 'd' by the amount given in each direction in 'n'.static void
Increase the Rectangle 'r' by the amount given in each direction in 'n'.static Point2D
scaledPoint
(double orx, double ory, double scale, double px, double py) Returns a point that is obtained from a point (px, py) after a scale transformation scale, keeping the point (orx, ory) fixed.static void
setLocationRelativeToAvoiding
(Window w, Component comp, Rectangle avoidme) Put Window into a nice place - in principle as setLocationRelativeTo(c), but try to avoid covering the given Rectangle.static void
Decrease the Dimension 'd' by the amount given in each direction in 'n'.static void
Decrease the Rectangle 'r' by the amount given in each direction in 'n'.static void
Translate a point.
-
Method Details
-
add
Add 's' to 'r', but respect isEmpty: is 's' is empty, do nothing; if 'r' is empty, 'r' is set to 's'. The rounding behaviour if 'r' and 's' have different precision is undefined.- Parameters:
r
- The first Rectangle.s
- The rectangle to add.- See Also:
-
add
- Parameters:
r
- The first rectangle.x
- The x coordinate of the rectangle to add.y
- The y coordinate of the rectangle to add.width
- The width of the rectangle to add.height
- The height of the rectangle to add.
-
clear
Clear: Ensure 'r.isEmpty()'.- Parameters:
r
- The rectangle to clear.- See Also:
-
grow
Increase the Rectangle 'r' by the amount given in each direction in 'n'.- Parameters:
r
- The rectangle to grow.n
- The insets to add.
-
shrink
Decrease the Rectangle 'r' by the amount given in each direction in 'n'. Currently does not handle underflow - so 'r' may have negative width/height afterwards.- Parameters:
r
- The rectangle to shrink.n
- The insets to subtract.
-
grow
Increase the Dimension 'd' by the amount given in each direction in 'n'.- Parameters:
d
- The dimension to grow.n
- The insets to add.
-
shrink
Decrease the Dimension 'd' by the amount given in each direction in 'n'. Currently does not handle underflow - so 'd' may have negative width/height afterwards.- Parameters:
d
- The dimension to shrink.n
- The insets to subtract.
-
getBounds
Bounding box of a Collection of Shapes. Returns the union of all the object's bounding boxess.- Parameters:
objects
- A collection of objects, only Shapes contribute to the result.- Returns:
- A Rectangle containing the union bounding box. Returns null for an empty Collection, or if there are no Shapes.
-
scaledPoint
Returns a point that is obtained from a point (px, py) after a scale transformation scale, keeping the point (orx, ory) fixed.- Parameters:
orx
- The x-coordinate of the fixed point.ory
- The y-coordinate of the fixed point.scale
- The scale factor.px
- The x-coordinate of the point to be transformed.py
- The y-coordinate of the point to be transformed.- Returns:
- A Point2D containing the x- and y-coordinate of the new point.
-
bezierLength
Returns the approximate length of a Bezier curve.- Parameters:
p
- the four control points of the Bezier curve.error
- An absolute value for an error estimate- Returns:
- The length of the Bezier curve.
-
bezierSplit
Splits a Bezier into half and calculates the control points of the two parts.- Parameters:
controlPoints
- the four control points of the Bezier.left
- (output) the four control points of the left half.right
- (output) the four control points of the right half.
-
bezierPoint
Returns a point of a Bezier curve at parameter u.- Parameters:
p
- the four control points of the Bezier curve.u
- the parameter value, needs to be between 0 and 1.- Returns:
- A Point2D.
-
bezierSlope
Returns the first derivative of a Bezier curve at parameter u.- Parameters:
p
- the four control points of the Bezier curve.u
- the parameter value, needs to be between 0 and 1.- Returns:
- the slope (in radians) at t.
-
curveParameter
public static double curveParameter(double u) Checks that a curve parameter value is in range, within errors.- Parameters:
u
- the parameter value, needs to be between 0 and 1.- Returns:
- a parameter that is strictly between 0 and 1.
-
translate
Translate a point.- Parameters:
p
- the point to move.dx
- the translation in x direction.dy
- the translation in y direction.
-
setLocationRelativeToAvoiding
Put Window into a nice place - in principle as setLocationRelativeTo(c), but try to avoid covering the given Rectangle.- Parameters:
w
- The window to set.comp
- A compponent.avoidme
- The region to avoid.
-