Smith.Render (Smith v0.3.0)

Copy Markdown View Source

Headless orthographic PNG observations of evaluated geometry.

Uses OCEx tessellation and an Elixir software depth buffer. It requires no browser, GPU, display server, Python, or Kino. Images are mesh observations, not metrology: use Smith.Measure and Smith.Inspection for BREP checks. Independent opaque layers support colored stage differences.

Summary

Functions

Renders a source, or a list of {source, rgb} layers, to a PNG binary.

Writes a PNG after successful rendering. The parent directory must exist; returns {:ok, path} or a tagged error.

Types

color()

@type color() :: {0..255, 0..255, 0..255}

source()

@type source() :: Smith.Measure.source() | [{Smith.Measure.source(), color()}]

view()

@type view() ::
  :isometric
  | :top
  | :bottom
  | :front
  | :back
  | :left
  | :right
  | Smith.Plane.t()

Functions

png(source, opts \\ [])

@spec png(source(), keyword()) :: {:ok, binary()} | {:error, term()}

Renders a source, or a list of {source, rgb} layers, to a PNG binary.

Options:

  • view: :isometric — named view or explicit Smith.Plane. Top looks from +Z, front from −Y, right from +X. Opposite views reverse those axes. Plane-local X is screen-right and local Y screen-up.
  • width: 640, height: 480 — integer pixel dimensions, 32–2048 each, with at most 2,097,152 pixels. The model fits with a 6% margin.
  • color: {62, 153, 183} — default surface RGB; explicit layers override it.
  • tolerance: 0.03, angular_tolerance: 0.3 — OCEx mesh deflections.
  • edges: false — draw sampled native edges with depth testing.
  • clip: {plane, :positive | :negative} — discard material on the other side for observation. Clipping does not cap the mesh or alter geometry; use Smith.section/2 for a measured section face.

Shading is flat, surfaces are opaque, and a depth buffer resolves visibility. PNG metadata records source revisions and view. Empty geometry returns :empty_shape. Invalid options return :invalid_options; geometry failures propagate. Rendering runs synchronously in the calling process.

write(source, path, opts \\ [])

@spec write(source(), String.t(), keyword()) :: {:ok, String.t()} | {:error, term()}

Writes a PNG after successful rendering. The parent directory must exist; returns {:ok, path} or a tagged error.