Rectangle Generator
Generates a planar graph of nodes by recursively subdividing rectangles, used by `procTrack` for gymkhana track generation.
Generates a planar graph of nodes by recursively subdividing rectangles, used by procTrack for gymkhana track generation.
Overview
util_rectangleGen is a helper module (not an extension - it uses require) that takes a set of starting rectangles and parameters, recursively subdivides them, and returns a graph with nodes at rectangle centers and neighbor adjacency information.
Module path: lua/ge/extensions/util/rectangleGen.lua
Exports (M)
| Function | Signature | Description |
|---|---|---|
getGraph | (params) → graph|nil | Subdivides starting rectangles and returns a node graph with neighbors. |
dist | (a,b,x,y) → number | 2D Euclidean distance helper. |
Internals
Graph Structure
graph = {
nodes = {
{ x, y, neighbours = {{index, dist},...}, name, closestNeighbourDist, force },
...
},
start = node_or_nil, -- node with start flag
finish = node_or_nil -- node with finish flag
}Subdivision Algorithm
- Copies
startingRects(excludingnoSplitrects) into a working list. - Iteratively picks the largest rectangle and splits it vertically or horizontally:
- Direction chosen by
params.rectModeParams.vertSplitFunction(width, height). - Split position chosen by
params.rectModeParams.cutValueFunction(), clamped to respectminXDist/minYDist.
- Direction chosen by
- Stops when rectangle count reaches
params.rectModeParams.numNodesor no more splits possible. noSplitrectangles are appended afterwards (fixed nodes with optionalstart/finishflags).
Neighbor Detection
Two rectangles are neighbors if they share an edge (within floating-point tolerance 0.001):
- Left/right adjacency: matching X boundary and overlapping Y range.
- Top/bottom adjacency: matching Y boundary and overlapping X range.
Node Placement
Each rectangle's center becomes a node. The closestNeighbourDist field records the minimum distance to any neighbor, used by procTrack for radius calculations.
How It Works
procTrack.checkParams()callsrequire('util/rectangleGen').makeBaseNodePositions()callsgetGraph(params).- The returned graph feeds into the Hamiltonian path solver.
Lua Examples
-- Used internally by procTrack, not typically called directly
local rectGen = require('util/rectangleGen')
local graph = rectGen.getGraph(params)
-- graph.nodes contains positioned nodes with neighbor infoAdditional Exports
M.dist- (undocumented)M.getGraph- (undocumented)