diff --git a/src/drawing.rs b/src/drawing.rs index d3284ad..b2a5811 100644 --- a/src/drawing.rs +++ b/src/drawing.rs @@ -1,16 +1,15 @@ use std::f64; - -pub struct Point(pub f64, pub f64); +use crate::shapes::Point; pub fn draw_circle(center: Point, radius: f64, context: &web_sys::CanvasRenderingContext2d) { - context.move_to(center.0+radius, center.1); + context.move_to(center.x+radius, center.y); context - .arc(center.0, center.1, radius, 0.0, f64::consts::PI * 2.0) + .arc(center.x, center.y, radius, 0.0, f64::consts::PI * 2.0) .unwrap(); } pub fn draw_line(p1: Point, p2: Point, context: &web_sys::CanvasRenderingContext2d) { - context.move_to(p1.0, p1.1); + context.move_to(p1.x, p1.y); context - .line_to(p2.0, p2.1); + .line_to(p2.x, p2.y); } diff --git a/src/lib.rs b/src/lib.rs index bed845a..b971834 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,10 @@ use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; -pub mod drawing; -use drawing::Point; + +mod drawing; +mod shapes; + +use shapes::Point; #[wasm_bindgen(start)] pub fn start() { @@ -21,12 +24,12 @@ pub fn start() { context.begin_path(); - drawing::draw_circle(Point(75.0, 75.0), 70.0, &context); - drawing::draw_circle(Point(75.0, 75.0), 35.0, &context); - drawing::draw_circle(Point(60.0, 65.0), 5.0, &context); + drawing::draw_circle(Point {x: 75.0, y: 75.0}, 70.0, &context); + drawing::draw_circle(Point {x: 75.0, y: 75.0}, 35.0, &context); + drawing::draw_circle(Point {x: 60.0, y: 65.0}, 5.0, &context); - drawing::draw_line(Point(0.0, 0.0), Point(150.0, 150.0), &context); - drawing::draw_line(Point(0.0, 150.0), Point(150.0, 0.0), &context); + drawing::draw_line(Point {x: 0.0, y: 0.0}, Point {x: 150.0, y: 150.0}, &context); + drawing::draw_line(Point {x: 0.0, y: 150.0}, Point {x: 150.0, y: 0.0}, &context); context.stroke(); } diff --git a/src/shapes.rs b/src/shapes.rs new file mode 100644 index 0000000..e22a300 --- /dev/null +++ b/src/shapes.rs @@ -0,0 +1,9 @@ +pub struct Point { + pub x: f64, + pub y: f64, +} + +pub struct Circle { + pub center: Point, + pub radius: f64, +}