Cauldron2D.Sectors.Trace (Cauldron2D v0.2.2)

Copy Markdown View Source

What a straight line across a sector map crosses, nearest first: the map's lines and the bodies filed in a Cauldron2D.Sectors.Blockmap.

Cauldron2D.Sectors.Trace.run(map, blockmap, {x, y}, {x + 2048.0, y})
#=> [%{fraction: 0.12, line: 4}, %{fraction: 0.31, body: :imp_7, at: {..}, radius: 20.0}, ...]

fraction is how far along from from to to the crossing is, 0.0..1.0. A line is crossed where the trace meets it; a body where the trace first enters its circle, or at 0.0 where from is already inside it. Instant-hit weapons, line of sight, reaching for a switch and sliding along a wall are all built on this.

Options

  • :lines — include lines. Default true
  • :bodies — include bodies. Default true
  • :except — a body id to leave out, such as the one tracing. Default nil

Summary

Functions

Where segment a1–a2 meets segment b1–b2, as a fraction along the first, or nil.

The intercepts from from to to, nearest first. See the moduledoc.

Types

intercept()

@type intercept() ::
  %{fraction: float(), line: non_neg_integer()}
  | %{fraction: float(), body: term(), at: {float(), float()}, radius: float()}

Functions

crossing(arg1, arg2, arg3, arg4)

@spec crossing(
  {number(), number()},
  {number(), number()},
  {number(), number()},
  {number(), number()}
) ::
  float() | nil

Where segment a1–a2 meets segment b1–b2, as a fraction along the first, or nil.

run(map, blockmap, from, to, opts \\ [])

The intercepts from from to to, nearest first. See the moduledoc.