Class Point
A position or an offset in logical pixels, made with Point(...).
- Where a Point is expected, a table with
xandy, or two numbers in a row, works too.
lua
local area = output:usable_area()
local top_left = Point(area.x, area.y)
local inset_corner = top_left + Point(16, 16)
local halfway = (top_left + area:center()) * 0.5Properties
point.x: numberx read only
The horizontal position, growing to the right.
point.y: numbery read only
The vertical position, growing downwards.
Methods
point:add(other: Point) -> niladd
Adds other to this point in place. Every variable holding this point sees the change.
- Points read from properties, such as
window.box.position:now(), are new on every read. Changing one changes nothing else.
lua
local cursor_target = Point(100, 100)
cursor_target:add({ x = 20, y = -10 })Operators
point + other -> Pointpoint + other
A new point, adding x to x and y to y.
point + rectgives the rect moved by the point. See Rect.
point - other -> Pointpoint - other
A new point, subtracting each coordinate.
lua
local offset = output:area():center() - window.box.position:now()point * other -> Pointpoint * other
Multiplies x by x and y by y: Point(2, 3) * Point(2, 2) is Point(4, 6).
point * number -> Pointpoint * number
Both coordinates scaled by the number. number * point works too.
point == other -> booleanpoint == other
True only for the same point object. Two points made separately with the same x and y are not equal, so compare the coordinates.
lua
local function same_place(a, b) return a.x == b.x and a.y == b.y endpoint .. value -> stringpoint .. value
The point as text joined with value turned into text, on either side: "at " .. Point(1, 2) is "at Point { x: 1, y: 2 }".