SHIFT + D

Plane

Updated on August 22, 2024Source code

Baleada Features uses the concept of a plane to represent a two-dimensional space of elements.

Abstractly, a plane is an array of arrays. Each of those nested arrays contains items, which are the "points" in the plane.

[
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
]

To make this data structure a little easier to work with, Baleada Features implements and exports a Plane class, which is a simple extension of Array, with a few nice methods:

Method
Description
Parameters
Return value
get
Retrieves the value at a specific set of coordinates
{ row: number, column: number }
The value at the specified coordinates
set
Sets the value at a specific set of coordinates
{ row: number, column: number }, value: any
undefined
points
Iterates over every point in the plane, yielding the coordinates and value of each point
-
An iterator

In day-to-day userland code, you'll virtually never interact with any Planes directly. It's mainly useful for Baleada Features' internals, and it's useful to anyone authoring their own composables with Baleada Features' patterns.

But just in case, here are a few examples of how you might use a Plane:

const plane = new Plane([
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
])

plane.get({ row: 1, column: 1 }) // 5

plane.set({ row: 1, column: 1 }, 10)

for (const { row, column, point } of plane.points()) {
  console.log(`Row ${row}, column ${column}: ${point}`)
}

function isPlane (arrayOrPlane) {
  return arrayOrPlane instanceof Plane
}

Eligible pickingValidity

Edit doc on GitHub

ON THIS PAGE

Plane