Skip to main content
Path is a mutable path object that can be drawn by a Renderer. An unchanged path can be drawn multiple times per frame. However, if you mutate it (via moveTo, lineTo, cubicTo, add, etc.) after drawing, you must wait until the next frame to draw it again.

Constructors

new

new() -> Path
local path = Path.new()
path:moveTo(Vector.xy(0, 0))

Methods

moveTo

moveTo(to: Vector) -> () Moves the current point to the specified location, starting a new contour.
path:moveTo(Vector.xy(0, 0))

lineTo

lineTo(to: Vector) -> () Adds a straight line segment from the current point to the specified point.
path:lineTo(Vector.xy(10, 0))

quadTo

quadTo(control: Vector, to: Vector) -> () Adds a quadratic Bézier curve from the current point to the specified point, using the control point to define the curve shape.
path:quadTo(
  Vector.xy(-50, -50), -- control point
  Vector.xy(0, 0)      -- end point
)

cubicTo

cubicTo(controlOut: Vector, controlIn: Vector, to: Vector) -> () Adds a cubic Bézier curve from the current point to the specified point, using controlOut for the start tangent and controlIn for the end tangent.
path:cubicTo(
  Vector.xy(25, -40),  -- control point out
  Vector.xy(75, 40),   -- control point in
  Vector.xy(100, 0)    -- end point
)

close

close() -> () Closes the current contour by adding a line segment from the current point back to the first point of the contour (the last moveTo).
-- Draw a rectangle
path:moveTo(Vector.xy(-10, -10))
path:lineTo(Vector.xy(10, -10))
path:lineTo(Vector.xy(10, 10))
path:lineTo(Vector.xy(-10, 10))
-- Close the path
path:close()

__len

__len() Each entry is a PathCommand describing one segment or action in the path.
local cmd = path[1]
print(cmd.type)
Returns the number of commands in the path.
local count = #path
print(count)

reset

reset() -> () Do not mutate or reset a Path in the same frame after drawing it. If you need to change it, wait until the next frame. Only call reset on subsequent frames if you’ve called Renderer.drawPath with it.
path:reset()

add

add(other: PathData, transform: Mat2D?) -> () Appends the commands from other onto this path. If transform is provided, the appended commands are transformed as they are added.
local dst = Path.new()
local src = Path.new()

src:moveTo(Vector.xy(0, 0))
src:lineTo(Vector.xy(10, 0))
src:lineTo(Vector.xy(10, 10))
src:close()

-- Add `src` into `dst` (optionally with a transform)
dst:add(src)

contours

contours() -> ContourMeasure? Returns a ContourMeasure for the first contour in the path. A contour is a sequence of path segments starting at a moveTo and ending before the next moveTo (or end of path). Use the next property on the returned ContourMeasure to iterate through subsequent contours. Returns nil if the path has no contours.
local contour = path:contours()
while contour do
  print(contour.length)
  contour = contour.next
end

measure

measure() -> PathMeasure Returns a PathMeasure that measures the entire path across all contours. This provides the total length and allows operations on the path as a whole.
local measure = path:measure()
local pathLength = measure.length
print(pathLength)