RectangleGrid

class RectangleGrid(val grid: List<List<Rectangle>>) : List<List<Rectangle>> (source)

Represents a rectangular grid structure composed of lists of Rectangle instances.

This class provides a convenient abstraction for working with 2D grids, where each cell is represented by a Rectangle. The class delegates to the underlying grid structure, which is implemented as a list of lists, allowing it to be used interchangeably with other list-based data structures.

Constructors

Link copied to clipboard
constructor(grid: List<List<Rectangle>>)

Properties

Link copied to clipboard
@get:JvmName(name = "segmentBounds")
val Iterable<Segment2D>.bounds: Rectangle

Evaluates the bounds around all Segment2D instances in the Iterable

@get:JvmName(name = "shapeContourBounds")
val Iterable<ShapeContour>.bounds: Rectangle

Evaluates the bounds around all ShapeContour instances in the Iterable

@get:JvmName(name = "shapeBounds")
val Iterable<Shape>.bounds: Rectangle

Evaluates the bounds around all Shape instances in the Iterable

@get:JvmName(name = "getRectangleListBounds")
val List<List<Rectangle>>.bounds: Rectangle

Computes the bounding rectangle that encompasses all the rectangles contained in the lists.

Link copied to clipboard
val grid: List<List<Rectangle>>

The 2D list structure containing Rectangle elements.

Link copied to clipboard
open override val size: Int

Functions

Link copied to clipboard
fun List<Rectangle>.alignToHorizontally(to: Rectangle, anchor: Double = 0.5): List<Rectangle>

Aligns a list of rectangles horizontally relative to a specified rectangle.

Link copied to clipboard
fun List<Rectangle>.alignToVertically(to: Rectangle, anchor: Double = 0.5): List<Rectangle>

Aligns the rectangles in the list vertically to a reference rectangle. The vertical position of each rectangle is determined based on the reference rectangle and the specified vertical anchor point.

Link copied to clipboard
fun List<Vector2>.alphaShape(): Shape

Create an alpha shape from list of Vector2

Link copied to clipboard
fun List<Vector2>.arcer(closed: Boolean, startTangent: Vector2? = null, maxArcLength: Double = Double.POSITIVE_INFINITY, offset: Double = 0.0, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): ShapeContour

Converts this polyline into a contour of tangent-continuous circular arcs that pass through all of its points, after surface-detail.com/posts/arc-plotter.

Link copied to clipboard
fun List<Vector2>.biarcs(closed: Boolean, tangents: List<Vector2>? = null, tangentMethod: BiarcTangents = BiarcTangents.CatmullRom(), offset: Double = 0.0, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): ShapeContour

Converts this polyline into a contour of biarcs: every pair of consecutive points is joined by two circular arcs that leave the first point in its tangent direction, meet tangentially at a joint, and arrive at the second point in its tangent direction. Unlike org.openrndr.extra.shapes.arcer.arcer, every edge is fixed by its own end tangents, so the contour is tangent-continuous everywhere, also where it closes, and an edge doesn't influence the edges after it.

Link copied to clipboard
fun RectangleGrid.block(x: Int, y: Int, width: Int, height: Int): RectangleGrid

Extracts a sub-block from a 2D list of rectangles based on the specified coordinates and dimensions.

Link copied to clipboard
fun <T : LinearType<T>> List<T>.bSpline(degree: Int = 3, closed: Boolean = false): BSpline<T>

The B-spline with this control polygon: BSpline.clamped for an open polygon, BSpline.periodic for a closed one. The degree is reduced where there are too few control points for it.

Link copied to clipboard
fun List<Vector2>.catmullRom(alpha: Double = 0.5, closed: Boolean): CatmullRomChain2
fun List<Vector3>.catmullRom(alpha: Double = 0.5, closed: Boolean): CatmullRomChain3
Link copied to clipboard
fun List<Vector2>.circleSpline(closed: Boolean, tolerance: Double = 0.01, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): ShapeContour

Converts this polyline into a circle spline through all points, after Séquin, Lee and Yen, "Fair, G2- and C2-continuous circle splines for the interpolation of sparse data points" (Computer-Aided Design, 2005).

Link copied to clipboard
fun List<Vector2>.clothoids(closed: Boolean, tangents: List<Vector2>? = null, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): ShapeContour

Converts this polyline into a clothoid spline: a contour of clothoid (Euler spiral) segments, along which the curvature changes linearly with arc length, that passes through all points.

Link copied to clipboard
fun List<List<Rectangle>>.column(index: Int): List<Rectangle>

Retrieves a column of rectangles from a 2D list of rectangles.

Link copied to clipboard
open operator override fun contains(element: List<Rectangle>): Boolean
Link copied to clipboard
open override fun containsAll(elements: Collection<List<Rectangle>>): Boolean
Link copied to clipboard
fun List<Vector2>.convexHull(): ShapeContour

Computes the convex hull of a list of 2D points using the Monotone chain algorithm. The convex hull is the smallest convex shape that encompasses all the points in the input list.

Link copied to clipboard
fun List<Vector2>.convexHullSet(): Set<Vector2>

Computes the convex hull of a list of 2D points and returns the vertices of the hull as a set. The convex hull is the smallest convex polygon that can enclose all points in the input list.

Link copied to clipboard
fun List<Rectangle>.distributeHorizontally(within: Rectangle = bounds): List<Rectangle>

Distributes the rectangles in the list horizontally within a specified bounding rectangle.

Link copied to clipboard
fun List<Rectangle>.distributeVertically(within: Rectangle = bounds): List<Rectangle>

Distributes the rectangles in the list vertically within the given bounding rectangle. The rectangles are spaced evenly, ensuring an equal distance between them, while maintaining their original height and width.

Link copied to clipboard

Drops the first n columns from a 2D list of Rectangles.

Link copied to clipboard

Removes the last n columns from each row (inner list) within a two-dimensional list.

Link copied to clipboard
fun List<Vector2>.dubinsPath(radius: Double, closed: Boolean = false, directions: List<Vector2>? = null, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): ShapeContour

The shortest Dubins paths between consecutive points of this polyline, joined into a contour: the path a vehicle with minimum turning radius takes through the points. When directions is null, the direction at every point is that of the centripetal Catmull-Rom spline through the points. The path passes through every point in its direction and is tangent-continuous; between points it consists of arcs of radius and straight segments.

Link copied to clipboard
fun List<Vector2>.elastica(closed: Boolean, tolerance: Double = 0.01, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): ShapeContour

Converts this polyline into an elastica through all points: a minimum-energy curve (MEC), the G2 curve that minimizes its bending energy ∫κ² ds, which is the shape of a thin elastic rod threaded through pins at the points. A pin applies a force but no bending moment, so the curvature is continuous where the rod passes it.

Link copied to clipboard
fun List<Vector2>.filletCorners(radius: Double, closed: Boolean, reverseCurves: Boolean = true, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): ShapeContour

Converts this polyline into a contour in which the corners are replaced by circular arcs of radius that keep the tangent direction continuous along the whole contour.

Link copied to clipboard
fun List<Rectangle>.fitHorizontally(within: Rectangle = bounds, gutter: Double = 0.0): List<Rectangle>

Distributes a list of rectangles horizontally within a given container rectangle, maintaining their relative width proportions and adding an optional gutter between them.

Link copied to clipboard
fun List<Rectangle>.fitVertically(within: Rectangle = bounds, gutter: Double = 0.0): List<Rectangle>

Fits a list of rectangles within a given vertical rectangular area. Each rectangle's height is adjusted proportionally based on its original height relative to the total height of all rectangles in the list. The rectangles are then distributed vertically, with an optional gutter spacing between them.

Link copied to clipboard
fun List<Vector3>.frames(up0: Vector3): List<Matrix44>

Calculate frames (pose matrices) using parallel transport

Link copied to clipboard
open operator override fun get(index: Int): List<Rectangle>
Link copied to clipboard
operator fun RectangleGrid.get(x: Int, y: Int): Rectangle

Retrieves a Rectangle from a two-dimensional list of Rectangles based on the specified x and y indices.

operator fun RectangleGrid.get(x: Int, yRange: IntRange): List<Rectangle>

Retrieves a list of rectangles at a specific x-coordinate for a range of y-coordinates from a 2D list of rectangles.

operator fun RectangleGrid.get(xRange: IntRange, y: Int): List<Rectangle>

Retrieves a sublist of Rectangle objects from a two-dimensional List given a range of indices for rows and a specific column index.

operator fun RectangleGrid.get(xRange: IntRange, yRange: IntRange): RectangleGrid

Retrieves a subgrid from a 2D list of Rectangles based on the specified ranges.

Link copied to clipboard
fun List<Vector2>.hilbertOrder(scale: Double = 1.0, permutation: Axis2DPermutation = Axis2DPermutation.XY, bits: Int = 16): List<Vector2>
fun List<Vector3>.hilbertOrder(scale: Double = 1.0, permutation: Axis3DPermutation = Axis3DPermutation.XYZ, bits: Int): List<Vector3>
Link copied to clipboard
open override fun indexOf(element: List<Rectangle>): Int
Link copied to clipboard
@JvmName(name = "interpolatingBSpline2D")
fun List<Vector2>.interpolatingBSpline(degree: Int = 3, closed: Boolean = false, alpha: Double = 0.5): BSpline<Vector2>

The B-spline of degree that passes through these 2D points, see interpolatingBSpline.

@JvmName(name = "interpolatingBSpline3D")
fun List<Vector3>.interpolatingBSpline(degree: Int = 3, closed: Boolean = false, alpha: Double = 0.5): BSpline<Vector3>

The B-spline of degree that passes through these 3D points, see interpolatingBSpline.

fun <T : LinearType<T>> List<T>.interpolatingBSpline(degree: Int = 3, closed: Boolean = false, alpha: Double = 0.5, distance: (T, T) -> Double): BSpline<T>

The B-spline of degree that passes through these points, after Piegl and Tiller, "The NURBS Book", algorithm A9.1.

Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
open operator override fun iterator(): Iterator<List<Rectangle>>
Link copied to clipboard
fun List<Vector2>.kCurve(closed: Boolean, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): ShapeContour

Converts this polyline into a κ-curve, after Yan, Schiller, Wilensky, Carr and Schaefer, "κ-Curves: Interpolation at Local Maximum Curvature" (SIGGRAPH 2017): a curve of quadratic Béziers, one per point, on which every point is where the curvature of its quadratic peaks. Corners of the polyline therefore become the sharpest spots of the curve, and the curve never bends more sharply between the points than at them.

Link copied to clipboard
fun List<Vector3>.kochanekBartels(closed: Boolean, parameters: List<TCB>): Path3D

Converts this 3D polyline into a Kochanek-Bartels spline with a tension, continuity and bias per point.

fun List<Vector2>.kochanekBartels(closed: Boolean, parameters: List<TCB>, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): ShapeContour

Converts this polyline into a Kochanek-Bartels spline with a tension, continuity and bias per point, see List.kochanekBartels.

fun List<Vector3>.kochanekBartels(closed: Boolean, tension: Double = 0.0, continuity: Double = 0.0, bias: Double = 0.0): Path3D

Converts this 3D polyline into a Kochanek-Bartels spline, for instance for a camera path, see List.kochanekBartels.

fun List<Vector2>.kochanekBartels(closed: Boolean, tension: Double = 0.0, continuity: Double = 0.0, bias: Double = 0.0, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): ShapeContour

Converts this polyline into a Kochanek-Bartels spline, after Kochanek and Bartels, "Interpolating splines with local tension, continuity, and bias control" (SIGGRAPH 1984): a cubic Hermite spline through all points whose tangents are shaped by a tension, continuity and bias, see TCB. With all three 0 it is the uniform Catmull-Rom spline.

Link copied to clipboard
open override fun lastIndexOf(element: List<Rectangle>): Int
Link copied to clipboard
open override fun listIterator(): ListIterator<List<Rectangle>>
open override fun listIterator(index: Int): ListIterator<List<Rectangle>>
Link copied to clipboard
fun List<Vector2>.metro(closed: Boolean, directions: Int = 4, angleOffset: Double = 0.0, segmentPenalty: Double = 0.0, boundsWeight: Double = 0.0): List<Vector2>

Fits a polyline with segments in a limited set of directions to this sequence of points, using the path schematisation heuristic described in Dwyer, Hurst and Merrick, "A Fast and Simple Heuristic for Metro Map Path Simplification" (ISVC 2008).

Link copied to clipboard
fun List<Vector2>.minimumVariationCurve(closed: Boolean, tolerance: Double = 0.01, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): ShapeContour

Converts this polyline into a minimum-variation curve (MVC) through all points: the G2 curve that minimizes the variation of its curvature, ∫(dκ/ds)² ds, after Moreton and Séquin, "Functional optimization for fair surface design" (SIGGRAPH 1992). The variation shrinks as a curve grows, so where the curve loops it has no minimum: the loop would inflate without end. The scale-invariant form, the variation times the cube of the curve length, is minimized instead; it has the same minimizers up to how the length is weighed in, and a circle still scores zero. Where clothoid splines let the curvature change linearly along every segment, the MVC lets it change as little as possible over the whole curve, so it is fairer still. Points on a circle give that circle, the curve with zero variation, and collinear points a straight line.

Link copied to clipboard
fun List<Vector2>.mortonOrder(scale: Double = 1.0, permutation: Axis2DPermutation = Axis2DPermutation.XY, bits: Int = 16): List<Vector2>
fun List<Vector3>.mortonOrder(scale: Double = 1.0, permutation: Axis3DPermutation = Axis3DPermutation.XYZ, bits: Int = 10): List<Vector3>
Link copied to clipboard
fun List<Vector2>.phQuintics(closed: Boolean, offset: Double = 0.0, tolerance: Double = 0.01, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): ShapeContour

Converts this polyline into a C2 spline of Pythagorean-hodograph quintics through all points, see phQuinticSpline, as a contour of cubic Béziers within tolerance. With a non-zero offset the offset curve at that distance is returned; it is evaluated exactly, PH curves have rational offsets, and approximated within tolerance too.

Link copied to clipboard
fun List<Vector2>.phQuinticSpline(closed: Boolean): List<PHQuintic>

The C2 interpolating spline of PH quintics through this polyline, one per edge, after Albrecht and Farouki, "Construction of C2 Pythagorean-hodograph interpolating splines by the homotopy method" (Advances in Computational Mathematics, 1996).

Link copied to clipboard
fun List<List<Rectangle>>.row(index: Int): List<Rectangle>

Retrieves the row from a 2D list of Rectangle objects at the specified index.

Link copied to clipboard

Selects specific columns from a two-dimensional list of rectangles. The method slices each inner list based on the provided column indices.

Slices the specified range of columns from each row of a two-dimensional list.

Link copied to clipboard
open override fun subList(fromIndex: Int, toIndex: Int): List<List<Rectangle>>
Link copied to clipboard
fun List<Box>.subtract(other: Box): List<Box>

Subtracts a given Box from each Box in the list and returns a list of the resulting Boxes.

fun List<Rectangle>.subtract(other: Rectangle): List<Rectangle>

Subtracts a rectangle from a list of rectangles, removing overlapping areas and returning the non-overlapping parts of the original rectangles.

Link copied to clipboard

Selects the first n columns from each row in a 2D list of Rectangle objects.

Link copied to clipboard

Returns a new list where each sub-list contains only the last n elements of the original sub-list.

Link copied to clipboard
fun List<Segment2D>.toContour(closed: Boolean = false): ShapeContour

Stitch the fitted pieces into a single contour, e.g. for drawing; closed for the pieces of a closed fit.

Link copied to clipboard

Transposes a 2D list of rectangles, switching rows and columns.

Link copied to clipboard
fun List<List<Rectangle>>.uniform(random: Random): Rectangle

Selects a random Rectangle from a nested list of rectangles using the provided random generator.

Link copied to clipboard
fun RectangleGrid.uniformBlock(minWidth: Int = 1, maxWidth: Int = this[0].size, minHeight: Int = 1, maxHeight: Int = this.size, random: Random = Random.Default): RectangleGrid

Extracts a uniform random sub-block of rectangles from a 2D list within the specified constraints.

Link copied to clipboard
fun <E> List<E>.update(vararg updates: Pair<Int, E>): List<E>
Link copied to clipboard
fun List<Double>.weldAscending(epsilon: Double = 1.0E-6): List<Double>

Removes values from a list of doubles that are within a specified tolerance (epsilon) of the last added value, while preserving the ascending order of the list. The input list must already be in ascending order.