///|
/// Generates a rectangular coordinate field with normalized coordinates.
pub fn normalized_grid(columns : Int, rows : Int) -> Array[Vec2] {
let result = []
if columns > 0 && rows > 0 {
for row in 0.. Array[Vec2] {
let result = []
let random = Random::new(seed)
for point in normalized_grid(columns, rows) {
result.push(
Vec2::new(
point.x + random.range(-jitter, jitter),
point.y + random.range(-jitter, jitter),
),
)
}
result
}
///|
pub fn triangular_points(
columns : Int,
rows : Int,
spacing : Double,
) -> Array[Vec2] {
let result = []
if columns > 0 && rows > 0 {
for row in 0.. Array[Vec2] {
let result = []
let horizontal = radius * 1.73205080757
let vertical = radius * 1.5
if columns > 0 && rows > 0 {
for row in 0.. Array[Vec2] {
let result = []
if rings > 0 && segments > 0 {
for ring in 0.. Array[Int] {
let result = []
if columns > 0 && rows > 0 && index >= 0 && index < columns * rows {
let x = index % columns
let y = index / columns
for dy in -1..<=1 {
for dx in -1..<=1 {
if !(dx == 0 && dy == 0) && (diagonal || dx == 0 || dy == 0) {
let nx = x + dx
let ny = y + dy
if nx >= 0 && ny >= 0 && nx < columns && ny < rows {
result.push(ny * columns + nx)
}
}
}
}
}
result
}
///|
pub fn grid_adjacency(
columns : Int,
rows : Int,
diagonal : Bool,
) -> Array[Array[Int]] {
let result = []
for index in 0..<(columns * rows) {
result.push(grid_neighbors(index, columns, rows, diagonal))
}
result
}