Skip to content

Commit 14482ea

Browse files
committed
add better point dargging with solve_minimize. fix double refcell borrow when nesting par iters
1 parent eed791e commit 14482ea

5 files changed

Lines changed: 223 additions & 75 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "rust_graph"
4-
version = "0.3.3"
4+
version = "0.3.4"
55
edition = "2024"
66
authors = ["Vedran Maric <valinion@gmail.com>"]
77
description = "Graphing calculator with f32 support."
@@ -17,6 +17,10 @@ crate-type = ["cdylib", "rlib"]
1717
puffin = ["dep:puffin_http", "dep:puffin"]
1818
default = []
1919

20+
[profile.release]
21+
# debug-assertions = true
22+
# debug="line-tables-only"
23+
2024
[profile.profiling]
2125
inherits = "release"
2226
debug = "line-tables-only"
@@ -44,10 +48,12 @@ smallvec = {version = "1", features = ["union"]}
4448
rayon={version="1", features=["web_spin_lock"]}
4549
thread_local="1"
4650
regex = "1"
51+
# debug-cell="*"
4752

4853
# [patch."https://github.com/vdrn/evalexpr"]
4954
# evalexpr = { path = "../../contrib/evalexpr" }
5055
# [patch.crates-io]
56+
# egui_plot = { path = "../../contrib/egui_plot/egui_plot" }
5157
# puffin = { path = "../../contrib/puffin/puffin" }
5258
# puffin_http = { path = "../../contrib/puffin/puffin_http" }
5359

src/entry.rs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use alloc::sync::Arc;
2-
use core::cell::Cell;
2+
use core::cell::{Cell, RefCell};
33
use core::mem;
44
use core::ops::RangeInclusive;
55
use regex::Regex;
@@ -711,10 +711,20 @@ pub fn edit_entry_ui<T: EvalexprNumericTypes>(
711711
DragPoint::BothCoordConstants(x, y) => {
712712
format!("{}({}, {})", point.drag_type.symbol(), x, y,)
713713
},
714+
DragPoint::SameConstantBothCoords(x) => {
715+
format!("{}({})", point.drag_type.symbol(), x)
716+
},
714717
},
715718
None => point.drag_type.symbol().to_string(),
716719
};
717720
ui.menu_button(drag_menu_text, |ui| {
721+
drag_type_changed |= ui
722+
.selectable_value(
723+
&mut point.drag_type,
724+
PointDragType::NoDrag,
725+
PointDragType::NoDrag.name(),
726+
)
727+
.changed();
718728
if point.both_drag_dirs_available {
719729
drag_type_changed |= ui
720730
.selectable_value(
@@ -766,6 +776,12 @@ pub fn edit_entry_ui<T: EvalexprNumericTypes>(
766776
let range = ty.range();
767777
let start = *range.start();
768778
let end = *range.end();
779+
780+
if v > end {
781+
v -= end - start;
782+
} else if v < start {
783+
v += end - start;
784+
}
769785
v = v.clamp(start, end);
770786

771787
ui.vertical(|ui| {
@@ -945,14 +961,24 @@ pub fn recompile_entry<T: EvalexprNumericTypes>(
945961
if x_state.is_literal {
946962
point.drag_point = Some(DragPoint::XLiteral);
947963
} else if let Some(x_const) = x_state.constants.first() {
948-
point.drag_point = Some(DragPoint::XConstant(x_const.to_string()));
964+
if y_state.constants.iter().any(|c| c == x_const) {
965+
point.drag_point =
966+
Some(DragPoint::SameConstantBothCoords(x_const.to_string()));
967+
} else {
968+
point.drag_point = Some(DragPoint::XConstant(x_const.to_string()));
969+
}
949970
}
950971
},
951972
PointDragType::Y => {
952973
if y_state.is_literal {
953974
point.drag_point = Some(DragPoint::YLiteral);
954975
} else if let Some(y_const) = y_state.constants.first() {
955-
point.drag_point = Some(DragPoint::YConstant(y_const.to_string()));
976+
if x_state.constants.iter().any(|c| c == y_const) {
977+
point.drag_point =
978+
Some(DragPoint::SameConstantBothCoords(y_const.to_string()));
979+
} else {
980+
point.drag_point = Some(DragPoint::YConstant(y_const.to_string()));
981+
}
956982
}
957983
},
958984
}
@@ -1081,7 +1107,7 @@ pub struct PlotParams {
10811107
#[allow(clippy::too_many_arguments)]
10821108
pub fn create_entry_plot_elements<T: EvalexprNumericTypes>(
10831109
entry: &mut Entry<T>, id: Id, selected_id: Option<Id>, ctx: &evalexpr::HashMapContext<T>,
1084-
plot_params: &PlotParams, draw_buffer: &mut DrawBuffer,
1110+
plot_params: &PlotParams, draw_buffer: &RefCell<DrawBuffer>,
10851111
) -> Result<(), String> {
10861112
let visible = entry.visible;
10871113
if !visible && !matches!(entry.ty, EntryType::Integral { .. }) {
@@ -1092,6 +1118,7 @@ pub fn create_entry_plot_elements<T: EvalexprNumericTypes>(
10921118
match &mut entry.ty {
10931119
EntryType::Constant { .. } => {},
10941120
EntryType::Integral { func, lower, upper, calculated, resolution, .. } => {
1121+
let mut draw_buffer = draw_buffer.borrow_mut();
10951122
let (Some(lower_node), Some(upper_node), Some(func_node)) = (&lower.node, &upper.node, &func.node)
10961123
else {
10971124
return Ok(());
@@ -1266,6 +1293,8 @@ pub fn create_entry_plot_elements<T: EvalexprNumericTypes>(
12661293
*calculated = Some(result);
12671294
},
12681295
EntryType::Label { x, y, size, underline, .. } => {
1296+
let mut draw_buffer = draw_buffer.borrow_mut();
1297+
12691298
match eval_point(ctx, x.node.as_ref(), y.node.as_ref()) {
12701299
Ok(Some((x, y))) => {
12711300
let size = if let Some(size) = &size.node {
@@ -1294,6 +1323,7 @@ pub fn create_entry_plot_elements<T: EvalexprNumericTypes>(
12941323
}
12951324
},
12961325
EntryType::Points(ps) => {
1326+
let mut draw_buffer = draw_buffer.borrow_mut();
12971327
// main_context
12981328
// .write()
12991329
// .unwrap()
@@ -1374,7 +1404,8 @@ pub fn create_entry_plot_elements<T: EvalexprNumericTypes>(
13741404
// .entry(text.clone())
13751405
// .or_insert_with(|| AHashMap::with_capacity(ui_state.conf.resolution))
13761406
// });
1377-
let mut add_line = |line: Vec<PlotPoint>| {
1407+
let add_line = |line: Vec<PlotPoint>| {
1408+
let mut draw_buffer = draw_buffer.borrow_mut();
13781409
draw_buffer.lines.push(FunctionLine {
13791410
width,
13801411
id,
@@ -1671,6 +1702,7 @@ pub enum DragPoint {
16711702
XLiteralYConstant(String),
16721703
YLiteralXConstant(String),
16731704
BothCoordConstants(String, String),
1705+
SameConstantBothCoords(String),
16741706
}
16751707

16761708
pub struct NodeAnalysis<'a> {

0 commit comments

Comments
 (0)