FixImage Documentation

Back to summary

import "image/image";

Shape class

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:

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).

Initialization

static function create(): Shape
Creates a new empty shape.

Common shapes

static function line(x1: Float, y1: Float, x2: Float, y2: Float): Shape
Creates a line shape.
static function rect(x: Float, y: Float, width: Float, height: Float): Shape
Creates a rectangle shape.
static function circle(cx: Float, cy: Float, radius: Float): Shape
Creates a circle shape.
static function ellipse(cx: Float, cy: Float, rx: Float, ry: Float): Shape
Creates an ellipse shape.
static function ellipse_rect(x: Float, y: Float, w: Float, h: Float): Shape
Creates an ellipse shape defined by a rectangle.
static function round_rect(x: Float, y: Float, w: Float, h: Float, arcw: Float, arch: Float): Shape
Creates a rounded rectangle.

Shape definition

function clear()
Clears the shape, making it empty.
function move_to(x: Float, y: Float)
Moves virtual pen to given position.
function line_to(x: Float, y: Float)
Draws line to given position.
function quad_to(x1: Float, y1: Float, x2: Float, y2: Float)
Draws quadratic curve using the control point (x1,y1) to given position (x2,y2).
function cubic_to(x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float)
Draws cubic curve using the control points (x1,y1 and x2,y2) to given position (x3,y3).
function arc_to(cx: Float, cy: Float, x2: Float, y2: Float)
Draws arc segment using the center (cx,cy) to given position (x2,y2). The segment is drawn clockwise in default transformation.
function arc_to_neg(cx: Float, cy: Float, x2: Float, y2: Float)
Draws arc segment in the opposite direction (in counter-clockwise).
function close_path()
Closes the current path, drawing a line between the last and first points.

Outline

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
Returns a shape that defines an outline of the shape. By default a width of 1.0 is used with the square cap and the miter join (with miter limit of 10.0).
Cap values:
CAP_BUTT - the ends are closed directly
CAP_ROUND - the ends are closed with a circle
CAP_SQUARE - the ends are closed with a half square
Join values:
JOIN_BEVEL - edges are joined with a line
JOIN_ROUND - edges are joined with a circle
JOIN_MITER - edges are extended to a sharp edge

Miscellaneous

function get_bounds(): Float[]
Returns the rectangular bounds of the shape. The returned values are in this order: min_x, min_y, max_x, max_y.
function transform(tr: Transform)
Transforms the shape by a given transform.
function append(shape: Shape)
function append(shape: Shape, tr: Transform)
Appends the shape to another, optionally applying given transform.
function hit_test(x: Float, y: Float): Boolean;
Returns true if given point is inside the shape.
function get_reversed(): Shape
Returns a new shape that has the opposite directions of the paths.