Macaw.Draw.Shape.Arc (macaw_draw v0.1.0)

Copy Markdown View Source

An annular sector, d3-shape's arc (spec/07 §6), copied from visualize's Visualize.Shape.Arc.

Every parameter is an accessor evaluated against one datum (§1.1). Radii are user units; angles are radians clockwise from 12 o'clock. The path is about the origin; callers translate it. pad_angle narrows the sector at pad_radius (√(r0² + r1²) when nil), and corner_radius rounds its four corners with tangent arcs.

iex> alias Macaw.Draw.Shape.Arc
iex> Arc.new() |> Arc.inner_radius(50) |> Arc.generate(%{start_angle: 0, end_angle: :math.pi() / 2})
"M0,-100A100,100,0,0,1,100,0L50,0A50,50,0,0,0,0,-50Z"

new/0 reads the datum's :start_angle (0 when absent) and :end_angle (2π when absent), so a Macaw.Draw.Shape.Pie arc datum is consumed directly. A zero outer radius or extent, and a radius or angle that is not a number, is the empty path: nothing to draw.

Summary

Types

A refusal: faults with their paths.

t()

Functions

The {start, end} angles the accessors give for a datum; nil where one is no number.

{x, y} at mid-radius and mid-angle; padding and corners do not move it. nil when a radius or angle is no number.

Sets the corner_radius accessor: a function, a field, or a number.

Sets the end_angle accessor: a function, a field, or a number.

The SVG path data of a datum's arc.

The Macaw.Draw.IR.Path of a datum's arc (§6.2).

Sets the inner_radius accessor: a function, a field, or a number.

An arc of outer radius 100, its angles read from the datum.

Sets the outer_radius accessor: a function, a field, or a number.

Sets the pad_angle accessor: a function, a field, or a number.

Sets the radius at which the pad angle is measured: the linear gap is pad_radius · pad_angle on both rings. nil restores √(r0² + r1²).

The {inner, outer} radii the accessors give for a datum; nil where one is no number.

Sets the start_angle accessor: a function, a field, or a number.

Types

accessor()

@type accessor() :: (term() -> term()) | atom() | String.t() | number()

error()

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

A refusal: faults with their paths.

t()

@type t() :: %Macaw.Draw.Shape.Arc{
  corner_radius: (term() -> term()) | number(),
  end_angle: (term() -> term()) | nil,
  inner_radius: (term() -> term()) | number(),
  outer_radius: (term() -> term()) | nil,
  pad_angle: (term() -> term()) | number(),
  pad_radius: (term() -> term()) | nil,
  start_angle: (term() -> term()) | nil
}

Functions

angles(arc, datum)

@spec angles(t(), term()) :: {number() | nil, number() | nil} | error()

The {start, end} angles the accessors give for a datum; nil where one is no number.

centroid(arc, datum)

@spec centroid(t(), term()) :: {float(), float()} | nil | error()

{x, y} at mid-radius and mid-angle; padding and corners do not move it. nil when a radius or angle is no number.

corner_radius(arc, accessor)

@spec corner_radius(t(), accessor()) :: t() | error()

Sets the corner_radius accessor: a function, a field, or a number.

end_angle(arc, accessor)

@spec end_angle(t(), accessor()) :: t() | error()

Sets the end_angle accessor: a function, a field, or a number.

generate(arc, datum)

@spec generate(t(), term()) :: String.t() | error()

The SVG path data of a datum's arc.

generate_path(arc, datum)

@spec generate_path(t(), term()) :: Macaw.Draw.IR.Path.t() | error()

The Macaw.Draw.IR.Path of a datum's arc (§6.2).

inner_radius(arc, accessor)

@spec inner_radius(t(), accessor()) :: t() | error()

Sets the inner_radius accessor: a function, a field, or a number.

new()

@spec new() :: t()

An arc of outer radius 100, its angles read from the datum.

outer_radius(arc, accessor)

@spec outer_radius(t(), accessor()) :: t() | error()

Sets the outer_radius accessor: a function, a field, or a number.

pad_angle(arc, accessor)

@spec pad_angle(t(), accessor()) :: t() | error()

Sets the pad_angle accessor: a function, a field, or a number.

pad_radius(arc, radius)

@spec pad_radius(t(), accessor() | nil) :: t() | error()

Sets the radius at which the pad angle is measured: the linear gap is pad_radius · pad_angle on both rings. nil restores √(r0² + r1²).

radii(arc, datum)

@spec radii(t(), term()) :: {number() | nil, number() | nil} | error()

The {inner, outer} radii the accessors give for a datum; nil where one is no number.

start_angle(arc, accessor)

@spec start_angle(t(), accessor()) :: t() | error()

Sets the start_angle accessor: a function, a field, or a number.