This commit is contained in:
Simon Gardling 2022-02-14 09:58:43 -05:00
parent 918bae6bec
commit 544989e4b2
2 changed files with 6 additions and 6 deletions

View File

@ -49,7 +49,7 @@ pub fn draw(
root.present()?; root.present()?;
let output = chart.into_coord_trans(); let output = chart.into_coord_trans();
return Ok((output, area)); Ok((output, area))
} }
// Creates and does the math for creating all the rectangles under the graph // Creates and does the math for creating all the rectangles under the graph
@ -83,5 +83,5 @@ fn integral_rectangles(
.filter(|ele| ele != &(0.0, 0.0, 0.0)) .filter(|ele| ele != &(0.0, 0.0, 0.0))
.collect(); .collect();
let area: f32 = data2.iter().map(|(_, _, y)| y * step).sum(); // sum of all rectangles' areas let area: f32 = data2.iter().map(|(_, _, y)| y * step).sum(); // sum of all rectangles' areas
return (data2, area); (data2, area)
} }

View File

@ -44,13 +44,13 @@ impl Chart {
.map_err(|err| err.to_string())?; .map_err(|err| err.to_string())?;
let map_coord = draw_output.0; let map_coord = draw_output.0;
return Ok(Chart { Ok(Chart {
convert: Box::new(move |coord| map_coord(coord).map(|(x, y)| (x.into(), y.into()))), convert: Box::new(move |coord| map_coord(coord).map(|(x, y)| (x, y))),
area: draw_output.1, area: draw_output.1,
}); })
} }
pub fn get_area(&self) -> f32 { return self.area; } pub fn get_area(&self) -> f32 { self.area }
pub fn coord(&self, x: i32, y: i32) -> Option<Point> { pub fn coord(&self, x: i32, y: i32) -> Option<Point> {
(self.convert)((x, y)).map(|(x, y)| Point::new(x, y)) (self.convert)((x, y)).map(|(x, y)| Point::new(x, y))