public abstract class Shape extends Object
Shape
class provides definitions for objects
that represent some form of geometric shape. The Shape
is described by a PathIterator
object, which can express the
outline of the Shape
as well as a rule for determining
how the outline divides the 2D plane into interior and exterior
points. Each Shape
object provides callbacks to get the
bounding box of the geometry, determine whether points or
rectangles lie partly or entirely within the interior
of the Shape
, and retrieve a PathIterator
object that describes the trajectory path of the Shape
outline.
Definition of insideness:
A point is considered to lie inside a
Shape
if and only if:
Shape
boundary or
Shape
boundary and the
space immediately adjacent to the
point in the increasing X
direction is
entirely inside the boundary or
Y
direction is inside the boundary.
The contains
and intersects
methods
consider the interior of a Shape
to be the area it
encloses as if it were filled. This means that these methods
consider
unclosed shapes to be implicitly closed for the purpose of
determining if a shape contains or intersects a rectangle or if a
shape contains a point.
PathIterator
,
BaseTransform
,
FlatteningPathIterator
,
Path2D
Modifier and Type | Field and Description |
---|---|
static int |
OUT_BOTTOM
The bitmask that indicates that a point lies below
this
Rectangle2D . |
static int |
OUT_LEFT
The bitmask that indicates that a point lies to the left of
this
Rectangle2D . |
static int |
OUT_RIGHT
The bitmask that indicates that a point lies to the right of
this
Rectangle2D . |
static int |
OUT_TOP
The bitmask that indicates that a point lies above
this
Rectangle2D . |
static int |
RECT_INTERSECTS
The rectangle intersection test counts the number of times
that the path crosses through the shadow that the rectangle
projects to the right towards (x => +INFINITY).
|
Constructor and Description |
---|
Shape() |
Modifier and Type | Method and Description |
---|---|
static void |
accumulate(float[] bbox,
Shape s,
BaseTransform tx) |
static void |
accumulateCubic(float[] bbox,
int off,
float v0,
float vc0,
float vc1,
float v1) |
static void |
accumulateCubic(float[] bbox,
int off,
float t,
float v0,
float vc0,
float vc1,
float v1) |
static void |
accumulateQuad(float[] bbox,
int off,
float v0,
float vc,
float v1) |
abstract boolean |
contains(float x,
float y)
Tests if the specified coordinates are inside the boundary of the
Shape . |
abstract boolean |
contains(float x,
float y,
float w,
float h)
Tests if the interior of the
Shape entirely contains
the specified rectangular area. |
boolean |
contains(Point2D p)
Tests if a specified
Point2D is inside the boundary
of the Shape . |
boolean |
contains(RectBounds r)
Tests if the interior of the
Shape entirely contains the
specified RectBounds . |
abstract Shape |
copy()
Returns a new copy of this
Shape instance. |
abstract RectBounds |
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 . |
abstract PathIterator |
getPathIterator(BaseTransform tx)
Returns an iterator object that iterates along the
Shape boundary and provides access to the geometry of the
Shape outline. |
abstract PathIterator |
getPathIterator(BaseTransform tx,
float flatness)
Returns an iterator object that iterates along the
Shape
boundary and provides access to a flattened view of the
Shape outline geometry. |
abstract boolean |
intersects(float x,
float y,
float w,
float h)
Tests if the interior of the
Shape intersects the
interior of a specified rectangular area. |
boolean |
intersects(RectBounds r)
Tests if the interior of the
Shape intersects the
interior of a specified rectangular area. |
static int |
pointCrossingsForCubic(float px,
float py,
float x0,
float y0,
float xc0,
float yc0,
float xc1,
float yc1,
float x1,
float y1,
int level)
Calculates the number of times the cubic from (x0,y0) to (x1,y1)
crosses the ray extending to the right from (px,py).
|
static int |
pointCrossingsForLine(float px,
float py,
float x0,
float y0,
float x1,
float y1)
Calculates the number of times the line from (x0,y0) to (x1,y1)
crosses the ray extending to the right from (px,py).
|
static int |
pointCrossingsForPath(PathIterator pi,
float px,
float py)
Calculates the number of times the given path
crosses the ray extending to the right from (px,py).
|
static int |
pointCrossingsForQuad(float px,
float py,
float x0,
float y0,
float xc,
float yc,
float x1,
float y1,
int level)
Calculates the number of times the quad from (x0,y0) to (x1,y1)
crosses the ray extending to the right from (px,py).
|
static int |
rectCrossingsForCubic(int crossings,
float rxmin,
float rymin,
float rxmax,
float rymax,
float x0,
float y0,
float xc0,
float yc0,
float xc1,
float yc1,
float x1,
float y1,
int level)
Accumulate the number of times the cubic crosses the shadow
extending to the right of the rectangle.
|
static int |
rectCrossingsForLine(int crossings,
float rxmin,
float rymin,
float rxmax,
float rymax,
float x0,
float y0,
float x1,
float y1)
Accumulate the number of times the line crosses the shadow
extending to the right of the rectangle.
|
static int |
rectCrossingsForPath(PathIterator pi,
float rxmin,
float rymin,
float rxmax,
float rymax)
Accumulate the number of times the path crosses the shadow
extending to the right of the rectangle.
|
static int |
rectCrossingsForQuad(int crossings,
float rxmin,
float rymin,
float rxmax,
float rymax,
float x0,
float y0,
float xc,
float yc,
float x1,
float y1,
int level)
Accumulate the number of times the quad crosses the shadow
extending to the right of the rectangle.
|
public static final int RECT_INTERSECTS
public static final int OUT_LEFT
Rectangle2D
.public static final int OUT_TOP
Rectangle2D
.public static final int OUT_RIGHT
Rectangle2D
.public static final int OUT_BOTTOM
Rectangle2D
.public abstract RectBounds getBounds()
RectBounds
is the smallest bounding box that encloses
the Shape
, only that the Shape
lies
entirely within the indicated RectBounds
.RectBounds
public abstract boolean contains(float x, float y)
Shape
.x
- the specified X coordinate to be testedy
- the specified Y coordinate to be testedtrue
if the specified coordinates are inside
the Shape
boundary; false
otherwise.public boolean contains(Point2D p)
Point2D
is inside the boundary
of the Shape
.p
- the specified Point2D
to be testedtrue
if the specified Point2D
is
inside the boundary of the Shape
;
false
otherwise.public abstract boolean intersects(float x, float y, float w, float h)
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:
Shape
intersect, but
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.x
- the X coordinate of the upper-left corner
of the specified rectangular areay
- the Y coordinate of the upper-left corner
of the specified rectangular areaw
- the width of the specified rectangular areah
- the height of the specified rectangular areatrue
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.public boolean intersects(RectBounds r)
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:
Shape
intersect, but
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.x
- the X coordinate of the upper-left corner
of the specified rectangular areay
- the Y coordinate of the upper-left corner
of the specified rectangular areaw
- the width of the specified rectangular areah
- the height of the specified rectangular areatrue
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.public abstract boolean contains(float x, float y, float w, float h)
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:
intersect
method returns true
and
Shape
entirely contains the rectangular area are
prohibitively expensive.
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.x
- the X coordinate of the upper-left corner
of the specified rectangular areay
- the Y coordinate of the upper-left corner
of the specified rectangular areaw
- the width of the specified rectangular areah
- the height of the specified rectangular areatrue
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.intersects(float, float, float, float)
public boolean contains(RectBounds r)
Shape
entirely contains the
specified RectBounds
.
The Shape.contains()
method allows a Shape
implementation to conservatively return false
when:
intersect
method returns true
and
Shape
entirely contains the RectBounds
are prohibitively expensive.
Shapes
this method might
return false
even though the Shape
contains
the RectBounds
.
The Area
class performs
more accurate geometric computations than most
Shape
objects and therefore can be used if a more precise
answer is required.r
- The specified RectBounds
true
if the interior of the Shape
entirely contains the RectBounds
;
false
otherwise or, if the Shape
contains the RectBounds
and the
intersects
method returns true
and the containment calculations would be too expensive to
perform.contains(float, float, float, float)
public abstract PathIterator getPathIterator(BaseTransform tx)
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.
tx
- an optional BaseTransform
to be applied to the
coordinates as they are returned in the iteration, or
null
if untransformed coordinates are desiredPathIterator
object, which independently
traverses the geometry of the Shape
.public abstract PathIterator getPathIterator(BaseTransform tx, float flatness)
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.
tx
- an optional BaseTransform
to be applied to the
coordinates as they are returned in the iteration, or
null
if untransformed coordinates are desiredflatness
- the maximum distance that the line segments used to
approximate the curved segments are allowed to deviate
from any point on the original curvePathIterator
that independently traverses
a flattened view of the geometry of the Shape
.public abstract Shape copy()
Shape
instance.public static int pointCrossingsForPath(PathIterator pi, float px, float py)
public static int pointCrossingsForLine(float px, float py, float x0, float y0, float x1, float y1)
public static int pointCrossingsForQuad(float px, float py, float x0, float y0, float xc, float yc, float x1, float y1, int level)
public static int pointCrossingsForCubic(float px, float py, float x0, float y0, float xc0, float yc0, float xc1, float yc1, float x1, float y1, int level)
public static int rectCrossingsForPath(PathIterator pi, float rxmin, float rymin, float rxmax, float rymax)
public static int rectCrossingsForLine(int crossings, float rxmin, float rymin, float rxmax, float rymax, float x0, float y0, float x1, float y1)
public static int rectCrossingsForQuad(int crossings, float rxmin, float rymin, float rxmax, float rymax, float x0, float y0, float xc, float yc, float x1, float y1, int level)
public static int rectCrossingsForCubic(int crossings, float rxmin, float rymin, float rxmax, float rymax, float x0, float y0, float xc0, float yc0, float xc1, float yc1, float x1, float y1, int level)
public static void accumulate(float[] bbox, Shape s, BaseTransform tx)
public static void accumulateQuad(float[] bbox, int off, float v0, float vc, float v1)
public static void accumulateCubic(float[] bbox, int off, float v0, float vc0, float vc1, float v1)
public static void accumulateCubic(float[] bbox, int off, float t, float v0, float vc0, float vc1, float v1)
Copyright © 2020. All rights reserved.