Extents
Based on game build 714014 | Last updated: 2026-02-27
Overview
This file contains standalone utility functions for computing spatial extents (axis-aligned bounding boxes) and minimum bounding radii for collections of nodes and polygonal shapes. It does not implement an Entity Component System (ECS) component; rather, it offers standalone helper functions used elsewhere in the map generation and layout systems to calculate spatial bounds. Functions here operate on plain Lua tables representing node data and polygon vertices, and update or return extent metadata including min/max coordinates, size, and radius.
Usage example
local extents = ResetextentsForNodes(my_nodes)
print("Bounding box:", extents.xmin, extents.ymin, extents.xmax, extents.ymax)
local poly_extents = ResetextentsForPoly({
{0, 0},
{4, 0},
{4, 3},
{0, 3}
})
print("Polygon radius:", poly_extents.radius)
local radius, cx, cy = GetMinimumRadiusForNodes(my_nodes)
Dependencies & tags
Components used: None identified.
Tags: None identified.
Properties
No public properties are initialized in a component constructor, as this file defines only stateless utility functions.
Main functions
UpdateextentsForNode(extents, node)
- Description: Expands the given
extentsbounding box to include the spatial footprint ofnode, assumingnode.data.positionis a 2D point andnode.data.sizeis the half-size (axis-aligned square centered atposition). - Parameters:
extents: Table with keysxmin,ymin,xmax,ymax. Modified in place.node: Table expected to havenode.data.position = {x, y}andnode.data.size = number.
- Returns: None (modifies
extentsin place). - Error states: Assumes
node.data.positionis indexable andnode.data.sizeis numeric; undefined behavior if not.
ResetextentsForNodes(nodes)
- Description: Computes a new bounding box that tightly encloses all nodes in the list. Initializes with extreme initial values (
xmin=1000000,xmax=-1000000, etc.) and iteratively expands viaUpdateextentsForNode. - Parameters:
nodes: List (array-like table) of node tables withnode.data.positionandnode.data.size.
- Returns: Table with keys
xmin,ymin,xmax,ymax. - Error states: Returns extreme initial values if
nodesis empty.
GetMinimumRadiusForNodes(nodes)
- Description: Computes the radius of the smallest circle that encloses all node centers and their extents. Internally constructs a list of candidate points (center and points offset by
+/-sizealong each axis) and delegates to a globalgetminimumradiusfunction. - Parameters:
nodes: List of node tables withnode.data.positionandnode.data.size.
- Returns: Three values:
radius(number),cx(center X),cy(center Y). (Exact definition of returned center depends ongetminimumradiusimplementation, which is not provided.) - Error states: Returns
nilor undefined values ifnodesis empty orgetminimumradiusfails.
UpdateextentsForPoint(extents, point)
- Description: Expands the given
extentsbounding box to include a single 2D point (represented as a two-element table). - Parameters:
extents: Table with keysxmin,ymin,xmax,ymax. Modified in place.point: Table{x, y}(indices1and2) of numeric coordinates.
- Returns: None (modifies
extentsin place). - Error states: Assumes
pointis indexable and numeric; undefined behavior otherwise.
ResetextentsForPoly(poly)
- Description: Computes a bounding box for a polygon defined by a list of vertices, and also calculates
sizeandradiusfields for convenience. Radius is defined as the larger of width and height. - Parameters:
poly: List of 2D points (each{x, y}or{point[1], point[2]}).
- Returns: Table with keys:
xmin,ymin,xmax,ymax: bounding coordinates.size:{x = width, y = height}.radius:max(width, height).
- Error states: Returns extreme initial values if
polyis empty.
Events & listeners
None. This file contains no event registration or emission logic.