add rustfmt.toml

This commit is contained in:
Simon Gardling
2022-02-11 14:29:43 -05:00
parent 4e99bf651e
commit 7eb4008d15
3 changed files with 9 additions and 23 deletions

3
.rustfmt.toml Normal file
View File

@@ -0,0 +1,3 @@
edition = "2021"
fn_args_layout = "Compressed"
fn_single_line = true

View File

@@ -5,14 +5,8 @@ use plotters_canvas::CanvasBackend;
use web_sys::HtmlCanvasElement; use web_sys::HtmlCanvasElement;
pub fn draw( pub fn draw(
element: HtmlCanvasElement, element: HtmlCanvasElement, func_str: &str, min_x: f32, max_x: f32, min_y: f32, max_y: f32,
func_str: &str, num_interval: usize, resolution: i32,
min_x: f32,
max_x: f32,
min_y: f32,
max_y: f32,
num_interval: usize,
resolution: i32,
) -> DrawResult<(impl Fn((i32, i32)) -> Option<(f32, f32)>, f32)> { ) -> DrawResult<(impl Fn((i32, i32)) -> Option<(f32, f32)>, f32)> {
let expr: Expr = func_str.parse().unwrap(); let expr: Expr = func_str.parse().unwrap();
let func = expr.bind("x").unwrap(); let func = expr.bind("x").unwrap();
@@ -61,10 +55,7 @@ pub fn draw(
// 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
#[inline(always)] #[inline(always)]
fn integral_rectangles( fn integral_rectangles(
min_x: f32, min_x: f32, step: f32, num_interval: usize, func: &dyn Fn(f64) -> f64,
step: f32,
num_interval: usize,
func: &dyn Fn(f64) -> f64,
) -> (Vec<(f32, f32, f32)>, f32) { ) -> (Vec<(f32, f32, f32)>, f32) {
let mut area: f32 = 0.0; // sum of all rectangles' areas let mut area: f32 = 0.0; // sum of all rectangles' areas
let mut tmp1: f32; // Top left Y value that's tested let mut tmp1: f32; // Top left Y value that's tested

View File

@@ -23,14 +23,8 @@ pub struct Point {
#[wasm_bindgen] #[wasm_bindgen]
impl Chart { impl Chart {
pub fn draw( pub fn draw(
canvas: HtmlCanvasElement, canvas: HtmlCanvasElement, func_str: &str, min_x: f32, max_x: f32, min_y: f32, max_y: f32,
func_str: &str, num_interval: usize, resolution: i32,
min_x: f32,
max_x: f32,
min_y: f32,
max_y: f32,
num_interval: usize,
resolution: i32,
) -> Result<Chart, JsValue> { ) -> Result<Chart, JsValue> {
let draw_output = func_plot::draw( let draw_output = func_plot::draw(
canvas, canvas,
@@ -51,9 +45,7 @@ impl Chart {
}); });
} }
pub fn get_area(&self) -> f32 { pub fn get_area(&self) -> f32 { return self.area; }
return 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 { x, y }) (self.convert)((x, y)).map(|(x, y)| Point { x, y })