MCPcopy Create free account
hub / github.com/Notgnoshi/generative / new

Method new

generative/attractor.rs:41–74  ·  view source on GitHub ↗
(
        format: OutputFormat,
        output: Option<PathBuf>,
        expected_coords: usize,
        width: Option<u32>,
        height: Option<u32>,
    )

Source from the content-addressed store, hash-verified

39// public
40impl AttractorFormatter {
41 pub fn new(
42 format: OutputFormat,
43 output: Option<PathBuf>,
44 expected_coords: usize,
45 width: Option<u32>,
46 height: Option<u32>,
47 ) -> eyre::Result<Self> {
48 let writer: Box<dyn Write> = match &output {
49 Some(path) => {
50 if path == Path::new("-") {
51 Box::new(std::io::stdout())
52 } else {
53 let file = std::fs::File::create(path)?;
54 Box::new(file)
55 }
56 }
57 None => Box::new(std::io::stdout()),
58 };
59 let writer = BufWriter::new(writer);
60 let buffer_capacity = match format {
61 OutputFormat::Points | OutputFormat::Line => 1024,
62 OutputFormat::Image => expected_coords,
63 };
64 let accumulated = Vec::with_capacity(buffer_capacity);
65
66 Ok(Self {
67 format,
68 writer,
69 output,
70 accumulated,
71 width,
72 height,
73 })
74 }
75
76 pub fn handle_point(&mut self, x: f64, y: f64) -> eyre::Result<()> {
77 self.accumulate_coord(Coord { x, y })

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected