refactoring
This commit is contained in:
30
src/misc.rs
Normal file
30
src/misc.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
pub type DrawResult<T> = Result<T, Box<dyn std::error::Error>>;
|
||||
|
||||
/// Result of screen to chart coordinates conversion.
|
||||
#[wasm_bindgen]
|
||||
pub struct Point {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Point {
|
||||
pub fn new(x: f32, y: f32) -> Self { Self { x, y } }
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct Chart {
|
||||
pub(crate) convert: Box<dyn Fn((i32, i32)) -> Option<(f32, f32)>>,
|
||||
pub(crate) area: f32,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Chart {
|
||||
pub fn get_area(&self) -> f32 { self.area }
|
||||
|
||||
pub fn coord(&self, x: i32, y: i32) -> Option<Point> {
|
||||
(self.convert)((x, y)).map(|(x, y)| Point::new(x, y))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user