-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Start brainstorming transform tool
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use clap::{Parser, ValueEnum}; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Debug, Clone, ValueEnum)] | ||
pub enum GeometryFormat { | ||
Wkt, | ||
WkbHex, | ||
} | ||
|
||
#[derive(Debug, Clone, ValueEnum)] | ||
pub enum Projection { | ||
Xy, | ||
Xz, | ||
Yz, | ||
Pca, | ||
Svd, | ||
Identity, | ||
Isometric, | ||
} | ||
|
||
/// Perform transformations on geometries | ||
#[derive(Debug, Parser)] | ||
#[clap(name = "transform")] | ||
pub struct CmdlineOptions { | ||
/// Increase logging verbosity. Defaults to ERROR level. | ||
#[clap(short, long, action = clap::ArgAction::Count)] | ||
pub verbosity: u8, | ||
|
||
/// Output file to write result to. Defaults to stdout. | ||
#[clap(short, long)] | ||
pub output: Option<PathBuf>, | ||
|
||
/// Output geometry format. | ||
#[clap(short = 'O', long, default_value = "wkt")] | ||
pub output_format: GeometryFormat, | ||
|
||
/// Input file to read input from. Defaults to stdin. | ||
#[clap(short, long)] | ||
pub input: Option<PathBuf>, | ||
|
||
/// Input geometry format. | ||
#[clap(short = 'I', long, default_value = "wkt")] | ||
pub input_format: GeometryFormat, | ||
|
||
/// CCW rotation, in degrees. | ||
#[clap(short, long, default_value = "0.0")] | ||
pub rotation: f64, | ||
|
||
/// Additive offset in the x direction | ||
#[clap(long, default_value = "0.0")] | ||
pub x_offset: f64, | ||
|
||
/// Additive offset in the y direction | ||
#[clap(long, default_value = "0.0")] | ||
pub y_offset: f64, | ||
|
||
/// Multiplicative scale in the x direction | ||
#[clap(short, long, default_value = "1.0")] | ||
pub x_scale: f64, | ||
|
||
/// Multiplicative scale in the y direction | ||
#[clap(short, long, default_value = "1.0")] | ||
pub y_scale: f64, | ||
// TODO: Add projections | ||
// pub projection: Projection, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
mod cmdline; | ||
|
||
use clap::Parser; | ||
use generative::stdio::{get_input_reader, get_output_writer}; | ||
use generative::wkio::{read_wkt_geometries, write_wkt_geometries}; | ||
use stderrlog::ColorChoice; | ||
|
||
fn main() { | ||
let args = cmdline::CmdlineOptions::parse(); | ||
|
||
stderrlog::new() | ||
.verbosity(args.verbosity as usize + 1) // Default to WARN level. | ||
.color(ColorChoice::Auto) | ||
.init() | ||
.expect("Failed to initialize stderrlog"); | ||
|
||
let writer = get_output_writer(args.output).unwrap(); | ||
let reader = get_input_reader(args.input).unwrap(); | ||
|
||
let geometries = read_wkt_geometries(reader); | ||
write_wkt_geometries(writer, geometries); | ||
|
||
// TODO: I don't think there needs to be any flattening | ||
// * linear transforms can be done with the MapCoordsInplace trait on-the-fly | ||
// * projections can be done by collecting CoordsIter into an array, performing the projection, | ||
// and running back over the geometries with MapCoordsInplace to replace the coordinates. | ||
// In either case, I don't think there needs to be a recursive flattener, or a flattened and | ||
// tagged point array. | ||
|
||
// TODO: Describe the offset, scale, and rotate as a linear transformation. | ||
// TODO: Determe if it's more efficient (with my problem size) to do it on-the-fly or all at once. | ||
// TODO: Perhaps allow switching between buffered and dynamic approaches? Or perhaps chunk the | ||
// transformations? | ||
// TODO: Projections | ||
// TODO: WKB I/O | ||
} |