Module ui.geometry

2D Geometry utilities

All of these apply to full rectangles:

local Geom = require("ui/geometry")
Geom:new{ x = 1, y = 0, w = Screen:scaleBySize(100), h = Screen:scaleBySize(200), }

Some behaviour is defined for points:

Geom:new{ x = 0, y = 0, }

Some behaviour is defined for dimensions:

Geom:new{ w = Screen:scaleBySize(600), h = Screen:scaleBySize(800), }

Just use it on simple tables that have x, y and/or w, h or define your own types using this as a metatable

Functions

Geom:copy () Makes a deep copy of itself.
Geom:offsetBy (dx, dy) Offsets rectangle or point by relative values
Geom:offsetTo (x, y) Offsets rectangle or point to certain coordinates
Geom:scaleBy (zx, zy) Scales rectangle (grow to bottom and to the right) or dimension
Geom:transformByScale (zx, zy) This method also takes care of x and y on top of Geom:scaleBy
Geom:area () Returns area of itself.
Geom:changeSizeBy (dw, dh) Enlarges or shrinks dimensions or rectangles
Geom:combine (rect_b) Returns a new outer rectangle that contains both us and a given rectangle
Geom:intersect (rect_b) Returns a new rectangle for the part that we and a given rectangle share
Geom:notIntersectWith (rect_b) Returns true if self does not share any area with rect_b
Geom:intersectWith (rect_b) Returns true if self geom shares area with rect_b.
Geom:setSizeTo (rect_b) Set size of dimension or rectangle to size of given dimension/rectangle.
Geom:contains (rect_b) Checks whether rect_b is within current rectangle

Works for dimensions, too.

Geom:__eq (rect_b) Checks for equality.
Geom:equalSize (rect_b) Checks the size of a dimension/rectangle for equality.
Geom:__lt (rect_b) Checks if our size is smaller than the size of the given dimension/rectangle.
Geom:__le (rect_b) Checks if our size is smaller or equal to the size of the given dimension/rectangle.
Geom:offsetWithin (rect_b, dx, dy) Offsets the current rectangle by dx, dy while fitting it into the space of a given rectangle.
Geom:centerWithin (rect_b, dx, dy) Centers the current rectangle at position x and y of a given rectangle.
Geom:distance (rect_b) Returns the Euclidean distance between two geoms.
Geom:midpoint (geom) Returns the midpoint of two geoms.
Geom:center () Returns the center point of this geom.

Tables

Geom


Functions

Geom:copy ()
Makes a deep copy of itself.

Returns:

    Geom
Geom:offsetBy (dx, dy)
Offsets rectangle or point by relative values

Parameters:

  • dx int x delta
  • dy int y delta
Geom:offsetTo (x, y)
Offsets rectangle or point to certain coordinates

Parameters:

  • x int new x
  • y int new y
Geom:scaleBy (zx, zy)
Scales rectangle (grow to bottom and to the right) or dimension If a single factor is given, it is applied to both width and height

Parameters:

  • zx int scale for x axis
  • zy int scale for y axis
Geom:transformByScale (zx, zy)
This method also takes care of x and y on top of Geom:scaleBy

Parameters:

  • zx int scale for x axis
  • zy int scale for y axis
Geom:area ()
Returns area of itself.

Returns:

    int
Geom:changeSizeBy (dw, dh)
Enlarges or shrinks dimensions or rectangles Note that for rectangles the offset stays the same

Parameters:

  • dw int width delta
  • dh int height delta
Geom:combine (rect_b)
Returns a new outer rectangle that contains both us and a given rectangle Works for rectangles, dimensions and points

Parameters:

Returns:

    Geom
Geom:intersect (rect_b)
Returns a new rectangle for the part that we and a given rectangle share

Parameters:

Returns:

    Geom TODO: what happens if there is no rectangle shared? currently behaviour is undefined.
Geom:notIntersectWith (rect_b)
Returns true if self does not share any area with rect_b

Parameters:

Geom:intersectWith (rect_b)
Returns true if self geom shares area with rect_b.

Parameters:

Geom:setSizeTo (rect_b)
Set size of dimension or rectangle to size of given dimension/rectangle.

Parameters:

Geom:contains (rect_b)
Checks whether rect_b is within current rectangle

Works for dimensions, too. For points, it is basically an equality check.

Parameters:

Geom:__eq (rect_b)
Checks for equality.

Works for rectangles, points, and dimensions.

Parameters:

Geom:equalSize (rect_b)
Checks the size of a dimension/rectangle for equality.

Parameters:

Geom:__lt (rect_b)
Checks if our size is smaller than the size of the given dimension/rectangle.

Parameters:

Geom:__le (rect_b)
Checks if our size is smaller or equal to the size of the given dimension/rectangle.

Parameters:

Geom:offsetWithin (rect_b, dx, dy)
Offsets the current rectangle by dx, dy while fitting it into the space of a given rectangle.

This can also be called with dx=0 and dy=0, which will fit the current rectangle into the given rectangle.

Parameters:

  • rect_b Geom
  • dx int
  • dy int
Geom:centerWithin (rect_b, dx, dy)
Centers the current rectangle at position x and y of a given rectangle.

Parameters:

  • rect_b Geom
  • dx int
  • dy int
Geom:distance (rect_b)
Returns the Euclidean distance between two geoms.

Parameters:

Geom:midpoint (geom)
Returns the midpoint of two geoms.

Parameters:

Returns:

    Geom
Geom:center ()
Returns the center point of this geom.

Returns:

    Geom

Tables

Geom

Fields:

  • x
  • y
  • w
  • h
generated by LDoc 1.4.6 Last updated 2017-10-08 14:57:40