pub struct Dots { /* private fields */ }Expand description
A braille dot lattice: 2·w × 4·h square dots over a w × h cell region (CORE-R41).
Each cell stores its dot mask and one ink, that of its most intense lit dot (highest
level, or |level − 128| for Role::Div; ties go to the dot set last), since a
terminal cell has one colour.
Masks and inks are separate arrays so blit scans a dense byte array, which is
mostly zeros for sparse line art.
Implementations§
Source§impl Dots
impl Dots
Sourcepub const CELL_H: i32 = 4
pub const CELL_H: i32 = 4
Dots per cell vertically; CELL_H / CELL_W = ASPECT makes the dots square.
Sourcepub fn from_cells(x: f64, y: f64) -> (f64, f64)
pub fn from_cells(x: f64, y: f64) -> (f64, f64)
Dot coordinates of the continuous cell point (x, y), where cell i spans
[i, i + 1) (CORE-R64): dot j is centred at cell (j + ½) / CELL_W across and
(j + ½) / CELL_H down, so plot lights the dot whose area holds
the point, inside the cell that holds it. The one cell → dot convention for every
scene; a cell centre (cx + ½, cy + ½) maps to the middle of its 2×4 block.
Sourcepub fn dot_size(&self) -> Size
pub fn dot_size(&self) -> Size
Lattice dimensions in dots, 2·w × 4·h (saturated at u16::MAX per axis).
Sourcepub fn resize(&mut self, cells: Size)
pub fn resize(&mut self, cells: Size)
Resize to cells and clear. Reuses the buffers unless they must grow.
Sourcepub fn set(&mut self, x: i32, y: i32, ink: Ink)
pub fn set(&mut self, x: i32, y: i32, ink: Ink)
Light dot (x, y) with ink; off-lattice dots are ignored.
Sourcepub fn plot(&mut self, x: f64, y: f64, ink: Ink)
pub fn plot(&mut self, x: f64, y: f64, ink: Ink)
Light the dot nearest to (x, y) (dot units); non-finite or off-lattice points
are ignored, so simulation code never casts NaN to a coordinate.
Sourcepub fn stipple(&mut self, x: i32, y: i32, p: f64, salt: u64, ink: Ink)
pub fn stipple(&mut self, x: i32, y: i32, p: f64, salt: u64, ink: Ink)
Light dot (x, y) with ink when stipple_keep(salt, x, y, p) (CORE-R107): a
probability cloud sampled with fixed per-dot thresholds, as electron_orbitals’
clouds are. Off-lattice dots are ignored.
Sourcepub fn stipple_puff(
&mut self,
cx: f64,
cy: f64,
sigma: f64,
peak: f64,
salt: u64,
ink: Ink,
)
pub fn stipple_puff( &mut self, cx: f64, cy: f64, sigma: f64, peak: f64, salt: u64, ink: Ink, )
Light a small Gaussian stipple atom about (cx, cy) (dot units, CORE-R108): each dot
within 3σ is kept by stipple_keep at peak·e^(−r²/2σ²), and the dot nearest
the centre is always lit, so an atom never vanishes. The density only grows with
sigma and peak, so a swelling atom only gains dots. A non-finite or non-positive
sigma leaves just the centre dot; peak ≤ 0 or a non-finite centre lights nothing.
Sourcepub fn line(&mut self, x0: f64, y0: f64, x1: f64, y1: f64, ink: Ink)
pub fn line(&mut self, x0: f64, y0: f64, x1: f64, y1: f64, ink: Ink)
Light the Bresenham segment from (x0, y0) to (x1, y1) (dot units, rounded),
both endpoints inclusive, clipped to the lattice (CORE-R51). Non-finite endpoints
draw nothing, and the walk is capped at 4·(dot width + dot height) steps, so
wild coordinates stay cheap.
Sourcepub fn disc(&mut self, x: f64, y: f64, r: f64, ink: Ink)
pub fn disc(&mut self, x: f64, y: f64, r: f64, ink: Ink)
Light the filled disc of radius r (dot units, so round on screen) about (x, y):
every dot whose centre lies within r, plus the dot nearest the centre, so a
radius below ½ is one dot (CORE-R82). Clipped to the lattice; a non-finite centre
or radius, or r < 0, lights nothing. Bobs, suns and grains in line-art scenes.
Sourcepub fn contour(
&mut self,
values: &[f32],
w: usize,
h: usize,
level: f32,
to_dot: impl Fn(f64, f64) -> (f64, f64),
ink: Ink,
)
pub fn contour( &mut self, values: &[f32], w: usize, h: usize, level: f32, to_dot: impl Fn(f64, f64) -> (f64, f64), ink: Ink, )
Draw the iso-contour v = level of a row-major w × h node field, one dot thick,
by marching squares (CORE-R105). to_dot(x, y) maps continuous node coordinates
(node (i, j) at (i, j)) to dot coordinates. Too-short fields and w or h
below 2 draw nothing; nothing allocates.
Sourcepub fn contour_by(
&mut self,
values: &[f32],
w: usize,
h: usize,
level: f32,
to_dot: impl Fn(f64, f64) -> (f64, f64),
ink: impl FnMut(usize, usize) -> Option<Ink>,
)
pub fn contour_by( &mut self, values: &[f32], w: usize, h: usize, level: f32, to_dot: impl Fn(f64, f64) -> (f64, f64), ink: impl FnMut(usize, usize) -> Option<Ink>, )
contour with the ink chosen per cell of four nodes: ink(i, j)
is asked only for cells the level crosses ((i, j) the top-left node) and None
skips the cell, so a contour can be coloured by sign, age or a sampled variable.
Sourcepub fn contour_cell(
&mut self,
corners: [f32; 4],
level: f32,
(i, j): (usize, usize),
to_dot: impl Fn(f64, f64) -> (f64, f64),
ink: Ink,
)
pub fn contour_cell( &mut self, corners: [f32; 4], level: f32, (i, j): (usize, usize), to_dot: impl Fn(f64, f64) -> (f64, f64), ink: Ink, )
Draw the level set v = level inside one cell of four nodes (CORE-R105), for
scenes that cull cells themselves. corners are the values at nodes (i, j),
(i+1, j), (i+1, j+1), (i, j+1) (clockwise on screen); a node is below the level
when v < level. Each straddling edge’s crossing is linearly interpolated, and the
crossings are joined by line: two crossings make one piece, four (a
saddle) two, paired in edge order. Non-finite corners draw nothing.
Sourcepub fn contour_cell_refined(
&mut self,
corners: [f32; 4],
level: f32,
(i, j): (usize, usize),
k: usize,
to_dot: impl Fn(f64, f64) -> (f64, f64),
ink: Ink,
)
pub fn contour_cell_refined( &mut self, corners: [f32; 4], level: f32, (i, j): (usize, usize), k: usize, to_dot: impl Fn(f64, f64) -> (f64, f64), ink: Ink, )
contour_cell with the cell refined into k × k sub-cells
whose corners are bilinear in the four node values (CORE-R106): where one node
spans many dots the level set is traced as a smooth curve (the bilinear surface’s
own level set, to within 1/k of a cell) instead of one straight chord per cell.
k ≤ 1 is plain contour_cell; k is capped at 16. Sub-cells the level does not
cross are skipped; nothing allocates.
Sourcepub fn cell_mask(&self, cx: i32, cy: i32) -> Option<u8>
pub fn cell_mask(&self, cx: i32, cy: i32) -> Option<u8>
The dot mask of cell (cx, cy) (bit layout as braille; 0 = no dot lit), or
None off the region (CORE-R64).
Sourcepub fn blit(&self, canvas: &mut Canvas)
pub fn blit(&self, canvas: &mut Canvas)
Write every cell with at least one lit dot as its braille glyph (or the dot-count ASCII fallback) and ink; cells with no lit dots are left untouched, so a lattice layers over earlier drawing.
Sourcepub fn blit_over(&self, canvas: &mut Canvas, under: &Pixels)
pub fn blit_over(&self, canvas: &mut Canvas, under: &Pixels)
blit over a half-block layer (CORE-R84): each written cell gets
Pixels::cell_bg of under as its background, so a glow drawn as Pixels
carries on under a point cloud or a track instead of stopping at the first dotted
cell. under should cover the same cells; outside it the background is blank.
ASCII mode has no half blocks, so there it is plain blit.