Function -> FunctionEntry
This commit is contained in:
parent
2e55768972
commit
5e9328ce85
@ -1,4 +1,4 @@
|
|||||||
use crate::function::{Function, RiemannSum};
|
use crate::function::{FunctionEntry, RiemannSum};
|
||||||
use crate::misc::{add_asterisks, digits_precision, test_func};
|
use crate::misc::{add_asterisks, digits_precision, test_func};
|
||||||
use const_format::formatc;
|
use const_format::formatc;
|
||||||
use eframe::{egui, epi};
|
use eframe::{egui, epi};
|
||||||
@ -130,7 +130,7 @@ impl Default for AppSettings {
|
|||||||
|
|
||||||
pub struct MathApp {
|
pub struct MathApp {
|
||||||
// Stores vector of functions
|
// Stores vector of functions
|
||||||
functions: Vec<Function>,
|
functions: Vec<FunctionEntry>,
|
||||||
|
|
||||||
// Stores vector containing the string representation of the functions. This is used because of hacky reasons
|
// Stores vector containing the string representation of the functions. This is used because of hacky reasons
|
||||||
func_strs: Vec<String>,
|
func_strs: Vec<String>,
|
||||||
@ -151,7 +151,7 @@ pub struct MathApp {
|
|||||||
impl Default for MathApp {
|
impl Default for MathApp {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
functions: vec![Function::empty().integral(true)],
|
functions: vec![FunctionEntry::empty().integral(true)],
|
||||||
func_strs: vec![String::from(DEFAULT_FUNCION)],
|
func_strs: vec![String::from(DEFAULT_FUNCION)],
|
||||||
last_error: String::new(),
|
last_error: String::new(),
|
||||||
font: FontData::from_static(&FONT_FILE),
|
font: FontData::from_static(&FONT_FILE),
|
||||||
@ -363,7 +363,7 @@ impl epi::App for MathApp {
|
|||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
self.functions
|
self.functions
|
||||||
.push(Function::empty().update_riemann(self.settings.sum));
|
.push(FunctionEntry::empty().update_riemann(self.settings.sum));
|
||||||
self.func_strs.push(String::new());
|
self.func_strs.push(String::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ impl fmt::Display for RiemannSum {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) }
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Function {
|
pub struct FunctionEntry {
|
||||||
function: BackingFunction,
|
function: BackingFunction,
|
||||||
func_str: String,
|
func_str: String,
|
||||||
min_x: f64,
|
min_x: f64,
|
||||||
@ -44,7 +44,7 @@ pub struct Function {
|
|||||||
// x^2 function, set here so we don't have to regenerate it every time a new function is made
|
// x^2 function, set here so we don't have to regenerate it every time a new function is made
|
||||||
fn default_function(x: f64) -> f64 { x.powi(2) }
|
fn default_function(x: f64) -> f64 { x.powi(2) }
|
||||||
|
|
||||||
impl Function {
|
impl FunctionEntry {
|
||||||
// Creates Empty Function instance
|
// Creates Empty Function instance
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -324,7 +324,7 @@ fn left_function_test() {
|
|||||||
let integral_num = 10;
|
let integral_num = 10;
|
||||||
let pixel_width = 10;
|
let pixel_width = 10;
|
||||||
|
|
||||||
let mut function = Function::empty()
|
let mut function = FunctionEntry::empty()
|
||||||
.update_riemann(RiemannSum::Left)
|
.update_riemann(RiemannSum::Left)
|
||||||
.pixel_width(pixel_width)
|
.pixel_width(pixel_width)
|
||||||
.integral_num(integral_num)
|
.integral_num(integral_num)
|
||||||
@ -447,7 +447,7 @@ fn middle_function_test() {
|
|||||||
let integral_num = 10;
|
let integral_num = 10;
|
||||||
let pixel_width = 10;
|
let pixel_width = 10;
|
||||||
|
|
||||||
let mut function = Function::empty()
|
let mut function = FunctionEntry::empty()
|
||||||
.update_riemann(RiemannSum::Middle)
|
.update_riemann(RiemannSum::Middle)
|
||||||
.pixel_width(pixel_width)
|
.pixel_width(pixel_width)
|
||||||
.integral_num(integral_num)
|
.integral_num(integral_num)
|
||||||
@ -570,7 +570,7 @@ fn right_function_test() {
|
|||||||
let integral_num = 10;
|
let integral_num = 10;
|
||||||
let pixel_width = 10;
|
let pixel_width = 10;
|
||||||
|
|
||||||
let mut function = Function::empty()
|
let mut function = FunctionEntry::empty()
|
||||||
.update_riemann(RiemannSum::Right)
|
.update_riemann(RiemannSum::Right)
|
||||||
.pixel_width(pixel_width)
|
.pixel_width(pixel_width)
|
||||||
.integral_num(integral_num)
|
.integral_num(integral_num)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user