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

Function main

tools/grid.rs:573–682  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

571}
572
573fn main() -> eyre::Result<()> {
574 color_eyre::install()?;
575 let args = CmdlineOptions::parse();
576
577 let filter = tracing_subscriber::EnvFilter::builder()
578 .with_default_directive(args.log_level.into())
579 .from_env_lossy();
580 tracing_subscriber::fmt()
581 .with_env_filter(filter)
582 .with_ansi(true)
583 .with_writer(std::io::stderr)
584 .init();
585
586 // Exit early with a nice error message here, so that I can use unreachable!() later
587 if !cfg!(feature = "cxx-bindings")
588 && args.grid_type == GridType::Radial
589 && args.output_format == GridFormat::Graph
590 {
591 // No need to check if args.output_format == GridFormat::Cells, because that's hidden
592 // behind the cxx-bindings feature already.
593 eprintln!(
594 "Using the {} output format with radial grids requires the 'cxx-bindings' feature",
595 args.output_format
596 );
597 std::process::exit(1);
598 }
599
600 let (mut size_x, mut size_y) = if let Some(size) = args.size {
601 (size, size)
602 } else {
603 (1.0, 1.0)
604 };
605 if let Some(size) = args.size_x {
606 size_x = size;
607 }
608 if let Some(size) = args.size_y {
609 size_y = size;
610 }
611
612 let writer = get_output_writer(&args.output)?;
613
614 // Radial grids need to be created as geometry-first instead of grid-first, to enable
615 // outputting the radial spokes as LINESTRINGs, and the concentric rings as POLYGONs, which
616 // itself is desired, because it makes it possible to densify / smooth the rings separately
617 // from the spokes.
618 if args.grid_type == GridType::Radial {
619 let strategy = if let Some(points) = args.ring_fill_points {
620 FillStrategy::NumPoints(points)
621 } else if let Some(ratio) = args.ring_fill_ratio {
622 FillStrategy::RadiusRatio(ratio)
623 } else {
624 FillStrategy::None
625 };
626 let (spokes, rings) = radial_grid(args.width, args.height, size_y, strategy);
627 let spokes = spokes.into_iter().map(Geometry::LineString);
628 let rings = rings.into_iter().map(Geometry::Polygon);
629 let geoms = rings.chain(spokes);
630

Callers

nothing calls this directly

Calls 9

get_output_writerFunction · 0.85
radial_gridFunction · 0.85
write_geometriesFunction · 0.85
snap_geomsFunction · 0.85
write_graphFunction · 0.85
gridFunction · 0.85
PointClass · 0.50
nodeFunction · 0.50
polygonizeFunction · 0.50

Tested by

no test coverage detected