Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class RasterPath

  1. Object
  2. RasterPath

A shape made of straight lines and quadratic and cubic Bezier curves, for RasterGraphics.fill(RasterPath) and RasterGraphics.draw(RasterPath).

A path is a list of subpaths, each started by moveTo(double, double). Filling closes every subpath implicitly; stroking draws a subpath closed only after closePath().

The static factories build the common shapes. Angles are in degrees, counterclockwise from three o’clock, as on screen with y pointing down (so a positive extent turns toward the top).

Fields

public static final int ARC_OPEN = 0An arc drawn alone, both ends open.
public static final int ARC_CHORD = 1An arc closed by the straight line between its ends.
public static final int ARC_PIE = 2An arc closed through the center, a pie slice.

Constructors

public RasterPath()

Methods

public RasterPath moveTo(double x, double y)Starts a new subpath at a point.
public RasterPath lineTo(double x, double y)Adds a straight line to a point.
public RasterPath quadTo(double cx, double cy, double x, double y)Adds a quadratic Bezier curve.
public RasterPath curveTo(double c1x, double c1y, double c2x, double c2y, double x, double y)Adds a cubic Bezier curve.
public RasterPath closePath()Closes the current subpath with a line back to its start.
public boolean isEmpty()Returns true when the path has no segments.
public static RasterPath polygon(double[] xs, double[] ys, int n)Creates a closed polygon.
public static RasterPath polyline(double[] xs, double[] ys, int n)Creates an open chain of lines.
public static RasterPath rect(double x, double y, double w, double h)Creates a rectangle.
public static RasterPath roundRect(double x, double y, double w, double h, double arcW, double arcH)Creates a rectangle with elliptical corners.
public static RasterPath ellipse(double x, double y, double w, double h)Creates the ellipse inscribed in a rectangle.
public static RasterPath arc(double x, double y, double w, double h, double startDeg, double extentDeg, int type)Creates an arc of the ellipse inscribed in a rectangle.
public RasterPath append(RasterPath other)Appends every subpath of another path to this one.

Inherited methods

Field details

ARC_OPEN

public static final int ARC_OPEN = 0
An arc drawn alone, both ends open.

ARC_CHORD

public static final int ARC_CHORD = 1
An arc closed by the straight line between its ends.

ARC_PIE

public static final int ARC_PIE = 2
An arc closed through the center, a pie slice.

Constructor details

RasterPath

public RasterPath()

Method details

moveTo

public RasterPath moveTo(double x, double y)
Starts a new subpath at a point.

Parameters

x double
x
y double
y

Returns

this path

lineTo

public RasterPath lineTo(double x, double y)
Adds a straight line to a point.

Parameters

x double
x
y double
y

Returns

this path

quadTo

public RasterPath quadTo(double cx, double cy, double x, double y)
Adds a quadratic Bezier curve.

Parameters

cx double
control point x
cy double
control point y
x double
end x
y double
end y

Returns

this path

curveTo

public RasterPath curveTo(double c1x, double c1y, double c2x, double c2y, double x, double y)
Adds a cubic Bezier curve.

Parameters

c1x double
first control point x
c1y double
first control point y
c2x double
second control point x
c2y double
second control point y
x double
end x
y double
end y

Returns

this path

closePath

public RasterPath closePath()
Closes the current subpath with a line back to its start.

Returns

this path

isEmpty

public boolean isEmpty()
Returns true when the path has no segments.

polygon

public static RasterPath polygon(double[] xs, double[] ys, int n)
Creates a closed polygon.

Parameters

xs double[]
x of each vertex
ys double[]
y of each vertex
n int
number of vertices to use

Returns

the path

polyline

public static RasterPath polyline(double[] xs, double[] ys, int n)
Creates an open chain of lines.

Parameters

xs double[]
x of each vertex
ys double[]
y of each vertex
n int
number of vertices to use

Returns

the path

rect

public static RasterPath rect(double x, double y, double w, double h)
Creates a rectangle.

Parameters

x double
left
y double
top
w double
width
h double
height

Returns

the path

roundRect

public static RasterPath roundRect(double x, double y, double w, double h, double arcW, double arcH)
Creates a rectangle with elliptical corners.

Parameters

x double
left
y double
top
w double
width
h double
height
arcW double
horizontal diameter of a corner
arcH double
vertical diameter of a corner

Returns

the path

ellipse

public static RasterPath ellipse(double x, double y, double w, double h)
Creates the ellipse inscribed in a rectangle.

Parameters

x double
left
y double
top
w double
width
h double
height

Returns

the path

arc

public static RasterPath arc(double x, double y, double w, double h, double startDeg, double extentDeg, int type)
Creates an arc of the ellipse inscribed in a rectangle.

Parameters

x double
left of the ellipse’s bounds
y double
top of the ellipse’s bounds
w double
width of the ellipse
h double
height of the ellipse
startDeg double
start angle in degrees
extentDeg double
angular extent in degrees, negative for clockwise
type int
ARC_OPEN, ARC_CHORD or ARC_PIE

Returns

the path

append

public RasterPath append(RasterPath other)
Appends every subpath of another path to this one.

Parameters

other RasterPath
the path to append

Returns

this path