rustfmt
This commit is contained in:
parent
19e73b070a
commit
95a0a8b194
@ -57,29 +57,32 @@ pub fn draw(
|
|||||||
fn integral_rectangles(
|
fn integral_rectangles(
|
||||||
min_x: f32, step: f32, num_interval: usize, func: &dyn Fn(f64) -> f64,
|
min_x: f32, step: f32, num_interval: usize, func: &dyn Fn(f64) -> f64,
|
||||||
) -> (Vec<(f32, f32, f32)>, f32) {
|
) -> (Vec<(f32, f32, f32)>, f32) {
|
||||||
let data2: Vec<(f32, f32, f32)> = (0..num_interval).map(|e| {
|
let data2: Vec<(f32, f32, f32)> = (0..num_interval)
|
||||||
let x: f32 = ((e as f32) * step) + min_x;
|
.map(|e| {
|
||||||
|
let x: f32 = ((e as f32) * step) + min_x;
|
||||||
|
|
||||||
let x2: f32 = match x > 0.1 {
|
let x2: f32 = match x > 0.1 {
|
||||||
true => x+step,
|
true => x + step,
|
||||||
false => x-step,
|
false => x - step,
|
||||||
};
|
};
|
||||||
|
|
||||||
let tmp1: f32 = func(x as f64) as f32;
|
let tmp1: f32 = func(x as f64) as f32;
|
||||||
let tmp2: f32 = func(x2 as f64) as f32;
|
let tmp2: f32 = func(x2 as f64) as f32;
|
||||||
|
|
||||||
let y: f32 = match tmp2.abs() > tmp1.abs() {
|
let y: f32 = match tmp2.abs() > tmp1.abs() {
|
||||||
true => tmp1,
|
true => tmp1,
|
||||||
false => tmp2
|
false => tmp2,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add current rectangle's area to the total
|
// Add current rectangle's area to the total
|
||||||
if !y.is_nan() {
|
if !y.is_nan() {
|
||||||
(x, x2, y)
|
(x, x2, y)
|
||||||
} else {
|
} else {
|
||||||
(0.0, 0.0, 0.0)
|
(0.0, 0.0, 0.0)
|
||||||
}
|
}
|
||||||
}).filter(|ele| ele != &(0.0, 0.0, 0.0)).collect();
|
})
|
||||||
let area: f32 = data2.iter().map(|(_, _, y)| y*step).sum(); // sum of all rectangles' areas
|
.filter(|ele| ele != &(0.0, 0.0, 0.0))
|
||||||
|
.collect();
|
||||||
|
let area: f32 = data2.iter().map(|(_, _, y)| y * step).sum(); // sum of all rectangles' areas
|
||||||
return (data2, area);
|
return (data2, area);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user