refactoring
This commit is contained in:
parent
95a0a8b194
commit
2e0aecd892
19
src/lib.rs
19
src/lib.rs
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user