Skip to main content

Geodesic

Struct Geodesic 

Source
pub struct Geodesic {
    pub start: StartHint,
    pub bridge: u16,
}
Expand description

Reveal by tracing the art’s skeleton.

The ink is first thinned to a one-cell-wide skeleton (Zhang-Suen), the centerline a pen would draw. Each connected piece of that skeleton is traced tip to tip by geodesic distance, a double breadth-first sweep finding the two ends of its longest path, and the pieces are ordered along the art’s dominant axis. So a snake paints head to tail, a filled dragon paints down its spine, and a multi-letter logo paints letter by letter in reading order, with no per-art tuning.

Hand-drawn ASCII is usually many separate strokes, not one connected line, so the trace bridges small gaps to stitch a broken stroke into one piece; art that is already whole is traced strictly, with no shortcuts (see Geodesic::bridge).

The flesh around the skeleton inherits the value of its nearest centerline cell, a Voronoi flood, so detail reveals in step with the part of the spine it hangs from; where the skeleton is a mere dot, as in a solid blob, the fill radiates out from the middle. Finally the values are rank-transformed to evenly spaced ranks, so the reveal keeps its order yet tracks the progress bar with no dead zone at either end.

Fields§

§start: StartHint

Which tip of the spine the reveal begins from.

§bridge: u16

The largest gap, in blank cells, the spine may step across. Bridging only engages when the art is actually fragmented (see [Spine::solve]), so it stitches the separate strokes of hand-drawn ASCII into one body without ever adding shortcuts to art that was already connected. 0 disables it.

Implementations§

Source§

impl Geodesic

Source

pub fn diagnose(&self, art: &Art) -> GeodesicReport

Inspect the art without building a full rank map.

Examples found in repository?
examples/dragon.rs (line 40)
20fn main() {
21    let args: Vec<String> = std::env::args().skip(1).collect();
22    let snapshots = args.iter().any(|a| a == "--snapshots");
23
24    let art = match arg_value(&args, "--art") {
25        Some(path) => match std::fs::read_to_string(&path) {
26            Ok(text) => Art::parse(&text),
27            Err(e) => {
28                eprintln!("inkling: could not read {path}: {e}");
29                std::process::exit(1);
30            }
31        },
32        None => Art::parse(&serpent(64, 13)),
33    };
34
35    let ordering = Geodesic::default();
36    let GeodesicReport {
37        ink_cells,
38        connected_cells,
39        spine_length,
40    } = ordering.diagnose(&art);
41    let ranks = ordering.rank(&art);
42
43    eprintln!(
44        "inkling · {ink_cells} ink cells · {connected_cells} on the spine \
45         ({:.0}% connected) · spine length {spine_length}",
46        100.0 * connected_cells as f32 / ink_cells.max(1) as f32,
47    );
48
49    // Headless / piped / explicit: print staged text frames and exit.
50    if snapshots || !std::io::stdout().is_terminal() {
51        for p in [0.0, 0.2, 0.4, 0.6, 0.8, 1.0] {
52            println!("\n── progress {:>3.0}% {}", p * 100.0, "─".repeat(28));
53            print!("{}", frame::to_string(&art, &ranks, p));
54        }
55        return;
56    }
57
58    #[cfg(feature = "terminal")]
59    {
60        use inkling::{
61            easing::Easing,
62            render::{animate, Style},
63        };
64        use std::time::Duration;
65        if let Err(e) = animate(
66            &art,
67            &ranks,
68            Style::default(),
69            Duration::from_millis(3500),
70            Easing::EaseInOutCubic,
71        ) {
72            eprintln!("inkling: render error: {e}");
73        }
74    }
75}

Trait Implementations§

Source§

impl Clone for Geodesic

Source§

fn clone(&self) -> Geodesic

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Geodesic

Source§

impl Debug for Geodesic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Geodesic

Source§

fn default() -> Self

Start at the top-left tip and bridge single-cell gaps when the art is fragmented, which is what most hand-drawn ASCII needs.

Source§

impl Ordering for Geodesic

Source§

fn rank(&self, art: &Art) -> RankMap

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.