Improve rendering efficiency and add caching (#95)

Fixes #84

*Reduce heap allocations
* Add caching for rendering svgs
* Deduplicate UpdateCanvas Responses
This commit is contained in:
TrueDoctor
2021-05-07 02:47:38 -07:00
committed by Keavon Chambers
parent 5f1620b008
commit cb9d34c84d
14 changed files with 123 additions and 73 deletions
+6 -3
View File
@@ -1,6 +1,8 @@
use super::style;
use super::LayerData;
use std::fmt::Write;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Line {
shape: kurbo::Line,
@@ -17,14 +19,15 @@ impl Line {
}
impl LayerData for Line {
fn render(&self) -> String {
format!(
fn render(&mut self, svg: &mut String) {
let _ = write!(
svg,
r#"<line x1="{}" y1="{}" x2="{}" y2="{}" {} />"#,
self.shape.p0.x,
self.shape.p0.y,
self.shape.p1.x,
self.shape.p1.y,
self.style.render(),
)
);
}
}