Skip to content

Commit b5ad053

Browse files
committed
small cleanup/refactors
1 parent 2202ec2 commit b5ad053

16 files changed

Lines changed: 815 additions & 949 deletions

src/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::LazyLock;
33
use eframe::egui::{self, RichText};
44
use evalexpr::{EvalexprError, EvalexprFloat, EvalexprResult, IStr, IStrSet, Value, istr};
55

6-
use crate::entry::f64_to_value;
6+
use crate::utils::f64_to_value;
77

88
const BUILTIN_VARIABLE_NAMES: &[&str] = &["x", "y", "z"];
99

src/custom_rendering/fan_fill_renderer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ struct StencilTexture {
4444
}
4545

4646
impl FanFillRenderer {
47-
pub fn new<'a>(cc: &'a eframe::CreationContext<'a>) -> Option<Self> {
48-
let wgpu_render_state = cc.wgpu_render_state.as_ref()?;
47+
pub fn new<'a>(cc: &'a eframe::CreationContext<'a>) -> Self {
48+
let wgpu_render_state = cc.wgpu_render_state.as_ref().unwrap();
4949
let device = &wgpu_render_state.device;
5050

5151
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
@@ -228,7 +228,7 @@ impl FanFillRenderer {
228228
index_buffer_capacity: 1024,
229229
}));
230230

231-
Some(Self { texture_pool: Vec::new(), current_texture_index: 0, stencil_texture: None })
231+
Self { texture_pool: Vec::new(), current_texture_index: 0, stencil_texture: None }
232232
}
233233

234234
pub fn reset_textures(&mut self) { self.current_texture_index = 0; }

src/entry.rs

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use evalexpr::{EvalexprFloat, ExpressionFunction, FlatNode, HashMapContext, IStr
77

88
use crate::color::{EntryColor, NUM_COLORS};
99
use crate::custom_rendering::fan_fill_renderer::FillRule;
10-
use crate::graph::plot_elements::PlotElements;
10+
use crate::graph_ui::plot_elements::RawPlotElements;
1111

1212
mod entry_processing;
1313
mod entry_ui;
@@ -20,23 +20,18 @@ pub const MAX_IMPLICIT_RESOLUTION: usize = 500;
2020
pub const MIN_IMPLICIT_RESOLUTION: usize = 10;
2121

2222
pub struct Entry<T: EvalexprFloat> {
23-
pub id: u64,
24-
pub name: String,
25-
pub active: bool,
26-
pub color: EntryColor,
27-
pub ty: EntryType<T>,
28-
pub plot_elements: PlotElements,
23+
pub id: u64,
24+
pub name: String,
25+
pub active: bool,
26+
pub color: EntryColor,
27+
pub ty: EntryType<T>,
28+
pub raw_plot_elements: RawPlotElements,
2929
}
3030
pub struct ClonedEntry<T: EvalexprFloat> {
3131
pub id: u64,
32-
// pub color: C,
3332
pub ty: EntryType<T>,
3433
}
3534

36-
// impl<T: EvalexprFloat, C:Fn(T,T,T)->Result<Color32,String>> ClonedEntry<T,C> {
37-
// fn color(&self) -> Color32 { COLORS[self.color % NUM_COLORS] }
38-
// }
39-
4035
impl<T: EvalexprFloat + core::fmt::Debug> core::fmt::Debug for Entry<T> {
4136
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
4237
f.debug_struct("Entry")
@@ -52,16 +47,17 @@ impl<T: EvalexprFloat + core::fmt::Debug> core::fmt::Debug for Entry<T> {
5247
impl<T: EvalexprFloat + Clone> Clone for Entry<T> {
5348
fn clone(&self) -> Self {
5449
Self {
55-
id: self.id,
56-
name: self.name.clone(),
57-
active: self.active,
58-
color: self.color.clone(),
59-
ty: self.ty.clone(),
60-
plot_elements: PlotElements::empty(),
50+
id: self.id,
51+
name: self.name.clone(),
52+
active: self.active,
53+
color: self.color.clone(),
54+
ty: self.ty.clone(),
55+
raw_plot_elements: RawPlotElements::empty(),
6156
}
6257
}
6358
}
6459
impl<T: EvalexprFloat> core::hash::Hash for Entry<T> {
60+
// Used for drag and drop
6561
fn hash<H: core::hash::Hasher>(&self, state: &mut H) { self.id.hash(state); }
6662
}
6763

@@ -133,8 +129,6 @@ impl<T: EvalexprFloat> Expr<T> {
133129

134130
#[derive(Clone, Copy, Debug, PartialEq)]
135131
pub enum FunctionType {
136-
// ExpressionX,
137-
// ExpressionY,
138132
Expression,
139133
WithCustomParams,
140134
}
@@ -416,7 +410,7 @@ impl<T: EvalexprFloat> Entry<T> {
416410
color: EntryColor::DefaultColor(id as usize % NUM_COLORS),
417411
active: true,
418412
name: String::new(),
419-
plot_elements: PlotElements::empty(),
413+
raw_plot_elements: RawPlotElements::empty(),
420414
ty: EntryType::Function {
421415
identifier: istr_empty(),
422416
can_be_drawn: true,
@@ -440,7 +434,7 @@ impl<T: EvalexprFloat> Entry<T> {
440434
color: EntryColor::DefaultColor(id as usize % NUM_COLORS),
441435
active: false,
442436
name: String::new(),
443-
plot_elements: PlotElements::empty(),
437+
raw_plot_elements: RawPlotElements::empty(),
444438
ty: EntryType::Constant {
445439
istr_name: istr_empty(),
446440
value: T::ZERO,
@@ -457,7 +451,7 @@ impl<T: EvalexprFloat> Entry<T> {
457451
color: EntryColor::DefaultColor(id as usize % NUM_COLORS),
458452
active: true,
459453
name: String::new(),
460-
plot_elements: PlotElements::empty(),
454+
raw_plot_elements: RawPlotElements::empty(),
461455
ty: EntryType::Points {
462456
identifier: istr_empty(),
463457
points_ty: PointsType::Separate(vec![PointEntry::default()]),
@@ -471,7 +465,7 @@ impl<T: EvalexprFloat> Entry<T> {
471465
color: EntryColor::CustomColor(id),
472466
active: true,
473467
name: String::new(),
474-
plot_elements: PlotElements::empty(),
468+
raw_plot_elements: RawPlotElements::empty(),
475469
ty: EntryType::Color(ColorEntry { expr: Expr::from_text(""), ty: ColorEntryType::default() }),
476470
}
477471
}
@@ -481,7 +475,7 @@ impl<T: EvalexprFloat> Entry<T> {
481475
color: EntryColor::DefaultColor(id as usize % NUM_COLORS),
482476
active: true,
483477
name: String::new(),
484-
plot_elements: PlotElements::empty(),
478+
raw_plot_elements: RawPlotElements::empty(),
485479
ty: EntryType::Folder { entries: Vec::new() },
486480
}
487481
}
@@ -549,10 +543,6 @@ pub enum PointsType<T: EvalexprFloat> {
549543

550544
#[derive(Clone, Debug, Serialize, Deserialize)]
551545
pub enum ConstantType {
552-
// LoopForwardAndBackward { start: f64, end: f64, forward: bool },
553-
// LoopForward { start: f64, end: f64 },
554-
// PlayOnce { start: f64, end: f64 },
555-
// PlayIndefinitely { start: f64 },
556546
LoopForwardAndBackward { forward: bool },
557547
LoopForward,
558548
PlayOnce,
@@ -610,7 +600,6 @@ impl ConstantType {
610600

611601
pub static RESERVED_NAMES: [&str; 2] = ["x", "y"];
612602

613-
pub fn f64_to_value<T: EvalexprFloat>(x: f64) -> Value<T> { Value::<T>::Float(T::from_f64(x)) }
614603
// pub fn f64_to_float<T: EvalexprFloat>(x: f64) -> T { T::f64_to_float(x) }
615604

616605
#[derive(Clone, Debug)]

src/entry/entry_processing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use smallvec::SmallVec;
99
use crate::builtins::is_builtin;
1010
use crate::color::ProcessedColors;
1111
use crate::entry::{DragPoint, Entry, EntryType, EquationType, FunctionType, PointDragType, PointsType};
12-
use crate::graph::create_plot_elements::eval_point2;
12+
use crate::graph_ui::create_plot_elements::eval_2_points;
1313
use crate::scope;
1414

1515
pub fn preprocess_ast<T: EvalexprFloat>(mut ast: Node<T>) -> Result<(Node<T>, EquationType), String> {
@@ -567,7 +567,7 @@ fn inline_and_fold_entry<T: EvalexprFloat>(
567567
match points_ty {
568568
PointsType::Separate(points) => {
569569
for p in points.iter_mut() {
570-
match eval_point2(&mut stack, ctx, p.x.node.as_ref(), p.y.node.as_ref()) {
570+
match eval_2_points(&mut stack, ctx, p.x.node.as_ref(), p.y.node.as_ref()) {
571571
Ok(Some(v)) => {
572572
p.val = Some(v);
573573
},

src/entry/entry_ui.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::entry::entry_processing::preprocess_ast;
1515
use crate::entry::{
1616
ColorEntryType, ConstantType, DragPoint, Entry, EntryColor, EntryType, EquationType, Expr, FillAlpha, LabelConfig, LabelPosition, LabelSize, LineStyleConfig, LineStyleType, MAX_IMPLICIT_RESOLUTION, MIN_IMPLICIT_RESOLUTION, PointDrag, PointDragType, PointEntry, PointsType, RESERVED_NAMES
1717
};
18-
use crate::widgets::{duplicate_entry_btn, full_width_slider, remove_entry_btn};
18+
use crate::utils::{duplicate_entry_btn, full_width_slider, remove_entry_btn};
1919

2020
pub struct EditEntryResult {
2121
pub needs_recompilation: bool,

0 commit comments

Comments
 (0)