introduce Line and Circle
parent
12f8f86a37
commit
9b2845ca51
@ -1,15 +1,15 @@
|
|||||||
use std::f64;
|
use std::f64;
|
||||||
use crate::shapes::Point;
|
use crate::shapes::*;
|
||||||
|
|
||||||
pub fn draw_circle(center: Point, radius: f64, context: &web_sys::CanvasRenderingContext2d) {
|
pub fn draw_circle(circle: Circle, context: &web_sys::CanvasRenderingContext2d) {
|
||||||
context.move_to(center.x+radius, center.y);
|
context.move_to(circle.center.x+circle.radius, circle.center.y);
|
||||||
context
|
context
|
||||||
.arc(center.x, center.y, radius, 0.0, f64::consts::PI * 2.0)
|
.arc(circle.center.x, circle.center.y, circle.radius, 0.0, f64::consts::PI * 2.0)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_line(p1: Point, p2: Point, context: &web_sys::CanvasRenderingContext2d) {
|
pub fn draw_line(line: Line, context: &web_sys::CanvasRenderingContext2d) {
|
||||||
context.move_to(p1.x, p1.y);
|
context.move_to(line.p1.x, line.p1.y);
|
||||||
context
|
context
|
||||||
.line_to(p2.x, p2.y);
|
.line_to(line.p2.x, line.p2.y);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue