import "image/image";
The class represents a 2D shape defined by multiple paths (either closed or open), using lines and quadratic and cubic curves as primitives.
Internally the class is represented as an array where for each primitive there is a part type (an integer) followed by the coordinates (floats). Therefore no fields can be added in potential subclasses.
The primitive types are:
PART_MOVE_TO (0)
- followed by the point to move to (two floats for the x
and y
coordinate)PART_LINE_TO (1)
- followed by the point to line toPART_QUAD_TO (2)
- followed by the control point and the next pointPART_CUBIC_TO (3)
- followed by two control points and the next pointPART_CLOSE_PATH (4)
- adds line to coordinates of the last MOVE_TO
command
You can also process just the coordinates by checking the individual stored values using
the built-in is_float
function. You can distinguish between the x
and y
coordinates based on the parity (even or odd).
static function create(): Shape
static function line(x1: Float, y1: Float, x2: Float, y2: Float): Shape
static function rect(x: Float, y: Float, width: Float, height: Float): Shape
static function circle(cx: Float, cy: Float, radius: Float): Shape
static function ellipse(cx: Float, cy: Float, rx: Float, ry: Float): Shape
static function ellipse_rect(x: Float, y: Float, w: Float, h: Float): Shape
static function round_rect(x: Float, y: Float, w: Float, h: Float, arcw: Float, arch: Float): Shape
function clear()
function move_to(x: Float, y: Float)
function line_to(x: Float, y: Float)
function quad_to(x1: Float, y1: Float, x2: Float, y2: Float)
function cubic_to(x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float)
function arc_to(cx: Float, cy: Float, x2: Float, y2: Float)
function arc_to_neg(cx: Float, cy: Float, x2: Float, y2: Float)
function close_path()
function get_outline(): Shape
function get_outline(width: Float): Shape
function get_outline(width: Float, cap: Integer, join: Integer): Shape
function get_outline(width: Float, cap: Integer, join: Integer, miter_limit: Float): Shape
function get_bounds(): Float[]
function transform(tr: Transform)
function append(shape: Shape)
function append(shape: Shape, tr: Transform)
function hit_test(x: Float, y: Float): Boolean;
function get_reversed(): Shape