wip
This commit is contained in:
parent
a563d7f0ea
commit
4b9e21c6a0
|
@ -1476,6 +1476,7 @@ name = "tile-svg"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"euclid 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"euclid 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"jemallocator 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"jemallocator 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lyon_geom 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lyon_geom 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -6,6 +6,7 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.0"
|
bitflags = "1.0"
|
||||||
|
clap = "2.32"
|
||||||
euclid = "0.19"
|
euclid = "0.19"
|
||||||
jemallocator = "0.1"
|
jemallocator = "0.1"
|
||||||
lyon_geom = "0.12"
|
lyon_geom = "0.12"
|
||||||
|
|
|
@ -16,6 +16,7 @@ extern crate quickcheck;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
|
||||||
|
use clap::{App, Arg};
|
||||||
use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D};
|
use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D};
|
||||||
use jemallocator;
|
use jemallocator;
|
||||||
use lyon_geom::cubic_bezier::Flattened;
|
use lyon_geom::cubic_bezier::Flattened;
|
||||||
|
@ -45,48 +46,38 @@ const SCALE_FACTOR: f32 = 8.0;
|
||||||
// TODO(pcwalton): Make this configurable.
|
// TODO(pcwalton): Make this configurable.
|
||||||
const FLATTENING_TOLERANCE: f32 = 3.0;
|
const FLATTENING_TOLERANCE: f32 = 3.0;
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct GroupStyle {
|
|
||||||
fill_color: Option<SvgColor>,
|
|
||||||
stroke_width: Option<f32>,
|
|
||||||
stroke_color: Option<SvgColor>,
|
|
||||||
transform: Option<Transform2D<f32>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct ComputedStyle {
|
|
||||||
fill_color: Option<SvgColor>,
|
|
||||||
stroke_width: f32,
|
|
||||||
stroke_color: Option<SvgColor>,
|
|
||||||
transform: Transform2D<f32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ComputedStyle {
|
|
||||||
fn new() -> ComputedStyle {
|
|
||||||
ComputedStyle {
|
|
||||||
fill_color: None,
|
|
||||||
stroke_width: 1.0,
|
|
||||||
stroke_color: None,
|
|
||||||
transform: Transform2D::identity(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let path = PathBuf::from(env::args().skip(1).next().unwrap());
|
let matches =
|
||||||
|
App::new("tile-svg").arg(Arg::with_name("runs").short("r")
|
||||||
|
.long("runs")
|
||||||
|
.value_name("COUNT")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("Run a benchmark with COUNT runs"))
|
||||||
|
.arg(Arg::with_name("INPUT").help("Path to the SVG file to render")
|
||||||
|
.required(true)
|
||||||
|
.index(1))
|
||||||
|
.arg(Arg::with_name("OUTPUT").help("Path to the output PF3 data")
|
||||||
|
.required(false)
|
||||||
|
.index(2))
|
||||||
|
.get_matches();
|
||||||
|
let runs: usize = match matches.value_of("runs") {
|
||||||
|
Some(runs) => runs.parse().unwrap(),
|
||||||
|
None => 1,
|
||||||
|
};
|
||||||
|
let path = PathBuf::from(matches.value_of("INPUT").unwrap());
|
||||||
|
|
||||||
let scene = Scene::from_path(&path);
|
let scene = Scene::from_path(&path);
|
||||||
println!("bounds: {:?}", scene.bounds);
|
println!("bounds: {:?}", scene.bounds);
|
||||||
|
|
||||||
const RUNS: u32 = 100;
|
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
let mut primitives = vec![];
|
let mut primitives = vec![];
|
||||||
for _ in 0..RUNS {
|
for _ in 0..runs {
|
||||||
primitives = scene.generate_tiles();
|
primitives = scene.generate_tiles();
|
||||||
}
|
}
|
||||||
let elapsed_time = Instant::now() - start_time;
|
let elapsed_time = Instant::now() - start_time;
|
||||||
let elapsed_ms = elapsed_time.as_secs() as f64 * 1000.0 +
|
let elapsed_ms = elapsed_time.as_secs() as f64 * 1000.0 +
|
||||||
elapsed_time.subsec_micros() as f64 / 1000.0;
|
elapsed_time.subsec_micros() as f64 / 1000.0;
|
||||||
println!("{}ms elapsed", elapsed_ms / RUNS as f64);
|
println!("{}ms elapsed", elapsed_ms / runs as f64);
|
||||||
println!("{} primitives generated", primitives.len());
|
println!("{} primitives generated", primitives.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +96,33 @@ struct PathObject {
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct ComputedStyle {
|
||||||
|
fill_color: Option<SvgColor>,
|
||||||
|
stroke_width: f32,
|
||||||
|
stroke_color: Option<SvgColor>,
|
||||||
|
transform: Transform2D<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct GroupStyle {
|
||||||
|
fill_color: Option<SvgColor>,
|
||||||
|
stroke_width: Option<f32>,
|
||||||
|
stroke_color: Option<SvgColor>,
|
||||||
|
transform: Option<Transform2D<f32>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ComputedStyle {
|
||||||
|
fn new() -> ComputedStyle {
|
||||||
|
ComputedStyle {
|
||||||
|
fill_color: None,
|
||||||
|
stroke_width: 1.0,
|
||||||
|
stroke_color: None,
|
||||||
|
transform: Transform2D::identity(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||||
struct StyleId(u32);
|
struct StyleId(u32);
|
||||||
|
|
||||||
|
@ -392,6 +410,10 @@ impl Outline {
|
||||||
fn segment_after(&self, endpoint_index: PointIndex) -> Segment {
|
fn segment_after(&self, endpoint_index: PointIndex) -> Segment {
|
||||||
self.contours[endpoint_index.contour_index].segment_after(endpoint_index.point_index)
|
self.contours[endpoint_index.contour_index].segment_after(endpoint_index.point_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_point(&self, index: PointIndex) -> &Point2D<f32> {
|
||||||
|
&self.contours[index.contour_index].points[index.point_index]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Contour {
|
impl Contour {
|
||||||
|
|
Loading…
Reference in New Issue