StdLib.Area
Tools for working with bounding boxes.
Methods61
function Area.__call(_: any, ...: any) -> nil
function Area.new(area: BoundingBox) -> StdLib.Area
Converts an area in either array or table format to an area with a metatable. Returns itself if it already has a metatable
function Area.construct(...: number) -> StdLib.Area
Creates an area from number parameters.
function Area.load(area: BoundingBox) -> StdLib.Area
Loads the metatable into the passed Area without creating a new one.
function Area.from_string(area_string: string) -> StdLib.Area
Converts an area string to an area.
function Area.from_key(area_string: string) -> StdLib.Area
Converts a string key area to an area.
function Area.store(area: BoundingBox) -> BoundingBox
Stores the area for recall later, not deterministic. Only the last area stored is saved.
function Area.recall(area: BoundingBox) -> BoundingBox
Recalls the stored area.
areaBoundingBox
- BoundingBox
the stored area
function Area.normalize(area: BoundingBox) -> BoundingBox
Normalizes the given area. <ul> <li>Swaps the values between right_bottom.x & left_top.x IF right_bottom.x < left_top.x <li>Swaps the values between right_bottom.y & left_top.y IF right_bottom.y < left_top.y </ul>
areaBoundingBoxthe area to normalize
- BoundingBox
a new normalized area
function Area.normalized(area: BoundingBox) -> area BoundingBox
Normalize an area in place.
areaBoundingBoxthe area to normalize
areaBoundingBoxThe area normalized in place
function Area.from_pixels(area: BoundingBox) -> BoundingBox
Convert area from pixels.
function Area.to_pixels(area: BoundingBox) -> BoundingBox
Convert area to pixels.
function Area.round(area: BoundingBox) -> BoundingBox
Rounds an areas points to its closest integer.
function Area.ceil(area: BoundingBox) -> BoundingBox
Ceils an area by increasing the size of the area outwards
areaBoundingBoxthe area to round
- BoundingBox
function Area.floor(area: BoundingBox) -> BoundingBox
Floors an area by decreasing the size of the area inwards.
areaBoundingBoxthe area to round
- BoundingBox
function Area.center_points(area: BoundingBox) -> BoundingBox
Gets the center positions of the tiles where the given area's two positions reside.
areaBoundingBox
- BoundingBox
the area with its two positions at the center of the tiles in which they reside
function Area.corners(area: BoundingBox) -> area StdLib.Area.BoundingBoxCorners
Adds the left-bottom and right-top corner positions to a bounding box.
function Area.flip(area: BoundingBox) -> BoundingBox
Flip an area such that the value of its width becomes its height, and the value of its height becomes its width.
areaBoundingBoxthe area to flip
- BoundingBox
the fliped area
function Area.non_zero(area: BoundingBox, amount: number | Vector) -> the BoundingBox
Return a non zero sized area by expanding if needed
areaBoundingBoxthe area to check
amountnumber | Vectorthe amount to expand
theBoundingBoxarea
function Area.to_diameter(area: BoundingBox, diameter: number) -> BoundingBox
Returns the area to the diameter from left_top
function Area.min(area: BoundingBox, area2: BoundingBox) -> the BoundingBox
Returns the smallest sized area.
areaBoundingBoxarea2BoundingBox
theBoundingBoxsmallest area
function Area.max(area: BoundingBox, area2: BoundingBox) -> the BoundingBox
Returns the largest sized area.
areaBoundingBoxarea2BoundingBox
theBoundingBoxlargest area
function Area.shrink(area: BoundingBox, amount: number | Vector) -> the BoundingBox
Shrinks the area inwards by the given amount. The area shrinks inwards from top-left towards the bottom-right, and from bottom-right towards the top-left.
areaBoundingBoxthe area to shrink
amountnumber | Vectorthe amount to shrink
theBoundingBoxarea reduced by amount
function Area.expand(area: BoundingBox, amount: number | Vector) -> the BoundingBox
Expands the area outwards by the given amount.
areaBoundingBoxthe area
amountnumber | Vectorto expand each edge of the area outwards by
theBoundingBoxarea expanded by amount @see Area.shrink
function Area.adjust(area: BoundingBox, amount: number | Vector) -> BoundingBox
Adjust an area by shrinking or expanding. Imagine pinching & holding with fingers the top-left & bottom-right corners of a 2D box and pulling outwards to expand and pushing inwards to shrink the box. @usage local area = Area.adjust({{-2, -2}, {2, 2}}, {4, -1}) -- returns {lefttop = {x = -6, y = -1}, rightbottom = {x = 6, y = 1}}
areaBoundingBoxthe area to adjust
amountnumber | Vectorthe vectors to use
- BoundingBox
adjusted bounding box
function Area.offset(area: BoundingBox, pos: MapPosition) -> BoundingBox
Offsets the area by the {x, y} values.
function Area.translate(area: BoundingBox, direction: defines.direction, distance: number) -> BoundingBox
Translates an area in the given direction.
areaBoundingBoxthe area to translate
directiondefines.directionthe direction of translation
distancenumberthe distance of the translation
- BoundingBox
the area translated
function Area.to_surface_size(area: BoundingBox, surface: LuaSurface) -> BoundingBox
Set an area to the whole size of the surface.
function Area.shrink_to_surface_size(area: BoundingBox, surface: LuaSurface) -> BoundingBox
Shrinks an area to the size of the surface if it is bigger.
function Area.to_chunk_coords(area: BoundingBox) -> BoundingBox
Return the chunk coordinates from an area.
areaBoundingBox
- BoundingBox
Chunk position coordinates
function Area.center(area: BoundingBox) -> StdLib.Area.Position
Calculates the center of the area and returns the position.
function Area.to_key(area: BoundingBox) -> string
Return a suitable string for using as a table key
function Area.to_string(area: BoundingBox) -> string
Converts an area to a string.
areaBoundingBoxthe area to convert
- string
the string representation of the area
function Area.to_string_xy(area: BoundingBox) -> the string
Converts an area to an ltx, lty / rbx, rby string.
areaBoundingBoxthe area to convert
thestringstring representation of the area
function Area.is_zero(area: BoundingBox) -> boolean
Is this a non zero sized area
function Area.is_normalized(area: BoundingBox) -> boolean
Is the area normalized.
function Area.valid(area: BoundingBox) -> boolean
Is the area non-zero and normalized.
function Area.is_simple_area(area: BoundingBox) -> boolean
Is this a simple area. {{num, num}, {num, num}}
function Area.is_complex_area(area: BoundingBox) -> boolean
Is this a complex area {lefttop = {x = num, y = num}, rightbottom = {x = num, y = num}}
function Area.is_area(area: BoundingBox) -> boolean
Is this and area of any kind.
function Area.is_Area(area: BoundingBox) -> boolean
Does the area have the class attached
function Area.unpack(area: BoundingBox) -> (lt.x number, lt.y number, rb.x number, rb.y number, orientation float)
Unpack an area into a tuple.
function Area.unpack_positions(area: BoundingBox) -> (left_top MapPosition, right_bottom MapPosition)
Unpack an area into a tuple of position tables.
function Area.pack(area: BoundingBox) -> array BoundingBox
Pack an area into an array.
function Area.pack_positions(area: BoundingBox) -> BoundingBox
Pack an area into a simple bounding box array
areaBoundingBox
- BoundingBox
simple array
function Area.size(area: BoundingBox) -> (the number, the number, the number, the number)
Gets the properties of the given area. This function returns a total of four values that represent the properties of the given area.
areaBoundingBoxthe area from which to get the size
thenumbersize of the area — (width × height)
thenumberwidth of the area
thenumberheight of the area
thenumberperimeter of the area — (2 × (width + height))
function Area.rectangle(area: BoundingBox) -> (left_top.x number, left_top.y number, width number, height number)
Return the rectangle.
function Area.width(area: BoundingBox) -> width number
The width of the area.
function Area.height(area: BoundingBox) -> width number
The height of an area.
function Area.dimensions(area: BoundingBox) -> (width number, height number)
The dimensions of an area.
function Area.perimeter(area: BoundingBox) -> width number
The Perimiter of an area.
function Area.equals(area1: BoundingBox, area2: BoundingBox) -> boolean
Returns true if two areas are the same.
area1BoundingBoxarea2BoundingBox
- boolean
true if areas are the same
function Area.less_than(area1: BoundingBox, area2: BoundingBox) -> boolean
Is area1 smaller in size than area2
area1BoundingBoxarea2BoundingBox
- boolean
is area1 less than area2 in size
function Area.less_than_eq(area1: BoundingBox, area2: BoundingBox) -> boolean
Is area1 smaller or equal in size to area2.
area1BoundingBoxarea2BoundingBox
- boolean
is area1 less than or equal to area2 in size @local
function Area.collides(area1: BoundingBox, area2: BoundingBox) -> boolean
Does either area overlap/collide with the other area.
function Area.contains_positions(area: BoundingBox, positions: MapPosition.struct[]) -> boolean
Are the passed positions all located in an area.
function Area.contains_areas(area: BoundingBox, areas: BoundingBox[]) -> boolean
Are all passed areas completly inside an area.
areaBoundingBoxareasBoundingBox[]array of BoundingBox
- boolean
function Area.collides_areas(area: BoundingBox, areas: BoundingBox[]) -> boolean
Do all passed areas collide with an area.
areaBoundingBoxareasBoundingBox[]array of BoundingBox
- boolean
function Area.iterate(area: BoundingBox, as_position: nil | boolean, inside: nil | boolean, step: nil | number) -> function
Iterates an area. @usage local area = {{0, -5}, {3, -3}} for x,y in Area.iterate(area) do -- return x, y values end for position in Area.iterate(area, true) do -- returns a position object end -- Iterates from lefttop.x to rightbottom.x then goes down y until right_bottom.y
areaBoundingBoxthe area to iterate
as_positionnil | boolean[opt=false] return a position object
insidenil | boolean[opt=false] only return values that contain the areas tiles
stepnil | number[opt=1] size to increment
- function
an iterator
function Area.spiral_iterate(area: BoundingBox, as_position: nil | boolean) -> (fun(state: BoundingBox, control: any) -> ...number | StdLib.Area.Position | nil, area BoundingBox, control number)
Iterates the given area in a spiral as depicted below, from innermost to the outermost location. <p>! @usage for x, y in Area.spiral_iterate({{-2, -1}, {2, 1}}) do print('(' .. x .. ', ' .. y .. ')') end prints: (0, 0) (1, 0) (1, 1) (0, 1) (-1, 1) (-1, 0) (-1, -1) (0, -1) (1, -1) (2, -1) (2, 0) (2, 1) (-2, 1) (-2, 0) (-2, -1)
areaBoundingBoxThe area to iterate.
as_positionnil | booleanReturn a position object instead of x and y coordinates.
- fun(state: BoundingBox, control: any) -> ...number | StdLib.Area.Position | nil
areaBoundingBoxcontrolnumber
function Area.Positions(area, inside, step) -> table
Fields5
Area.left_top : StdLib.Area.Position
Area.right_bottom : StdLib.Area.Position
Area.orientation : RealOrientation | nil
Area.__class: string = "Area"
Area.__index : StdLib.Core