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

Function main

tools/transform.rs:277–337  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

275}
276
277fn main() -> eyre::Result<()> {
278 color_eyre::install()?;
279 let args = CmdlineOptions::parse();
280 if !args.range1.is_empty() && args.range1.len() != 2 {
281 eyre::bail!("--range1 must have 2 comma-separated values");
282 }
283 if !args.range2.is_empty() && args.range2.len() != 2 {
284 eyre::bail!("--range2 must have 2 comma-separated values");
285 }
286
287 let filter = tracing_subscriber::EnvFilter::builder()
288 .with_default_directive(args.log_level.into())
289 .from_env_lossy();
290 tracing_subscriber::fmt()
291 .with_env_filter(filter)
292 .with_ansi(true)
293 .with_writer(std::io::stderr)
294 .init();
295
296 let reader = get_input_reader(&args.input)?;
297 let writer = get_output_writer(&args.output)?;
298 let geometries = read_geometries(reader);
299 let mut transformed = affine_transform(geometries, &args);
300
301 if args.range1.len() == 2 || args.range2.len() == 2 {
302 let geometries: Vec<_> = transformed.collect();
303 let bounds = bounding_box(&geometries);
304
305 let mut x_dst = None;
306 let mut y_dst = None;
307 if args.range1.len() == 2 {
308 let dst = [args.range1[0], args.range1[1]];
309 x_dst = Some(dst);
310 }
311 if args.range2.len() == 2 {
312 // If we're converting from polar, then the "y" coordinate is actually theta.
313 // Use degrees in the CLI args, because it's waaaay easier to do "0 360" than it is
314 // "0 2PI"
315 let dst = if args.from_polar {
316 [args.range2[0].to_radians(), args.range2[1].to_radians()]
317 } else {
318 [args.range2[0], args.range2[1]]
319 };
320 y_dst = Some(dst);
321 }
322
323 let scaled: Vec<_> = geoms_coordwise(geometries.into_iter(), |coord| {
324 scale_coord_range(&bounds, x_dst.as_ref(), y_dst.as_ref(), coord)
325 })
326 .collect();
327 transformed = Box::new(scaled.into_iter());
328 }
329
330 if args.to_polar {
331 transformed = Box::new(geoms_coordwise(transformed, to_polar));
332 } else if args.from_polar {
333 transformed = Box::new(geoms_coordwise(transformed, from_polar));
334 }

Callers

nothing calls this directly

Calls 8

get_input_readerFunction · 0.85
get_output_writerFunction · 0.85
read_geometriesFunction · 0.85
affine_transformFunction · 0.85
geoms_coordwiseFunction · 0.85
scale_coord_rangeFunction · 0.85
write_geometriesFunction · 0.85
bounding_boxFunction · 0.70

Tested by

no test coverage detected