Skip to content

Commit

Permalink
CLI tessellate command custom formatting
Browse files Browse the repository at this point in the history
Add --format flag to tessellate subcommand.
Update CLI readme.

Closes #289
  • Loading branch information
Roland Kovacs committed Jun 13, 2018
1 parent 395ef67 commit 204c6ad
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 35 deletions.
88 changes: 88 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ gfx = "0.17.1"
gfx_device_gl = "0.15.0"
gfx_window_glutin = "0.20.0"
glutin = "0.12.0"
itertools = "0.7.8"
regex = "1.0.0"
44 changes: 43 additions & 1 deletion cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Tessellates an SVG path. The output is a vertex buffer and an index buffer in te

Run ```$> lyon tessellate --help``` for more details.

### examples
### example

```
$> lyon tessellate "M 0 0 L 10 0 10 10 L 0 10 z"
Expand Down Expand Up @@ -58,6 +58,48 @@ indices: 6
triangles: 2
```

To specify the output format use ```--format <FORMAT_STRING>```.

There are 3 format markers, one for *vertices*, *indices* and for *triangles* (triplets of indices). Each format marker starts with ```@```, has a separator block (```{sep=...}```), a format block (```{fmt=...}``` and it ends with ```@```. In the blocks ```{``` and ```}``` characters have to be escaped!


#### list of format variables
- ```@vertices```
* ```{position.x}``` or ```{pos.x}```
* ```{position.y}``` or ```{pos.y}```
- ```@indices```
* ```{index}``` or ```{i}```
- ```@triangles```
* ```{index0}``` or ```{i0}```
* ```{index1}``` or ```{i1}```
* ```{index2}``` or ```{i2}```

#### examples

```
$> lyon tessellate --format "vertices: [@vertices{sep=, }{fmt=({position.x}, {position.y})}@]" "M 0 0 L 10 0 10 10 L 0 10 z"
vertices: [(0, 0), (10, 0), (0, 10), (10, 10)]
$> lyon tessellate --format "@indices{sep=, }{fmt=[{index}]}@" "M 0 0 L 10 0 10 10 L 0 10 z"
[0], [1], [2], [2], [1], [3]
$> lyon tessellate --format '\{\n "triangles": \{\n@triangles{sep=,\n}{fmt= "triangle": \{\n "{i0}",\n "{i1}",\n "{i2}"\n \}}@\n \}\n\}' "M 0 0 L 10 0 10 10 L 0 10 z"
{
"triangles": {
"triangle": {
"1",
"0",
"2"
},
"triangle": {
"1",
"2",
"3"
}
}
}
```

## ```show```

Opens a window with an interactive path viewer.
Expand Down
10 changes: 10 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ extern crate gfx;
extern crate gfx_window_glutin;
extern crate gfx_device_gl;
extern crate glutin;
extern crate regex;
extern crate itertools;

mod commands;
mod tessellate;
Expand Down Expand Up @@ -56,6 +58,13 @@ fn main() {
.takes_value(true)
.required(false)
)
.arg(Arg::with_name("FORMAT")
.long("format")
.help("Prints the output with the specified format")
.value_name("FORMAT_STRING")
.takes_value(true)
.required(false)
)
)
.subcommand(
declare_input_path(SubCommand::with_name("path"))
Expand Down Expand Up @@ -147,6 +156,7 @@ fn main() {
Ok(Ok(buffers)) => {
tessellate::write_output(buffers,
command.is_present("COUNT"),
command.value_of("FORMAT"),
float_precision,
output).unwrap();
}
Expand Down
Loading

0 comments on commit 204c6ad

Please sign in to comment.