fix build and add test for newtons_method

This commit is contained in:
Simon Gardling 2022-05-18 14:52:03 -04:00
parent db68d5e23a
commit e7e82a72b2
4 changed files with 21 additions and 7 deletions

12
Cargo.lock generated
View File

@ -659,7 +659,7 @@ checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541"
[[package]]
name = "eframe"
version = "0.18.0"
source = "git+https://github.com/Titaniumtown/egui.git#537c879b1c5a40384188dcc731a6d55c04deb99f"
source = "git+https://github.com/Titaniumtown/egui.git#ea25cc1a991610099ada8fe02f1c11ba708f77fd"
dependencies = [
"bytemuck",
"egui",
@ -679,7 +679,7 @@ dependencies = [
[[package]]
name = "egui"
version = "0.18.1"
source = "git+https://github.com/Titaniumtown/egui.git#537c879b1c5a40384188dcc731a6d55c04deb99f"
source = "git+https://github.com/Titaniumtown/egui.git#ea25cc1a991610099ada8fe02f1c11ba708f77fd"
dependencies = [
"ahash",
"epaint",
@ -691,7 +691,7 @@ dependencies = [
[[package]]
name = "egui-winit"
version = "0.18.0"
source = "git+https://github.com/Titaniumtown/egui.git#537c879b1c5a40384188dcc731a6d55c04deb99f"
source = "git+https://github.com/Titaniumtown/egui.git#ea25cc1a991610099ada8fe02f1c11ba708f77fd"
dependencies = [
"arboard",
"egui",
@ -705,7 +705,7 @@ dependencies = [
[[package]]
name = "egui_glow"
version = "0.18.1"
source = "git+https://github.com/Titaniumtown/egui.git#537c879b1c5a40384188dcc731a6d55c04deb99f"
source = "git+https://github.com/Titaniumtown/egui.git#ea25cc1a991610099ada8fe02f1c11ba708f77fd"
dependencies = [
"bytemuck",
"egui",
@ -725,7 +725,7 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "emath"
version = "0.18.0"
source = "git+https://github.com/Titaniumtown/egui.git#537c879b1c5a40384188dcc731a6d55c04deb99f"
source = "git+https://github.com/Titaniumtown/egui.git#ea25cc1a991610099ada8fe02f1c11ba708f77fd"
dependencies = [
"bytemuck",
"serde",
@ -734,7 +734,7 @@ dependencies = [
[[package]]
name = "epaint"
version = "0.18.1"
source = "git+https://github.com/Titaniumtown/egui.git#537c879b1c5a40384188dcc731a6d55c04deb99f"
source = "git+https://github.com/Titaniumtown/egui.git#ea25cc1a991610099ada8fe02f1c11ba708f77fd"
dependencies = [
"ab_glyph",
"ahash",

View File

@ -31,6 +31,7 @@ pub use crate::{
// decimal_round,
hashed_storage_create,
hashed_storage_read,
newtons_method,
option_vec_printer,
step_helper,
EguiHelper,

View File

@ -247,7 +247,7 @@ pub fn newtons_method_helper(
/// `f` is f(x)
/// `f_1` is f'(x) aka the derivative of f(x)
/// The function returns an `Option<f64>` of the x value at which a root occurs
fn newtons_method(
pub fn newtons_method(
f: &dyn Fn(f64) -> f64, f_1: &dyn Fn(f64) -> f64, start_x: &f64, range: &std::ops::Range<f64>,
threshold: &f64,
) -> Option<f64> {

View File

@ -162,3 +162,16 @@ fn to_points() {
assert_eq!(*data.get_series().get_values(), data_raw);
}
#[test]
fn newtons_method() {
use ytbn_graphing_software::newtons_method;
let data = newtons_method(
&|x: f64| x.powf(2.0) - 1.0,
&|x: f64| 2.0 * x,
&3.0,
&(0.0..10.0),
&f64::EPSILON,
);
assert_eq!(data, Some(1.0));
}