refactoring

This commit is contained in:
Simon Gardling 2022-02-14 09:49:20 -05:00
parent 95a0a8b194
commit 2e0aecd892

View File

@ -7,12 +7,6 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
pub type DrawResult<T> = Result<T, Box<dyn std::error::Error>>;
#[wasm_bindgen]
pub struct Chart {
convert: Box<dyn Fn((i32, i32)) -> 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<dyn Fn((i32, i32)) -> 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<Point> {
(self.convert)((x, y)).map(|(x, y)| Point { x, y })
(self.convert)((x, y)).map(|(x, y)| Point::new(x, y))
}
}