small code changes

This commit is contained in:
Simon Gardling 2022-03-26 00:52:38 -04:00
parent 723d61d1b5
commit 848588e29d
4 changed files with 33 additions and 25 deletions

View File

@ -1,6 +1,20 @@
use crate::function::Riemann;
use std::ops::RangeInclusive;
use const_format::formatc;
use shadow_rs::shadow;
shadow!(build);
// Constant string that has a string containing information about the build.
pub const BUILD_INFO: &str = formatc!(
"Commit: {} ({})\nBuild Date: {}\nRust Channel: {}\nRust Version: {}",
&build::SHORT_COMMIT,
&build::BRANCH,
&build::BUILD_TIME,
&build::RUST_CHANNEL,
&build::RUST_VERSION,
);
// Hard-Coded limits
/// Range of acceptable input values for integral_num

View File

@ -3,7 +3,6 @@ use crate::misc::{dyn_mut_iter, option_vec_printer, JsonFileOutput, SerdeValueHe
use crate::parsing::{process_func_str, test_func};
use crate::consts::*;
use const_format::formatc;
use eframe::{egui, epi};
use egui::plot::Plot;
use egui::{
@ -12,24 +11,11 @@ use egui::{
};
use epi::Frame;
use instant::Duration;
use shadow_rs::shadow;
use std::{collections::BTreeMap, io::Read, ops::BitXorAssign, str};
#[cfg(not(target_arch = "wasm32"))]
use rayon::iter::{IndexedParallelIterator, ParallelIterator};
shadow!(build);
// Constant string that has a string containing information about the build.
const BUILD_INFO: &str = formatc!(
"Commit: {} ({})\nBuild Date: {}\nRust Channel: {}\nRust Version: {}",
&build::SHORT_COMMIT,
&build::BRANCH,
&build::BUILD_TIME,
&build::RUST_CHANNEL,
&build::RUST_VERSION,
);
// Stores data loaded from files
struct Assets {
// Stores `FontDefinitions`
@ -529,7 +515,6 @@ impl MathApp {
impl epi::App for MathApp {
// Called each time the UI needs repainting, which may be many times per second.
#[inline(always)]
fn update(&mut self, ctx: &Context, _frame: &Frame) {
let start = instant::Instant::now();

View File

@ -6,7 +6,7 @@ use crate::misc::*;
use crate::parsing::BackingFunction;
use eframe::{egui, epaint};
use egui::{
plot::{BarChart, Line, PlotUi, Points, Value, Values},
plot::{BarChart, PlotUi, Value},
widgets::plot::Bar,
};
use epaint::Color32;
@ -297,7 +297,7 @@ impl FunctionEntry {
/ (settings.integral_num as f64);
// Plot back data
plot_ui.line(
Line::new(Values::from_values(self.output.back.clone().unwrap()))
vec_tuple_to_line(self.output.back.clone().unwrap())
.color(Color32::RED)
.name(func_str),
);
@ -306,7 +306,7 @@ impl FunctionEntry {
if self.derivative {
if let Some(derivative_data) = self.output.derivative.clone() {
plot_ui.line(
Line::new(Values::from_values(derivative_data))
vec_tuple_to_line(derivative_data)
.color(Color32::GREEN)
.name(derivative_str),
);
@ -317,7 +317,7 @@ impl FunctionEntry {
if settings.extrema {
if let Some(extrema_data) = self.output.extrema.clone() {
plot_ui.points(
Points::new(Values::from_values(extrema_data))
vec_tuple_to_points(extrema_data)
.color(Color32::YELLOW)
.name("Extrema")
.radius(5.0), // Radius of points of Extrema
@ -329,7 +329,7 @@ impl FunctionEntry {
if settings.roots {
if let Some(roots_data) = self.output.roots.clone() {
plot_ui.points(
Points::new(Values::from_values(roots_data))
vec_tuple_to_points(roots_data)
.color(Color32::LIGHT_BLUE)
.name("Root")
.radius(5.0), // Radius of points of Roots
@ -351,6 +351,7 @@ impl FunctionEntry {
None
}
}
#[cfg(test)]
pub fn tests(
&mut self, settings: AppSettings, back_target: Vec<(f64, f64)>,
@ -366,13 +367,13 @@ impl FunctionEntry {
let back_vec_tuple = back_data.to_tuple();
assert_eq!(back_vec_tuple, back_target);
assert_eq!(true, self.integral);
assert_eq!(true, self.derivative);
assert!(self.integral);
assert!(self.derivative);
assert_eq!(self.output.roots.is_some(), settings.roots);
assert_eq!(self.output.extrema.is_some(), settings.extrema);
assert_eq!(self.output.derivative.is_some(), true);
assert_eq!(self.output.integral.is_some(), true);
assert!(self.output.derivative.is_some());
assert!(self.output.integral.is_some());
assert_eq!(
self.output.derivative.as_ref().unwrap().to_tuple(),

View File

@ -1,4 +1,4 @@
use eframe::egui::plot::Value as EguiValue;
use eframe::egui::plot::{Line, Points, Value as EguiValue, Values};
use itertools::Itertools;
use serde_json::Value as JsonValue;
@ -148,6 +148,14 @@ impl From<Vec<f64>> for SteppedVector {
}
}
/// Converts Vector of egui `Value` into `Points`
pub fn vec_tuple_to_points(data: Vec<EguiValue>) -> Points {
Points::new(Values::from_values(data))
}
/// Converts Vector of egui `Value` into `Line`
pub fn vec_tuple_to_line(data: Vec<EguiValue>) -> Line { Line::new(Values::from_values(data)) }
#[derive(PartialEq, Debug)]
pub struct JsonFileOutput {
pub help_expr: String,