use super::painter::Painter;
#[derive(Debug, Clone, Copy)]
pub struct LineSegment {
pub x1: f64,
pub y1: f64,
pub x2: f64,
pub y2: f64,
}
#[derive(Debug, Clone, Copy)]
pub struct CircleBatch {
pub cx: f64,
pub cy: f64,
pub r: f64,
}
pub trait BatchPainter: Painter {
fn draw_line_batch(&mut self, lines: &[LineSegment], color: &str, width: f64) {
if lines.is_empty() {
return;
}
self.set_stroke_color(color);
self.set_stroke_width(width);
for l in lines {
self.begin_path();
self.move_to(l.x1, l.y1);
self.line_to(l.x2, l.y2);
self.stroke();
}
}
fn draw_circle_batch(&mut self, circles: &[CircleBatch], color: &str) {
if circles.is_empty() {
return;
}
self.set_fill_color(color);
for c in circles {
self.begin_path();
self.arc(c.cx, c.cy, c.r, 0.0, std::f64::consts::TAU);
self.fill();
}
}
fn stroke_polyline(&mut self, pts: &[(f64, f64)], color: &str, width: f64) {
if pts.is_empty() {
return;
}
self.set_stroke_color(color);
self.set_stroke_width(width);
self.begin_path();
self.move_to(pts[0].0, pts[0].1);
for &(x, y) in &pts[1..] {
self.line_to(x, y);
}
self.stroke();
}
}