Package-level declarations

Types

Link copied to clipboard
data class QuadTree(val cell: Rectangle, val children: List<QuadTree> = emptyList(), val isFull: Boolean = false, val isEmpty: Boolean = false)

A node in an adaptive quadtree over a Rectangle, as described in https://www.mattkeeter.com/projects/contours/

Link copied to clipboard
typealias ShapeFunction = (Vector2) -> Double

A scalar field. A contour is found where ShapeFunction crosses zero, with negative values considered "inside" and positive (or zero) values considered "outside".

Functions

Link copied to clipboard
fun QuadTree.Companion.buildQuadTree(shapeFunction: ShapeFunction, area: Rectangle, maxDepth: Int): QuadTree

Builds an adaptive quadtree over area for shapeFunction, down to maxDepth, collapsing every subtree that turns out to be fully inside or fully outside the shape into a single QuadTree.Full/QuadTree.Empty node.

Link copied to clipboard
fun findContours(f: ShapeFunction, area: Rectangle, cellSize: Double, useInterpolation: Boolean = true): List<ShapeContour>

Find contours for a function f using the marching squares algorithm. A contour is found when f(x) crosses zero.

Link copied to clipboard
fun findContoursAdaptive(shapeFunction: ShapeFunction, area: Rectangle, maxDepth: Int): List<ShapeContour>

Finds contours for shapeFunction using an adaptive quadtree and dual contouring, as described in https://www.mattkeeter.com/projects/contours/. Unlike plain marching squares, cells are only subdivided down to maxDepth where the boundary actually needs the extra resolution, and dual vertices are placed on sharp features (corners, thin edges) instead of naive edge midpoints.

Link copied to clipboard
fun findContoursAdaptiveMarchingSquares(shapeFunction: ShapeFunction, area: Rectangle, maxDepth: Int): List<ShapeContour>

Finds contours for shapeFunction over an adaptive quadtree, like findContoursAdaptive, but resolves each straddling leaf independently with plain marching squares instead of dual contouring -- there is no dual vertex, no faceProc-style stitching between cells, just every leaf's own crossingSegments gathered up directly.

Link copied to clipboard

Finds the dual graph of this, as described in https://www.mattkeeter.com/projects/contours/: one point per leaf cell (its center), and one polygon for every grid vertex shared by two or more leaves -- a quad where four same-depth leaves meet, or a triangle at a "hanging" T-junction where one coarser leaf borders two finer ones.