mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 07:18:04 +08:00
* Implement basic refactorings * Simplify some match statements * Rename `ix` to `index` If we're not going with a single letter name, then a full word makes more sense. * Rename `as_hex` to `to_hex` `as_` implies lossless reinterpretation while the function does a conversion that loses information * Replace `for_each` with for loops for loops are a lot easier to read and maintain. * factor out x and y coords in Line::render this is arguably more ergonomic * Remove redundant `format!(format_args!())`
29 lines
645 B
Rust
29 lines
645 B
Rust
use super::style;
|
|
use super::LayerData;
|
|
|
|
use std::fmt::Write;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
pub struct Line {
|
|
shape: kurbo::Line,
|
|
style: style::PathStyle,
|
|
}
|
|
|
|
impl Line {
|
|
pub fn new(p0: impl Into<kurbo::Point>, p1: impl Into<kurbo::Point>, style: style::PathStyle) -> Line {
|
|
Line {
|
|
shape: kurbo::Line::new(p0, p1),
|
|
style,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl LayerData for Line {
|
|
fn render(&mut self, svg: &mut String) {
|
|
let kurbo::Point { x: x1, y: y1 } = self.shape.p0;
|
|
let kurbo::Point { x: x2, y: y2 } = self.shape.p1;
|
|
|
|
let _ = write!(svg, r#"<line x1="{}" y1="{}" x2="{}" y2="{}" {} />"#, x1, y1, x2, y2, self.style.render(),);
|
|
}
|
|
}
|