Macaw.Frame.Hooks.Zoom (macaw_frame v0.1.0)

Copy Markdown View Source

The zoom transform helpers (spec/10 §7.6), visualize's Visualize.Hooks.Zoom: the transform FrameZoom writes on the drawing's zoom group, translate(x,y) scale(k), as %{k, x, y}, so the server reads what the client did with the same arithmetic. The transform is client-side: it costs the server nothing; the hook emits "zoom" only when the view needs more detail, "view" when a geographic pan ends, "reset" on a double-click.

iex> t = Macaw.Frame.Hooks.Zoom.scale_transform(Macaw.Frame.Hooks.Zoom.identity_transform(), 2, {10, 10})
iex> Macaw.Frame.Hooks.Zoom.transform_point({10, 10}, t)
{10, 10}

Summary

Types

A refusal: faults with their paths.

t()

A zoom transform: scale k and translation x, y.

Functions

The identity: %{k: 1, x: 0, y: 0}.

The point the transform takes to {x, y}; a transform of scale zero answers a fault.

The transform scaled by scale about {cx, cy}, which stays where it is.

A point under the transform: {x·k + tx, y·k + ty}.

The transform moved by {dx, dy}.

Types

error()

@type error() :: {:error, [Macaw.Base.Fault.t()]}

A refusal: faults with their paths.

t()

@type t() :: %{k: number(), x: number(), y: number()}

A zoom transform: scale k and translation x, y.

Functions

identity_transform()

@spec identity_transform() :: t()

The identity: %{k: 1, x: 0, y: 0}.

inverse_transform_point(p, t)

@spec inverse_transform_point({number(), number()}, t()) ::
  {number(), number()} | error()

The point the transform takes to {x, y}; a transform of scale zero answers a fault.

scale_transform(t, scale, c)

@spec scale_transform(t(), number(), {number(), number()}) :: t() | error()

The transform scaled by scale about {cx, cy}, which stays where it is.

transform_point(p, t)

@spec transform_point({number(), number()}, t()) :: {number(), number()} | error()

A point under the transform: {x·k + tx, y·k + ty}.

translate_transform(t, dx, dy)

@spec translate_transform(t(), number(), number()) :: t() | error()

The transform moved by {dx, dy}.