From 2e0aecd892adc30304fcd2178822e777c02c17b3 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Mon, 14 Feb 2022 09:49:20 -0500 Subject: [PATCH] refactoring --- src/lib.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 978985a..446c216 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,12 +7,6 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; pub type DrawResult = Result>; -#[wasm_bindgen] -pub struct Chart { - convert: Box Option<(f32, f32)>>, - area: f32, -} - /// Result of screen to chart coordinates conversion. #[wasm_bindgen] pub struct Point { @@ -20,6 +14,17 @@ pub struct Point { pub y: f32, } +#[wasm_bindgen] +impl Point { + pub fn new(x: f32, y: f32) -> Self { Self { x, y } } +} + +#[wasm_bindgen] +pub struct Chart { + convert: Box Option<(f32, f32)>>, + area: f32, +} + #[wasm_bindgen] impl Chart { pub fn draw( @@ -48,6 +53,6 @@ impl Chart { pub fn get_area(&self) -> f32 { return self.area; } pub fn coord(&self, x: i32, y: i32) -> Option { - (self.convert)((x, y)).map(|(x, y)| Point { x, y }) + (self.convert)((x, y)).map(|(x, y)| Point::new(x, y)) } }