|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object prefuse.util.GraphicsLib
public class GraphicsLib
Library of useful computer graphics routines such as geometry routines for computing the intersection of different shapes and rendering methods for computing bounds and performing optimized drawing.
Field Summary | |
---|---|
static int |
COINCIDENT
Indicates intersection between shapes |
static int |
NO_INTERSECTION
Indicates no intersection between shapes |
static int |
PARALLEL
Indicates two lines are parallel |
Constructor Summary | |
---|---|
GraphicsLib()
|
Method Summary | |
---|---|
static java.awt.geom.GeneralPath |
cardinalSpline(float[] pts,
float slack,
boolean closed)
Compute a cardinal spline, a series of cubic Bezier splines smoothly connecting a set of points. |
static java.awt.geom.GeneralPath |
cardinalSpline(float[] pts,
int start,
int npoints,
float slack,
boolean closed)
Compute a cardinal spline, a series of cubic Bezier splines smoothly connecting a set of points. |
static java.awt.geom.GeneralPath |
cardinalSpline(java.awt.geom.GeneralPath p,
float[] pts,
float slack,
boolean closed,
float tx,
float ty)
Compute a cardinal spline, a series of cubic Bezier splines smoothly connecting a set of points. |
static java.awt.geom.GeneralPath |
cardinalSpline(java.awt.geom.GeneralPath p,
float[] pts,
int start,
int npoints,
float slack,
boolean closed,
float tx,
float ty)
Compute a cardinal spline, a series of cubic Bezier splines smoothly connecting a set of points. |
static float[] |
centroid(float[] pts,
int len)
Computes the mean, or centroid, of a set of points |
static double[] |
convexHull(double[] pts,
int len)
Computes the 2D convex hull of a set of points using Graham's scanning algorithm. |
static double[] |
convexHull(double[] pts,
int len,
float[] angles,
int[] idx,
int[] stack)
Computes the 2D convex hull of a set of points using Graham's scanning algorithm. |
static void |
expand(java.awt.geom.Rectangle2D r,
double amount)
Expand a rectangle by the given amount. |
static void |
growPolygon(float[] pts,
int len,
float amt)
Expand a polygon by adding the given distance along the line from the centroid of the polyong. |
static int |
intersectLineLine(double a1x,
double a1y,
double a2x,
double a2y,
double b1x,
double b1y,
double b2x,
double b2y,
java.awt.geom.Point2D intersect)
Compute the intersection of two line segments. |
static int |
intersectLineLine(java.awt.geom.Line2D a,
java.awt.geom.Line2D b,
java.awt.geom.Point2D intersect)
Compute the intersection of two line segments. |
static int |
intersectLineRectangle(java.awt.geom.Line2D l,
java.awt.geom.Rectangle2D r,
java.awt.geom.Point2D[] pts)
Compute the intersection of a line and a rectangle. |
static int |
intersectLineRectangle(java.awt.geom.Point2D a1,
java.awt.geom.Point2D a2,
java.awt.geom.Rectangle2D r,
java.awt.geom.Point2D[] pts)
Compute the intersection of a line and a rectangle. |
static void |
paint(java.awt.Graphics2D g,
VisualItem item,
java.awt.Shape shape,
java.awt.BasicStroke stroke,
int type)
Render a shape associated with a VisualItem into a graphics context. |
static void |
setBounds(VisualItem item,
java.awt.Shape shape,
java.awt.BasicStroke stroke)
Sets a VisualItem's bounds based on its shape and stroke type. |
static java.awt.geom.GeneralPath |
stackSpline(java.awt.geom.GeneralPath p,
float[] pts,
float epsilon,
float slack,
boolean closed,
float tx,
float ty)
Computes a set of curves using the cardinal spline approach, but using straight lines for completely horizontal or vertical segments. |
static java.awt.geom.GeneralPath |
stackSpline(java.awt.geom.GeneralPath p,
float[] pts,
int start,
int npoints,
float epsilon,
float slack,
boolean closed,
float tx,
float ty)
Computes a set of curves using the cardinal spline approach, but using straight lines for completely horizontal or vertical segments. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NO_INTERSECTION
public static final int COINCIDENT
public static final int PARALLEL
Constructor Detail |
---|
public GraphicsLib()
Method Detail |
---|
public static int intersectLineLine(java.awt.geom.Line2D a, java.awt.geom.Line2D b, java.awt.geom.Point2D intersect)
a
- the first line segmentb
- the second line segmentintersect
- a Point in which to store the intersection point
NO_INTERSECTION
,
COINCIDENT
, or PARALLEL
.public static int intersectLineLine(double a1x, double a1y, double a2x, double a2y, double b1x, double b1y, double b2x, double b2y, java.awt.geom.Point2D intersect)
a1x
- the x-coordinate of the first endpoint of the first linea1y
- the y-coordinate of the first endpoint of the first linea2x
- the x-coordinate of the second endpoint of the first linea2y
- the y-coordinate of the second endpoint of the first lineb1x
- the x-coordinate of the first endpoint of the second lineb1y
- the y-coordinate of the first endpoint of the second lineb2x
- the x-coordinate of the second endpoint of the second lineb2y
- the y-coordinate of the second endpoint of the second lineintersect
- a Point in which to store the intersection point
NO_INTERSECTION
,
COINCIDENT
, or PARALLEL
.public static int intersectLineRectangle(java.awt.geom.Point2D a1, java.awt.geom.Point2D a2, java.awt.geom.Rectangle2D r, java.awt.geom.Point2D[] pts)
a1
- the first endpoint of the linea2
- the second endpoint of the liner
- the rectanglepts
- a length 2 or greater array of points in which to store
the results
NO_INTERSECTION
,
COINCIDENT
, or PARALLEL
.public static int intersectLineRectangle(java.awt.geom.Line2D l, java.awt.geom.Rectangle2D r, java.awt.geom.Point2D[] pts)
l
- the liner
- the rectanglepts
- a length 2 or greater array of points in which to store
the results
NO_INTERSECTION
,
COINCIDENT
, or PARALLEL
.public static double[] convexHull(double[] pts, int len)
pts
- the input points in [x0,y0,x1,y1,...] orderlen
- the length of the pts array to consider (2 * #points)
public static double[] convexHull(double[] pts, int len, float[] angles, int[] idx, int[] stack)
pts
-
public static float[] centroid(float[] pts, int len)
pts
- the points array, in x1, y1, x2, y2, ... arrangement.len
- the length of the array to consider
public static void growPolygon(float[] pts, int len, float amt)
pts
- the polygon to expand, a set of points in a float arraylen
- the length of the range of the array to consideramt
- the amount by which to expand the polygon, each point
will be moved this distance along the line from the centroid of the
polygon to the given point.public static java.awt.geom.GeneralPath cardinalSpline(float[] pts, float slack, boolean closed)
pts
- the points to interpolate with a cardinal splineslack
- a parameter controlling the "tightness" of the spline to
the control points, 0.10 is a typically suitable valueclosed
- true if the cardinal spline should be closed (i.e. return
to the starting point), false for an open curve
GeneralPath
instance.public static java.awt.geom.GeneralPath cardinalSpline(float[] pts, int start, int npoints, float slack, boolean closed)
pts
- the points to interpolate with a cardinal splinestart
- the starting index from which to read pointsnpoints
- the number of points to considerslack
- a parameter controlling the "tightness" of the spline to
the control points, 0.10 is a typically suitable valueclosed
- true if the cardinal spline should be closed (i.e. return
to the starting point), false for an open curve
GeneralPath
instance.public static java.awt.geom.GeneralPath cardinalSpline(java.awt.geom.GeneralPath p, float[] pts, float slack, boolean closed, float tx, float ty)
p
- the GeneralPath instance to use to store the resultpts
- the points to interpolate with a cardinal splineslack
- a parameter controlling the "tightness" of the spline to
the control points, 0.10 is a typically suitable valueclosed
- true if the cardinal spline should be closed (i.e. return
to the starting point), false for an open curvetx
- a value by which to translate the curve along the x-dimensionty
- a value by which to translate the curve along the y-dimension
GeneralPath
instance.public static java.awt.geom.GeneralPath cardinalSpline(java.awt.geom.GeneralPath p, float[] pts, int start, int npoints, float slack, boolean closed, float tx, float ty)
p
- the GeneralPath instance to use to store the resultpts
- the points to interpolate with a cardinal splinestart
- the starting index from which to read pointsnpoints
- the number of points to considerslack
- a parameter controlling the "tightness" of the spline to
the control points, 0.10 is a typically suitable valueclosed
- true if the cardinal spline should be closed (i.e. return
to the starting point), false for an open curvetx
- a value by which to translate the curve along the x-dimensionty
- a value by which to translate the curve along the y-dimension
GeneralPath
instance.public static java.awt.geom.GeneralPath stackSpline(java.awt.geom.GeneralPath p, float[] pts, float epsilon, float slack, boolean closed, float tx, float ty)
p
- the GeneralPath instance to use to store the resultpts
- the points to interpolate with the splineepsilon
- threshold value under which to treat the difference
between two values to be zero. Used to determine which segments to
treat as lines rather than curves.slack
- a parameter controlling the "tightness" of the spline to
the control points, 0.10 is a typically suitable valueclosed
- true if the spline should be closed (i.e. return
to the starting point), false for an open curvetx
- a value by which to translate the curve along the x-dimensionty
- a value by which to translate the curve along the y-dimension
GeneralPath
instance.public static java.awt.geom.GeneralPath stackSpline(java.awt.geom.GeneralPath p, float[] pts, int start, int npoints, float epsilon, float slack, boolean closed, float tx, float ty)
p
- the GeneralPath instance to use to store the resultpts
- the points to interpolate with the splinestart
- the starting index from which to read pointsnpoints
- the number of points to considerepsilon
- threshold value under which to treat the difference
between two values to be zero. Used to determine which segments to
treat as lines rather than curves.slack
- a parameter controlling the "tightness" of the spline to
the control points, 0.10 is a typically suitable valueclosed
- true if the spline should be closed (i.e. return
to the starting point), false for an open curvetx
- a value by which to translate the curve along the x-dimensionty
- a value by which to translate the curve along the y-dimension
GeneralPath
instance.public static void expand(java.awt.geom.Rectangle2D r, double amount)
r
- the rectangle to expandamount
- the amount by which to expand the rectanglepublic static void setBounds(VisualItem item, java.awt.Shape shape, java.awt.BasicStroke stroke)
item
- the VisualItem whose bounds are to be setshape
- a Shape from which to determine the item boundsstroke
- the stroke type that will be used for drawing the object,
and may affect the final bounds. A null value indicates the
default (line width = 1) stroke is used.public static void paint(java.awt.Graphics2D g, VisualItem item, java.awt.Shape shape, java.awt.BasicStroke stroke, int type)
Graphics
interface methods when it can,
as opposed to the Graphics2D
methods such as
Graphics2D.draw(java.awt.Shape)
and
Graphics2D.fill(java.awt.Shape)
, resulting in a
significant performance increase on the Windows platform, particularly
for rectangle and line drawing calls.
g
- the graphics context to render toitem
- the item being represented by the shape, this instance is
used to get the correct color values for the drawingshape
- the shape to renderstroke
- the stroke type to use for drawing the object.type
- the rendering type indicating if the shape should be drawn,
filled, or both. One of
AbstractShapeRenderer.RENDER_TYPE_DRAW
,
AbstractShapeRenderer.RENDER_TYPE_FILL
,
AbstractShapeRenderer.RENDER_TYPE_DRAW_AND_FILL
, or
AbstractShapeRenderer.RENDER_TYPE_NONE
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |