Top Description Inners Fields Constructors Methods
com.sun.javafx.sg.prism

pack-priv Class ShapeEvaluator

extends Object
Class Inheritance
Imports
java.util.Vector, com.sun.javafx.geom.FlatteningPathIterator, .IllegalPathStateException, .Path2D, .PathIterator, .Point2D, .RectBounds, .Rectangle, .Shape, com.sun.javafx.geom.transform.BaseTransform

A KeyFrame Evaluator for Shape objects. This Evaluator can be used to morph between the geometries of two relatively arbitrary shapes with the only restrictions being that the two different numbers of subpaths or two shapes with disparate winding rules may not blend together in a pleasing manner. The ShapeEvaluator will do the best job it can if the shapes do not match in winding rule or number of subpaths, but the geometry of the shapes may need to be adjusted by other means to make the shapes more like each other for best aesthetic effect.

Note that the process of comparing two geometries and finding similar structures between them to blend for the morphing operation can be expensive. Instances of ShapeEvaluator will properly perform the necessary geometric analysis of their arguments on every method call and attempt to cache the information so that they can operate more quickly if called multiple times in a row on the same pair of Shape objects. As a result attempting to mutate a Shape object that is stored in one of their keyframes may not have any effect if the associated ShapeEvaluator has already cached the geometry. Also, it is advisable to use different instances of ShapeEvaluator for every pair of keyframes being morphed so that the cached information can be reused as much as possible.

An example of proper usage:

    SGShape s = ...;
    Shape s0 = ...;
    Shape s1 = ...;
    Shape s2 = ...;
    KeyFrame k0 = KeyFrame.create(0.0f, s0, new ShapeEvaluator());
    KeyFrame k1 = KeyFrame.create(0.6f, s1, new ShapeEvaluator());
    KeyFrame k2 = KeyFrame.create(1.0f, s2, new ShapeEvaluator());
    KeyFrames morphFrames = KeyFrames.create(s, "shape", k0, k1, k2);
    Clip.create(5000, 1, morphFrames).start();

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private ShapeEvaluator.Geometry
private ShapeEvaluator.Geometry
private Shape
private Shape

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Shape
evaluate(Shape v0, Shape v1, float fraction)

private Shape
getShape(float fraction)

private static float
interp(float v0, float v1, float t)

private static float[]
mergeTvals(float[] tvals0, float[] tvals1)

private void
private static int
sortTvals(float[] tvals0, float[] tvals1, float[] newtvals)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

geom0back to summary
private ShapeEvaluator.Geometry geom0
geom1back to summary
private ShapeEvaluator.Geometry geom1
savedv0back to summary
private Shape savedv0
savedv1back to summary
private Shape savedv1

Constructor Detail

ShapeEvaluatorback to summary
pack-priv ShapeEvaluator()

Method Detail

evaluateback to summary
public Shape evaluate(Shape v0, Shape v1, float fraction)
getShapeback to summary
private Shape getShape(float fraction)
interpback to summary
private static float interp(float v0, float v1, float t)
mergeTvalsback to summary
private static float[] mergeTvals(float[] tvals0, float[] tvals1)
recalculateback to summary
private void recalculate(Shape v0, Shape v1)
sortTvalsback to summary
private static int sortTvals(float[] tvals0, float[] tvals1, float[] newtvals)
com.sun.javafx.sg.prism back to summary

private Class ShapeEvaluator.Geometry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv float[]
pack-priv static final float
pack-priv float[]
pack-priv int
pack-priv static final float
pack-priv int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
appendCubicTo(float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, float x1, float y1)

private void
appendLineTo(float x0, float y0, float x1, float y1)

private void
appendQuadTo(float x0, float y0, float ctrlx, float ctrly, float x1, float y1)

public float
getCoord(int i)

public int
public float[]
public int
public void
setTvals(float[] newTvals)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bezierCoordsback to summary
pack-priv float[] bezierCoords
MIN_LENback to summary
pack-priv static final float MIN_LEN
myTvalsback to summary
pack-priv float[] myTvals
numCoordsback to summary
pack-priv int numCoords
THIRDback to summary
pack-priv static final float THIRD
windingruleback to summary
pack-priv int windingrule

Constructor Detail

Geometryback to summary
public Geometry(Shape s)

Method Detail

appendCubicToback to summary
private void appendCubicTo(float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, float x1, float y1)
appendLineToback to summary
private void appendLineTo(float x0, float y0, float x1, float y1)
appendQuadToback to summary
private void appendQuadTo(float x0, float y0, float ctrlx, float ctrly, float x1, float y1)
getCoordback to summary
public float getCoord(int i)
getNumCoordsback to summary
public int getNumCoords()
getTvalsback to summary
public float[] getTvals()
getWindingRuleback to summary
public int getWindingRule()
setTvalsback to summary
public void setTvals(float[] newTvals)
com.sun.javafx.sg.prism back to summary

private Class ShapeEvaluator.Iterator

extends Object
implements PathIterator
Class Inheritance
All Implemented Interfaces
com.sun.javafx.geom.PathIterator

Field Summary

Modifier and TypeField and Description
pack-priv BaseTransform
pack-priv int
pack-priv ShapeEvaluator.Geometry
pack-priv ShapeEvaluator.Geometry
pack-priv float
t

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
currentSegment(float[]
an array that holds the data returned from this method
coords
)

Implements com.sun.javafx.geom.PathIterator.currentSegment.

Returns the coordinates and type of the current path segment in the iteration.

public int
getWindingRule()

Implements com.sun.javafx.geom.PathIterator.getWindingRule.

Returns the winding rule for determining the interior of the path.

public boolean
isDone()

Implements com.sun.javafx.geom.PathIterator.isDone.

Tests if the iteration is complete.

public void
next()

Implements com.sun.javafx.geom.PathIterator.next.

Moves the iterator to the next segment of the path forwards along the primary direction of traversal as long as there are more points in that direction.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

atback to summary
pack-priv BaseTransform at
cindexback to summary
pack-priv int cindex
g0back to summary
pack-priv ShapeEvaluator.Geometry g0
g1back to summary
pack-priv ShapeEvaluator.Geometry g1
tback to summary
pack-priv float t

Constructor Detail

Iteratorback to summary
public Iterator(BaseTransform at, ShapeEvaluator.Geometry g0, ShapeEvaluator.Geometry g1, float t)

Method Detail

currentSegmentback to summary
public int currentSegment(float[] coords)

Implements com.sun.javafx.geom.PathIterator.currentSegment.

Doc from com.sun.javafx.geom.PathIterator.currentSegment.

Returns the coordinates and type of the current path segment in the iteration. The return value is the path-segment type: SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. A float array of length 6 must be passed in and can be used to store the coordinates of the point(s). Each point is stored as a pair of float x,y coordinates. SEG_MOVETO and SEG_LINETO types returns one point, SEG_QUADTO returns two points, SEG_CUBICTO returns 3 points and SEG_CLOSE does not return any points.

Parameters
coords:float[]

an array that holds the data returned from this method

Returns:int

the path-segment type of the current path segment.

Annotations
@Override
getWindingRuleback to summary
public int getWindingRule()

Implements com.sun.javafx.geom.PathIterator.getWindingRule.

Doc from com.sun.javafx.geom.PathIterator.getWindingRule.

Returns the winding rule for determining the interior of the path.

Returns:int

the winding rule.

Annotations
@Override
isDoneback to summary
public boolean isDone()

Implements com.sun.javafx.geom.PathIterator.isDone.

Doc from com.sun.javafx.geom.PathIterator.isDone.

Tests if the iteration is complete.

Returns:boolean

true if all the segments have been read; false otherwise.

Annotations
@Override
nextback to summary
public void next()

Implements com.sun.javafx.geom.PathIterator.next.

Doc from com.sun.javafx.geom.PathIterator.next.

Moves the iterator to the next segment of the path forwards along the primary direction of traversal as long as there are more points in that direction.

Annotations
@Override
com.sun.javafx.sg.prism back to summary

private Class ShapeEvaluator.MorphedShape

extends Shape
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv ShapeEvaluator.Geometry
pack-priv ShapeEvaluator.Geometry
pack-priv float
t

Inherited from com.sun.javafx.geom.Shape:
OUT_BOTTOMOUT_LEFTOUT_RIGHTOUT_TOPRECT_INTERSECTS

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
contains(float
the specified X coordinate to be tested
x
,
float
the specified Y coordinate to be tested
y
)

Implements abstract com.sun.javafx.geom.Shape.contains.

Tests if the specified coordinates are inside the boundary of the Shape.

public boolean
contains(float
the X coordinate of the upper-left corner of the specified rectangular area
x
,
float
the Y coordinate of the upper-left corner of the specified rectangular area
y
,
float
the width of the specified rectangular area
width
,
float
the height of the specified rectangular area
height
)

Implements abstract com.sun.javafx.geom.Shape.contains.

Tests if the interior of the Shape entirely contains the specified rectangular area.

public Shape
copy()

Implements abstract com.sun.javafx.geom.Shape.copy.

Returns a new copy of this Shape instance.

public RectBounds
getBounds()

Implements abstract com.sun.javafx.geom.Shape.getBounds.

Note that there is no guarantee that the returned RectBounds is the smallest bounding box that encloses the Shape, only that the Shape lies entirely within the indicated RectBounds.

public PathIterator
getPathIterator(BaseTransform
an optional BaseTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired
at
)

Implements abstract com.sun.javafx.geom.Shape.getPathIterator.

Returns an iterator object that iterates along the Shape boundary and provides access to the geometry of the Shape outline.

public PathIterator
getPathIterator(BaseTransform
an optional BaseTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired
at
,
float
the maximum distance that the line segments used to approximate the curved segments are allowed to deviate from any point on the original curve
flatness
)

Implements abstract com.sun.javafx.geom.Shape.getPathIterator.

Returns an iterator object that iterates along the Shape boundary and provides access to a flattened view of the Shape outline geometry.

public Rectangle
public boolean
intersects(float
the X coordinate of the upper-left corner of the specified rectangular area
x
,
float
the Y coordinate of the upper-left corner of the specified rectangular area
y
,
float
the width of the specified rectangular area
w
,
float
the height of the specified rectangular area
h
)

Implements abstract com.sun.javafx.geom.Shape.intersects.

Tests if the interior of the Shape intersects the interior of a specified rectangular area.

Inherited from com.sun.javafx.geom.Shape:
accumulateaccumulateCubicaccumulateCubicaccumulateQuadcontainscontainsintersectspointCrossingsForCubicpointCrossingsForLinepointCrossingsForPathpointCrossingsForQuadrectCrossingsForCubicrectCrossingsForLinerectCrossingsForPathrectCrossingsForQuad

Field Detail

geom0back to summary
pack-priv ShapeEvaluator.Geometry geom0
geom1back to summary
pack-priv ShapeEvaluator.Geometry geom1
tback to summary
pack-priv float t

Constructor Detail

MorphedShapeback to summary
pack-priv MorphedShape(ShapeEvaluator.Geometry geom0, ShapeEvaluator.Geometry geom1, float t)

Method Detail

containsback to summary
public boolean contains(float x, float y)

Implements abstract com.sun.javafx.geom.Shape.contains.

Doc from com.sun.javafx.geom.Shape.contains.

Tests if the specified coordinates are inside the boundary of the Shape.

Parameters
x:float

the specified X coordinate to be tested

y:float

the specified Y coordinate to be tested

Returns:boolean

true if the specified coordinates are inside the Shape boundary; false otherwise.

Annotations
@Override
containsback to summary
public boolean contains(float x, float y, float width, float height)

Implements abstract com.sun.javafx.geom.Shape.contains.

Doc from com.sun.javafx.geom.Shape.contains.

Tests if the interior of the Shape entirely contains the specified rectangular area. All coordinates that lie inside the rectangular area must lie within the Shape for the entire rectanglar area to be considered contained within the Shape.

The Shape.contains() method allows a Shape implementation to conservatively return false when:

  • the intersect method returns true and
  • the calculations to determine whether or not the Shape entirely contains the rectangular area are prohibitively expensive.
This means that for some Shapes this method might return false even though the Shape contains the rectangular area. The Area class performs more accurate geometric computations than most Shape objects and therefore can be used if a more precise answer is required.
Parameters
x:float

the X coordinate of the upper-left corner of the specified rectangular area

y:float

the Y coordinate of the upper-left corner of the specified rectangular area

width:float

the width of the specified rectangular area

height:float

the height of the specified rectangular area

Returns:boolean

true if the interior of the Shape entirely contains the specified rectangular area; false otherwise or, if the Shape contains the rectangular area and the intersects method returns true and the containment calculations would be too expensive to perform.

Annotations
@Override
copyback to summary
public Shape copy()

Implements abstract com.sun.javafx.geom.Shape.copy.

Doc from com.sun.javafx.geom.Shape.copy.

Returns a new copy of this Shape instance.

Returns:Shape

a copy of this shape

Annotations
@Override
getBoundsback to summary
public RectBounds getBounds()

Implements abstract com.sun.javafx.geom.Shape.getBounds.

Doc from com.sun.javafx.geom.Shape.getBounds.

Note that there is no guarantee that the returned RectBounds is the smallest bounding box that encloses the Shape, only that the Shape lies entirely within the indicated RectBounds.

Returns:RectBounds

an instance of RectBounds

Annotations
@Override
getPathIteratorback to summary
public PathIterator getPathIterator(BaseTransform at)

Implements abstract com.sun.javafx.geom.Shape.getPathIterator.

Doc from com.sun.javafx.geom.Shape.getPathIterator.

Returns an iterator object that iterates along the Shape boundary and provides access to the geometry of the Shape outline. If an optional BaseTransform is specified, the coordinates returned in the iteration are transformed accordingly.

Each call to this method returns a fresh PathIterator object that traverses the geometry of the Shape object independently from any other PathIterator objects in use at the same time.

It is recommended, but not guaranteed, that objects implementing the Shape interface isolate iterations that are in process from any changes that might occur to the original object's geometry during such iterations.

Parameters
at:BaseTransform

an optional BaseTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired

Returns:PathIterator

a new PathIterator object, which independently traverses the geometry of the Shape.

Annotations
@Override
getPathIteratorback to summary
public PathIterator getPathIterator(BaseTransform at, float flatness)

Implements abstract com.sun.javafx.geom.Shape.getPathIterator.

Doc from com.sun.javafx.geom.Shape.getPathIterator.

Returns an iterator object that iterates along the Shape boundary and provides access to a flattened view of the Shape outline geometry.

Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by the iterator.

If an optional BaseTransform is specified, the coordinates returned in the iteration are transformed accordingly.

The amount of subdivision of the curved segments is controlled by the flatness parameter, which specifies the maximum distance that any point on the unflattened transformed curve can deviate from the returned flattened path segments. Note that a limit on the accuracy of the flattened path might be silently imposed, causing very small flattening parameters to be treated as larger values. This limit, if there is one, is defined by the particular implementation that is used.

Each call to this method returns a fresh PathIterator object that traverses the Shape object geometry independently from any other PathIterator objects in use at the same time.

It is recommended, but not guaranteed, that objects implementing the Shape interface isolate iterations that are in process from any changes that might occur to the original object's geometry during such iterations.

Parameters
at:BaseTransform

an optional BaseTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired

flatness:float

the maximum distance that the line segments used to approximate the curved segments are allowed to deviate from any point on the original curve

Returns:PathIterator

a new PathIterator that independently traverses a flattened view of the geometry of the Shape.

Annotations
@Override
getRectangleback to summary
public Rectangle getRectangle()
intersectsback to summary
public boolean intersects(float x, float y, float w, float h)

Implements abstract com.sun.javafx.geom.Shape.intersects.

Doc from com.sun.javafx.geom.Shape.intersects.

Tests if the interior of the Shape intersects the interior of a specified rectangular area. The rectangular area is considered to intersect the Shape if any point is contained in both the interior of the Shape and the specified rectangular area.

The Shape.intersects() method allows a Shape implementation to conservatively return true when:

  • there is a high probability that the rectangular area and the Shape intersect, but
  • the calculations to accurately determine this intersection are prohibitively expensive.
This means that for some Shapes this method might return true even though the rectangular area does not intersect the Shape. The Area class performs more accurate computations of geometric intersection than most Shape objects and therefore can be used if a more precise answer is required.
Parameters
x:float

the X coordinate of the upper-left corner of the specified rectangular area

y:float

the Y coordinate of the upper-left corner of the specified rectangular area

w:float

the width of the specified rectangular area

h:float

the height of the specified rectangular area

Returns:boolean

true if the interior of the Shape and the interior of the rectangular area intersect, or are both highly likely to intersect and intersection calculations would be too expensive to perform; false otherwise.

Annotations
@Override