com.caffeineowl.graphics.bezier.flatnessalgos
Class LineDefectFlatnessAlgo

java.lang.Object
  extended by com.caffeineowl.graphics.bezier.flatnessalgos.LineDefectFlatnessAlgo
All Implemented Interfaces:
CubicFlatnessAlgorithm, QuadFlatnessAlgorithm
Direct Known Subclasses:
LineDefectSubdivCriterion

public class LineDefectFlatnessAlgo
extends java.lang.Object
implements CubicFlatnessAlgorithm, QuadFlatnessAlgorithm

The algorithm computes the defected as the distance between the actual location control point(s) and the location of the control point(s) of a totally degenerated Bezier segment:

Note that, while this algorithm is the least computational intensive, it applies the most strict flatness criterion: the Bezier segment needs to be close to the total degeneration to offer a good flatness.

Author:
Adrian Colomitchi (acolomitchi(monkey_tail)gmail.com)

Field Summary
static int CBSV_DIST
          Use the Chebyshev (chess-board) distance to compute the distance between two points
protected  int distType
          The distance to use in computing the flatness.
static int EUCL_DIST
          Use the Euclidian norm to compute the distance between two points
static int MNHT_DIST
          Use the Manhattan (taxi-cab) distance to compute the distance between two points
protected  boolean usingSum
          Relevant only if this flatness algo is applied for the cubic: when true, the flatness is returned as the sum of the distances between the control points and their ideal position of the degenerate cubic.
 
Constructor Summary
LineDefectFlatnessAlgo()
          Defaults to LineDefectFlatnessAlgo(int, boolean), with a EUCL_DIST for the distance type and using the sum for the case of cubics.
LineDefectFlatnessAlgo(boolean useSumation)
          Defaults to LineDefectFlatnessAlgo(int, boolean), with a EUCL_DIST for the distance type and using the specified behaviour for the use of sum/max when computing the flatness for cubics.
LineDefectFlatnessAlgo(int distType)
          Defaults to LineDefectFlatnessAlgo(int, boolean), with the specified distance type and using the sum for the case of cubics.
LineDefectFlatnessAlgo(int distType, boolean useSum)
          Initialised this instance with the specified distance type and summation behaviour.
 
Method Summary
 double getFlatness(java.awt.geom.CubicCurve2D curve)
          Computes the flatness of the cubic using the distance type and sum/max strategy used in initialisation.
 double getFlatness(java.awt.geom.QuadCurve2D curve)
          Computes the flatness of the quad curve using the distance type and sum/max strategy used in initialisation.
 double getSquaredFlatness(java.awt.geom.CubicCurve2D curve)
          Computes the squared flatness of the cubic using the distance type and sum/max strategy used in initialisation.
 double getSquaredFlatness(java.awt.geom.QuadCurve2D curve)
          Computes the squared flatness of the quad curve using the distance type and sum/max strategy used in initialisation.
 boolean isDegenerationRobust()
          Yes, works fine for degenerated curves (curves on which the control point(s) are on the line defined by its anchors).
 boolean isSquaredFlatenessPreferred()
          Returns true if the distance type is EUCL_DIST (since computing the squared distance is less computational expensive than computing the distance), false if the distance type is MNHT_DIST or CBSV_DIST (for those two, computing the distance is less computational expensive than computing the squared distance}.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EUCL_DIST

public static final int EUCL_DIST
Use the Euclidian norm to compute the distance between two points

See Also:
Constant Field Values

MNHT_DIST

public static final int MNHT_DIST
Use the Manhattan (taxi-cab) distance to compute the distance between two points

See Also:
Constant Field Values

CBSV_DIST

public static final int CBSV_DIST
Use the Chebyshev (chess-board) distance to compute the distance between two points

See Also:
Constant Field Values

distType

protected int distType
The distance to use in computing the flatness. Must be one of EUCL_DIST, MNHT_DIST or CBSV_DIST.


usingSum

protected boolean usingSum
Relevant only if this flatness algo is applied for the cubic: when true, the flatness is returned as the sum of the distances between the control points and their ideal position of the degenerate cubic. If false, the maximum of the two is returned as the flatness.

Constructor Detail

LineDefectFlatnessAlgo

public LineDefectFlatnessAlgo()
Defaults to LineDefectFlatnessAlgo(int, boolean), with a EUCL_DIST for the distance type and using the sum for the case of cubics.


LineDefectFlatnessAlgo

public LineDefectFlatnessAlgo(int distType)
Defaults to LineDefectFlatnessAlgo(int, boolean), with the specified distance type and using the sum for the case of cubics.


LineDefectFlatnessAlgo

public LineDefectFlatnessAlgo(boolean useSumation)
Defaults to LineDefectFlatnessAlgo(int, boolean), with a EUCL_DIST for the distance type and using the specified behaviour for the use of sum/max when computing the flatness for cubics.


LineDefectFlatnessAlgo

public LineDefectFlatnessAlgo(int distType,
                              boolean useSum)
Initialised this instance with the specified distance type and summation behaviour.

Parameters:
distType - the distance type. Must be one of EUCL_DIST, MNHT_DIST or CBSV_DIST. If it is not, the EUCL_DIST will be used.
useSum - sum-or-max strategy to be used when computing the flatness of a cubic.
Method Detail

isDegenerationRobust

public final boolean isDegenerationRobust()
Yes, works fine for degenerated curves (curves on which the control point(s) are on the line defined by its anchors).

Specified by:
isDegenerationRobust in interface CubicFlatnessAlgorithm
Specified by:
isDegenerationRobust in interface QuadFlatnessAlgorithm

isSquaredFlatenessPreferred

public final boolean isSquaredFlatenessPreferred()
Returns true if the distance type is EUCL_DIST (since computing the squared distance is less computational expensive than computing the distance), false if the distance type is MNHT_DIST or CBSV_DIST (for those two, computing the distance is less computational expensive than computing the squared distance}.

Specified by:
isSquaredFlatenessPreferred in interface CubicFlatnessAlgorithm
Specified by:
isSquaredFlatenessPreferred in interface QuadFlatnessAlgorithm

getFlatness

public final double getFlatness(java.awt.geom.CubicCurve2D curve)
Computes the flatness of the cubic using the distance type and sum/max strategy used in initialisation. The flatness (actually the defect of the flatness - the higher, the worse) is computed based on the distance between the control points of the provided curve and the "ideal" positions (at 1/3 and 2/3 on the segment defined by the control points).

Specified by:
getFlatness in interface CubicFlatnessAlgorithm

getSquaredFlatness

public final double getSquaredFlatness(java.awt.geom.CubicCurve2D curve)
Computes the squared flatness of the cubic using the distance type and sum/max strategy used in initialisation. The flatness (actually the defect of the flatness - the higher, the worse) is computed based on the distance between the control points of the provided curve and the "ideal" positions (at 1/3 and 2/3 on the segment defined by the control points).

Specified by:
getSquaredFlatness in interface CubicFlatnessAlgorithm

getFlatness

public final double getFlatness(java.awt.geom.QuadCurve2D curve)
Computes the flatness of the quad curve using the distance type and sum/max strategy used in initialisation. The flatness (actually the defect of the flatness - the higher, the worse) is computed based on the distance between the control point of the provided curve and the "ideal" position (the mid point on the segment defined by the control points).

Specified by:
getFlatness in interface QuadFlatnessAlgorithm

getSquaredFlatness

public final double getSquaredFlatness(java.awt.geom.QuadCurve2D curve)
Computes the squared flatness of the quad curve using the distance type and sum/max strategy used in initialisation. The flatness (actually the defect of the flatness - the higher, the worse) is computed based on the distance between the control point of the provided curve and the "ideal" position (the mid point on the segment defined by the control points).

Specified by:
getSquaredFlatness in interface QuadFlatnessAlgorithm