Class Bezier
After creating each Bézier curve, this class performs a quality control using 2 additional points located at one quarter (t≈¼) and three quarters (t≈¾) of the curve. If the distance between given points and a close point on the curve is greater than εx and εy thresholds, then the curve is divided in two smaller curves and the process is repeated until curves meet the quality controls.
If a quadratic curve degenerates to a cubic curve or a straight line, ignoring errors up to εx
and εy, then CubicCurve2D are replaced by QuadCurve2D or Line2D.
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Martin Desruisseaux (Geomatys)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe number of times a curve has been divided in smaller curves.protected doubleComponents of α=(∂y/∂x) derivative at the point evaluated byevaluateAt(double).protected doubleComponents of α=(∂y/∂x) derivative at the point evaluated byevaluateAt(double).protected booleanWhether to force the creation ofQuadCurve2D.protected final double[]A buffer used by subclasses for storing results ofevaluateAt(double).protected doubleMaximal distance (approximate) on x and y axis between Bézier curves and desired curve.protected doubleMaximal distance (approximate) on x and y axis between Bézier curves and desired curve. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Path2Dbuild()Creates a sequence of Bézier curves from the position given byevaluateAt(0)to the position given byevaluateAt(1).protected abstract voidevaluateAt(double t) Invoked for computing a new point on the Bézier curve.
-
Field Details
-
εx
protected double εxMaximal distance (approximate) on x and y axis between Bézier curves and desired curve. Also used for deciding if a cubic Bézier curve can be simplified to quadratic curve or straight line. Initial value is zero. Subclasses should set the values either in their constructor or atevaluateAt(double)method call. Can be set to infinity or NaN for disabling the quality checks, or to negative value for forcing unconditional divisions of Bézier curves in two sub-curves. -
εy
protected double εyMaximal distance (approximate) on x and y axis between Bézier curves and desired curve. Also used for deciding if a cubic Bézier curve can be simplified to quadratic curve or straight line. Initial value is zero. Subclasses should set the values either in their constructor or atevaluateAt(double)method call. Can be set to infinity or NaN for disabling the quality checks, or to negative value for forcing unconditional divisions of Bézier curves in two sub-curves. -
dx
protected double dxComponents of α=(∂y/∂x) derivative at the point evaluated byevaluateAt(double). -
dy
protected double dyComponents of α=(∂y/∂x) derivative at the point evaluated byevaluateAt(double). -
point
protected final double[] pointA buffer used by subclasses for storing results ofevaluateAt(double). The two first elements are x and y coordinates respectively. Other elements (if any) are ignored. -
depth
protected int depthThe number of times a curve has been divided in smaller curves.- See Also:
-
forceCubic
protected boolean forceCubicWhether to force the creation ofQuadCurve2D. The default value isfalse, which allows simplification toCubicCurve2DorLine2D. This flag can be set totruewhen building circular shapes, in which case simplifications toCubicCurve2Dproduce bad results.
-
-
Constructor Details
-
Bezier
protected Bezier(int dimension) Creates a new builder.- Parameters:
dimension- length of thepointarray. Must be at least 2.
-
-
Method Details
-
evaluateAt
protected abstract void evaluateAt(double t) throws org.opengis.referencing.operation.TransformException Invoked for computing a new point on the Bézier curve. This method is invoked with a t value varying from 0 to 1 inclusive. Value 0 is for the starting point and value 1 is for the ending point. Other values are for points interpolated between the start and end points. In particular value ½ is for the point in the middle of the curve. This method will also be invoked at least for values ¼ and ¾, and potentially for other values too.This method shall store the point coordinates in the
pointarray with x coordinate in the first element and y coordinate in the second element. This method shall also store derivative (∂y/∂x) at that location in thedxanddyfields. If this method cannot compute a coordinate, it can storeDouble.NaNvalues except for t=0, ½ and 1 where finite coordinates are mandatory.Subclasses can optionally update the
εxandεyvalues if the tolerance thresholds change as a result of this method call, for example because we come closer to a pole. The tolerance values used for each Bézier curve are the ones computed at t=¼ and t=¾ of that curve.- Parameters:
t- desired point on the curve, from 0 (start point) to 1 (end point) inclusive.- Throws:
org.opengis.referencing.operation.TransformException- if the point coordinates cannot be computed.
-
build
Creates a sequence of Bézier curves from the position given byevaluateAt(0)to the position given byevaluateAt(1). This method determines the number of intermediate points required for achieving the precision requested by theεxandεyparameters given at construction time.- Returns:
- the sequence of Bézier curves.
- Throws:
org.opengis.referencing.operation.TransformException- if the coordinates of a point cannot be computed.
-