Cauldron2D.Shape (Cauldron2D v0.2.2)

Copy Markdown View Source

A solid shape placed in world pixels, for collision.

form is {:rectangle, width, height}, every pixel solid, or {:mask, mask}, the solid pixels of a Cauldron2D.Mask. It is placed as a picture is drawn by Cauldron2D.Blend.draw/6: its origin lands on position, scaled per axis by scale (negative mirrors) and turned by angle degrees counter-clockwise.

shape = Cauldron2D.Shape.new({:mask, mask}, {120, 88}, origin: {9, 28}, scale: {-1, 1})
Cauldron2D.Shape.contains?(shape, {121.5, 80.5})

A world point is inside the shape when the shape's pixel it falls on is solid; a pixel covers [x, x + 1) by [y, y + 1) of the shape's own pixels.

Summary

Functions

The world rectangle {left, top, right, bottom} the shape lies within; nil for a shape scaled to nothing.

Whether the world point {x, y} is inside the shape.

form placed at position, with :origin, :scale and :angle as above.

Types

form()

@type form() :: {:rectangle, number(), number()} | {:mask, Cauldron2D.Mask.t()}

t()

@type t() :: %Cauldron2D.Shape{
  cos: number(),
  form: form(),
  origin: {number(), number()},
  position: {number(), number()},
  scale: {number(), number()},
  sin: number()
}

Functions

bounds(shape)

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

The world rectangle {left, top, right, bottom} the shape lies within; nil for a shape scaled to nothing.

contains?(shape, point)

@spec contains?(t(), {number(), number()}) :: boolean()

Whether the world point {x, y} is inside the shape.

new(form, position, opts \\ [])

@spec new(form(), {number(), number()}, keyword()) :: t()

form placed at position, with :origin, :scale and :angle as above.