Cauldron2D.Grid.Coarse.Space (Cauldron2D v0.2.2)

Copy Markdown View Source

Positions on a grid of width by height tiles whose opposite edges join when wrap?, as Cauldron2D.Grid.Coarse measures them. Any map with those three keys is a space.

Space.delta(%{width: 10, height: 10, wrap?: true}, {9.5, 0.5}, {0.5, 0.5})
#=> {1.0, 0.0}

Summary

Functions

How far to lies from from on each axis, the short way across joined edges.

The straight distance from a to b, the short way across joined edges.

The place of point nearest reference: point itself, or on a wrapping grid the copy of it across the edges closest to reference.

The tile holding point, brought onto the grid when it wraps, or nil when it lies off a grid that does not.

Types

t()

@type t() :: %{
  :width => pos_integer(),
  :height => pos_integer(),
  :wrap? => boolean(),
  optional(atom()) => term()
}

Functions

delta(space, arg1, arg2)

@spec delta(t(), {number(), number()}, {number(), number()}) :: {number(), number()}

How far to lies from from on each axis, the short way across joined edges.

distance(space, a, b)

@spec distance(t(), {number(), number()}, {number(), number()}) :: float()

The straight distance from a to b, the short way across joined edges.

near(space, reference, point)

@spec near(t(), {number(), number()}, {number(), number()}) :: {number(), number()}

The place of point nearest reference: point itself, or on a wrapping grid the copy of it across the edges closest to reference.

tile(space, arg)

@spec tile(t(), {number(), number()}) :: {integer(), integer()} | nil

The tile holding point, brought onto the grid when it wraps, or nil when it lies off a grid that does not.