Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom formatting to cli tessellate cmd #362

Merged
merged 1 commit into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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