From ec723fb97ba02086ba9bd569d441193f2b461192 Mon Sep 17 00:00:00 2001 From: ramox81 <184937705+ramox81@users.noreply.github.com> Date: Fri, 11 Sep 2026 10:26:09 +0300 Subject: [PATCH 1/3] Match MEASURE marker placement behavior --- src/app/command_driver.rs | 12 +- src/app/commands/inquiry.rs | 2 +- src/command.rs | 10 +- src/modules/draw/inquiry/divide.rs | 250 +++++++++++++++++------------ 4 files changed, 168 insertions(+), 106 deletions(-) diff --git a/src/app/command_driver.rs b/src/app/command_driver.rs index 87635b15f..c6f5ada6e 100644 --- a/src/app/command_driver.rs +++ b/src/app/command_driver.rs @@ -3178,26 +3178,30 @@ impl OpenCADStudio { CmdResult::MeasureEntity { handle, segment_length, + pick_point, + marker, } => { use crate::modules::draw::inquiry::divide::measure_entity; let pts = self.tabs[i] .scene .document .get_entity(handle) - .map(|e| measure_entity(e, segment_length)) + .map(|e| measure_entity(e, segment_length, pick_point, marker.as_ref())) .unwrap_or_default(); let count = pts.len(); if count > 0 { self.push_undo_snapshot(i, "MEASURE"); - for p in pts { + let layer = self.tabs[i].active_layer.clone(); + for mut p in pts { + p.as_entity_mut().set_layer(layer.clone()); self.tabs[i].scene.add_entity(p); } self.tabs[i].dirty = true; self.command_line - .push_output(crate::tf!("MEASURE: {count} point(s) placed.").as_ref()); + .push_output(crate::tf!("MEASURE: {count} marker(s) placed.").as_ref()); } else { self.command_line - .push_error(crate::t!("MEASURE: entity type not supported or distance too large.").as_ref()); + .push_output(crate::t!("MEASURE: 0 markers placed.").as_ref()); } self.tabs[i].active_cmd = None; self.tabs[i].snap_result = None; diff --git a/src/app/commands/inquiry.rs b/src/app/commands/inquiry.rs index 08f920696..d81ff4ba4 100644 --- a/src/app/commands/inquiry.rs +++ b/src/app/commands/inquiry.rs @@ -982,7 +982,7 @@ impl OpenCADStudio { "MEASURE" => { use crate::modules::draw::inquiry::divide::MeasureCommand; - let cmd = MeasureCommand::new(); + let cmd = MeasureCommand::new().with_blocks(self.tabs[i].scene.custom_block_names()); self.command_line.push_info(&cmd.prompt()); self.tabs[i].active_cmd = Some(Box::new(cmd)); } diff --git a/src/command.rs b/src/command.rs index d69859462..9bd130c73 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1483,7 +1483,7 @@ pub enum CmdResult { /// Place Point entities at N equal intervals along the entity. DivideEntity { handle: Handle, n: usize }, /// Place Point entities at `segment_length` intervals along the entity. - MeasureEntity { handle: Handle, segment_length: f64 }, + MeasureEntity { handle: Handle, segment_length: f64, pick_point: DVec3, marker: Option }, /// Extend/trim a Line or Arc by the given mode; end command. LengthenEntity { handle: Handle, @@ -1939,6 +1939,14 @@ impl InputKind { } } +#[derive(Clone, Debug)] +pub struct CurveMarker { + pub block: String, + pub align: bool, + pub plane: WorkingPlane, +} + + pub trait CadCommand: Send { /// Keep the layer already carried by entities committed by this command /// instead of replacing it with the current drawing layer. diff --git a/src/modules/draw/inquiry/divide.rs b/src/modules/draw/inquiry/divide.rs index b8e8acdd2..885522066 100644 --- a/src/modules/draw/inquiry/divide.rs +++ b/src/modules/draw/inquiry/divide.rs @@ -1,17 +1,127 @@ -// DIVIDE command — place Point entities at N equal intervals along an entity. -// MEASURE command — place Point entities at fixed-distance intervals along an entity. - -use acadrust::entities::Point as PointEnt; -use cadkernel::space::PlanarCurve; +// DIVIDE and MEASURE place points or block references along a curve. +use acadrust::entities::{Insert, Point as PointEnt}; use acadrust::types::Vector3; -use acadrust::{EntityType, Handle}; +use acadrust::{Entity, EntityType, Handle}; +use cadkernel::space::PlanarCurve; use glam::DVec3; +use crate::command::{CadCommand, CmdOption, CmdResult, CurveMarker, WorkingPlane}; use crate::entities::curve::entity_curve; use crate::t; +const MEASURE: bool = true; -use crate::command::{CadCommand, CmdResult}; +#[derive(Clone, Copy, PartialEq)] +enum Step { Pick, Amount, BlockName, Align } + +pub struct MeasurementMarkerCommand { + target: Option, + pick_point: DVec3, + step: Step, + blocks: Vec, + block: Option, + align: bool, + plane: WorkingPlane, + valid_pick: bool, +} + +pub type MeasureCommand = MeasurementMarkerCommand; + +impl MeasurementMarkerCommand { + pub fn new() -> Self { + Self { target: None, pick_point: DVec3::ZERO, step: Step::Pick, + blocks: Vec::new(), block: None, align: true, + plane: WorkingPlane::default(), valid_pick: false } + } + pub fn with_blocks(mut self, blocks: Vec) -> Self { + self.blocks = blocks; + self + } + fn marker(&self) -> Option { + self.block.as_ref().map(|name| CurveMarker { + block: name.clone(), align: self.align, plane: self.plane, + }) + } +} + +impl CadCommand for MeasurementMarkerCommand { + fn name(&self) -> &'static str { if MEASURE { "MEASURE" } else { "DIVIDE" } } + fn prompt(&self) -> String { + let prompt = match self.step { + Step::Pick if MEASURE => "Select object to measure:", + Step::Pick => "Select object to divide:", + Step::BlockName => "Enter name of block to insert:", + Step::Align => "Align block with object? [Yes/No] :", + Step::Amount if MEASURE && self.block.is_none() => "Specify length of segment or [Block]:", + Step::Amount if MEASURE => "Specify length of segment:", + Step::Amount if self.block.is_none() => "Enter number of segments or [Block]:", + Step::Amount => "Enter number of segments:", + }; + format!("{} {}", self.name(), prompt) + } + fn options(&self) -> Vec { + match self.step { + Step::Amount if self.block.is_none() => vec![CmdOption::new("Block", "B")], + Step::Align => vec![CmdOption::new("Yes", "Y"), CmdOption::new("No", "N")], + _ => vec![], + } + } + fn set_working_plane(&mut self, plane: WorkingPlane) { self.plane = plane; } + fn needs_entity_pick(&self) -> bool { self.step == Step::Pick } + fn inject_before_entity_pick(&self) -> bool { true } + fn inject_picked_entity(&mut self, entity: EntityType) { + self.valid_pick = measurable(&entity).is_some(); + } + fn on_entity_pick(&mut self, handle: Handle, pt: DVec3) -> CmdResult { + if handle.is_null() || !self.valid_pick { return CmdResult::NeedPoint; } + self.target = Some(handle); + self.pick_point = pt; + self.step = Step::Amount; + CmdResult::NeedPoint + } + fn wants_text_input(&self) -> bool { self.step != Step::Pick } + fn dyn_field(&self) -> crate::command::DynField { + if self.step == Step::Amount { crate::command::DynField::Scalar } + else { crate::command::DynField::Point } + } + fn dyn_commit_as_text(&self) -> bool { self.step == Step::Amount } + fn on_text_input(&mut self, text: &str) -> Option { + let text = text.trim(); + match self.step { + Step::BlockName => { + self.block = Some(self.blocks.iter().find(|name| name.eq_ignore_ascii_case(text))?.clone()); + self.step = Step::Align; + } + Step::Align => { + self.align = match text.to_ascii_uppercase().as_str() { + "Y" | "YES" => true, + "N" | "NO" => false, + _ => return None, + }; + self.step = Step::Amount; + } + Step::Amount => { + if self.block.is_none() && matches!(text.to_ascii_uppercase().as_str(), "B" | "BLOCK") { + self.step = Step::BlockName; + } else { + let segment_length = text.replace(',', ".").parse::().ok() + .filter(|d| d.is_finite() && *d > 0.0)?; + return Some(CmdResult::MeasureEntity { handle: self.target?, segment_length, + pick_point: self.pick_point, marker: self.marker() }); + } + } + Step::Pick => return None, + } + Some(CmdResult::NeedPoint) + } + fn on_point(&mut self, _pt: DVec3) -> CmdResult { CmdResult::NeedPoint } + fn on_enter(&mut self) -> CmdResult { + if self.step == Step::Align { + self.align = true; + self.step = Step::Amount; + CmdResult::NeedPoint + } else { CmdResult::Cancel } + } +} -// ── DIVIDE ───────────────────────────────────────────────────────────────── pub struct DivideCommand { target: Option, @@ -80,86 +190,7 @@ impl CadCommand for DivideCommand { } } -// ── MEASURE ──────────────────────────────────────────────────────────────── -pub struct MeasureCommand { - target: Option, - waiting_for_dist: bool, -} - -impl MeasureCommand { - pub fn new() -> Self { - Self { - target: None, - waiting_for_dist: false, - } - } -} - -impl CadCommand for MeasureCommand { - fn name(&self) -> &'static str { - "MEASURE" - } - - fn prompt(&self) -> String { - if self.target.is_none() { - t!("MEASURE Select object to measure:").into_owned() - } else { - t!("MEASURE Specify segment length:").into_owned() - } - } - - fn needs_entity_pick(&self) -> bool { - self.target.is_none() - } - - fn on_entity_pick(&mut self, handle: Handle, _pt: DVec3) -> CmdResult { - if handle.is_null() { - return CmdResult::NeedPoint; - } - self.target = Some(handle); - self.waiting_for_dist = true; - CmdResult::NeedPoint - } - - fn wants_text_input(&self) -> bool { - self.waiting_for_dist - } - - fn dyn_field(&self) -> crate::command::DynField { - if self.waiting_for_dist { - crate::command::DynField::Scalar - } else { - crate::command::DynField::Point - } - } - - fn on_text_input(&mut self, text: &str) -> Option { - let dist: f64 = text - .trim() - .replace(',', ".") - .parse() - .ok() - .filter(|&d: &f64| d > 0.0)?; - let handle = self.target?; - self.waiting_for_dist = false; - Some(CmdResult::MeasureEntity { - handle, - segment_length: dist, - }) - } - - fn on_point(&mut self, _pt: DVec3) -> CmdResult { - CmdResult::NeedPoint - } - fn on_enter(&mut self) -> CmdResult { - CmdResult::Cancel - } -} - -// ── Geometry ─────────────────────────────────────────────────────────────── - -/// Compute N-1 equally spaced points along the entity (DIVIDE). pub fn divide_entity(entity: &EntityType, n: usize) -> Vec { if n < 2 { return vec![]; @@ -173,38 +204,57 @@ pub fn divide_entity(entity: &EntityType, n: usize) -> Vec { .collect() } -/// Compute points at fixed `segment_length` intervals along the entity (MEASURE). -pub fn measure_entity(entity: &EntityType, segment_length: f64) -> Vec { - if segment_length <= 0.0 { +pub fn measure_entity(entity: &EntityType, segment_length: f64, pick_point: DVec3, + marker: Option<&CurveMarker>) -> Vec { + if !segment_length.is_finite() || segment_length <= 0.0 { return vec![]; } let Some((curve, total)) = measurable(entity) else { return vec![]; }; let mut pts = Vec::new(); - let mut walked = segment_length; - while walked < total - 1e-6 { - pts.push(make_point(curve.point_at_distance(walked))); - walked += segment_length; + let first = DVec3::from_array(curve.point_at_distance(0.0)); + let last = DVec3::from_array(curve.point_at_distance(total)); + let reverse = !curve.is_closed() && pick_point.distance_squared(last) < pick_point.distance_squared(first); + // A complete final interval includes the end point. Index multiplication + // avoids cumulative drift when many intervals are placed on a long curve. + let count = (total / segment_length).floor() as usize; + for index in 1..=count { + let walked = segment_length * index as f64; + pts.push(make_marker(&curve, if reverse { total - walked } else { walked }, marker)); } pts } +fn make_marker(curve: &PlanarCurve, distance: f64, marker: Option<&CurveMarker>) -> EntityType { + let pos = curve.point_at_distance(distance); + let Some(marker) = marker else { + let mut point = PointEnt::new(); + point.location = Vector3::new(pos[0], pos[1], pos[2]); + return EntityType::Point(point); + }; + let local = marker.plane.to_local(DVec3::from_array(pos)); + let mut insert = Insert::new(marker.block.clone(), Vector3::new(local.x, local.y, local.z)); + if marker.align { + let tangent = DVec3::from_array(curve.tangent_at(curve.parameter_at_distance(distance))); + let tangent = marker.plane.vector_to_local(tangent); + insert.rotation = tangent.y.atan2(tangent.x); + } + insert.apply_transform(&marker.plane.to_world_transform()); + EntityType::Insert(insert) +} + fn make_point(pos: [f64; 3]) -> EntityType { let mut p = PointEnt::new(); p.location = Vector3::new(pos[0], pos[1], pos[2]); EntityType::Point(p) } -/// The entity's curve and its length, or `None` for anything that cannot be -/// walked along — a hatch, a block, an unbounded ray. fn measurable(entity: &EntityType) -> Option<(PlanarCurve, f64)> { let curve = entity_curve(entity)?; let total = curve.curve.length(); (total.is_finite() && total > 1e-10).then_some((curve, total)) } - -// ── Autocomplete registry ───────────────────────────────── -inventory::submit!(crate::command::CommandRegistration { names: &["DIVIDE"] }); // DivideCommand -inventory::submit!(crate::command::CommandRegistration { names: &["MEASURE"] }); // MeasureCommand +inventory::submit!(crate::command::CommandRegistration { names: &["DIVIDE"] }); +inventory::submit!(crate::command::CommandRegistration { names: &["MEASURE"] }); From 83a930950a19c3c3f40b602b49fce6ffe47437ca Mon Sep 17 00:00:00 2001 From: ramox81 <184937705+ramox81@users.noreply.github.com> Date: Fri, 11 Sep 2026 10:56:24 +0300 Subject: [PATCH 2/3] Accept two-point MEASURE spacing in spatial coordinates --- src/modules/draw/inquiry/divide.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/modules/draw/inquiry/divide.rs b/src/modules/draw/inquiry/divide.rs index 885522066..1a7842fec 100644 --- a/src/modules/draw/inquiry/divide.rs +++ b/src/modules/draw/inquiry/divide.rs @@ -21,6 +21,7 @@ pub struct MeasurementMarkerCommand { align: bool, plane: WorkingPlane, valid_pick: bool, + value_origin: Option, } pub type MeasureCommand = MeasurementMarkerCommand; @@ -29,7 +30,7 @@ impl MeasurementMarkerCommand { pub fn new() -> Self { Self { target: None, pick_point: DVec3::ZERO, step: Step::Pick, blocks: Vec::new(), block: None, align: true, - plane: WorkingPlane::default(), valid_pick: false } + plane: WorkingPlane::default(), valid_pick: false, value_origin: None } } pub fn with_blocks(mut self, blocks: Vec) -> Self { self.blocks = blocks; @@ -45,6 +46,7 @@ impl MeasurementMarkerCommand { impl CadCommand for MeasurementMarkerCommand { fn name(&self) -> &'static str { if MEASURE { "MEASURE" } else { "DIVIDE" } } fn prompt(&self) -> String { + if self.value_origin.is_some() { return "MEASURE Specify second point:".into(); } let prompt = match self.step { Step::Pick if MEASURE => "Select object to measure:", Step::Pick => "Select object to divide:", @@ -58,6 +60,7 @@ impl CadCommand for MeasurementMarkerCommand { format!("{} {}", self.name(), prompt) } fn options(&self) -> Vec { + if self.value_origin.is_some() { return vec![]; } match self.step { Step::Amount if self.block.is_none() => vec![CmdOption::new("Block", "B")], Step::Align => vec![CmdOption::new("Yes", "Y"), CmdOption::new("No", "N")], @@ -79,7 +82,8 @@ impl CadCommand for MeasurementMarkerCommand { } fn wants_text_input(&self) -> bool { self.step != Step::Pick } fn dyn_field(&self) -> crate::command::DynField { - if self.step == Step::Amount { crate::command::DynField::Scalar } + if self.step == Step::Amount && MEASURE { crate::command::DynField::Distance } + else if self.step == Step::Amount { crate::command::DynField::Scalar } else { crate::command::DynField::Point } } fn dyn_commit_as_text(&self) -> bool { self.step == Step::Amount } @@ -99,7 +103,7 @@ impl CadCommand for MeasurementMarkerCommand { self.step = Step::Amount; } Step::Amount => { - if self.block.is_none() && matches!(text.to_ascii_uppercase().as_str(), "B" | "BLOCK") { + if self.block.is_none() && self.value_origin.is_none() && matches!(text.to_ascii_uppercase().as_str(), "B" | "BLOCK") { self.step = Step::BlockName; } else { let segment_length = text.replace(',', ".").parse::().ok() @@ -112,7 +116,21 @@ impl CadCommand for MeasurementMarkerCommand { } Some(CmdResult::NeedPoint) } - fn on_point(&mut self, _pt: DVec3) -> CmdResult { CmdResult::NeedPoint } + fn dyn_live_value(&self, cursor: DVec3) -> Option { + if !MEASURE || self.step != Step::Amount || !cursor.is_finite() { return None; } + let origin = self.value_origin?; + let distance = cadkernel::space::Vec3::from(cursor.to_array()).distance(origin.to_array().into()); + (distance.is_finite() && distance > 0.0).then_some(distance) + } + fn on_point(&mut self, pt: DVec3) -> CmdResult { + if MEASURE && self.step == Step::Amount && pt.is_finite() { + if self.value_origin.is_none() { self.value_origin = Some(pt); } + else if let Some(value) = self.dyn_live_value(pt) { + return self.on_text_input(&value.to_string()).unwrap_or(CmdResult::NeedPoint); + } + } + CmdResult::NeedPoint + } fn on_enter(&mut self) -> CmdResult { if self.step == Step::Align { self.align = true; From 396c277fd59f5bb9c1ac627559db91d8ef42ee59 Mon Sep 17 00:00:00 2001 From: ramox81 <184937705+ramox81@users.noreply.github.com> Date: Fri, 11 Sep 2026 11:28:21 +0300 Subject: [PATCH 3/3] Place curve markers along spatial splines and polylines --- src/entities/curve.rs | 45 ++++++++++++++++++++++++++++++ src/modules/draw/inquiry/divide.rs | 41 +++++++++++++++++++++++---- 2 files changed, 80 insertions(+), 6 deletions(-) diff --git a/src/entities/curve.rs b/src/entities/curve.rs index f477a83b8..0eede62e8 100644 --- a/src/entities/curve.rs +++ b/src/entities/curve.rs @@ -107,6 +107,51 @@ pub fn entity_curve(entity: &EntityType) -> Option { } } +/// Exact spatial source geometry for commands that traverse nonplanar curves. +/// Curve construction and arc-length calculations remain in the kernel. +pub fn entity_spatial_measurement(entity: &EntityType) -> Option { + use cadkernel::space::{ArcLengthCurve3, NurbsCurve3, Parameterization}; + let curve = match entity { + EntityType::Polyline3D(polyline) => { + if polyline.flags.spline_fit { + let degree = match polyline.smooth_type as i16 { 5 => 2, 6 => 3, _ => return None }; + let controls: Vec<_> = polyline.vertices.iter().filter(|vertex| vertex.flags & 16 != 0) + .map(|vertex| [vertex.position.x, vertex.position.y, vertex.position.z]).collect(); + let curve = NurbsCurve3::from_control_polygon(degree, &controls, polyline.is_closed())?; + return ArcLengthCurve3::from_nurbs(curve); + } + let points: Vec<_> = polyline.vertices.iter().map(|vertex| { + [vertex.position.x, vertex.position.y, vertex.position.z] + }).collect(); + return ArcLengthCurve3::from_polyline(&points, polyline.is_closed()); + } + EntityType::Spline(spline) => { + if crate::entities::spline::uses_fit_method(spline) { + let points: Vec<_> = spline.fit_points.iter().copied().map(xyz).collect(); + let parameterization = match spline.knot_parameterization { + 1 => Parameterization::Centripetal, 2 => Parameterization::Uniform, + _ => Parameterization::Chord, + }; + if spline.flags.periodic { + NurbsCurve3::interpolate_periodic(&points, parameterization)? + } else { + if spline.flags.closed { return None; } + NurbsCurve3::interpolate_fit(&points, Some(xyz(spline.begin_tangent)), + Some(xyz(spline.end_tangent)), parameterization)? + } + } else { + let controls: Vec<_> = spline.control_points.iter().copied().map(xyz).collect(); + let weights = if spline.weights.is_empty() { vec![1.0; controls.len()] } + else { spline.weights.clone() }; + NurbsCurve3::new_strict(spline.degree as usize, controls, spline.knots.clone(), weights)? + .with_periodicity(spline.flags.periodic) + } + } + _ => return None, + }; + ArcLengthCurve3::from_nurbs(curve) +} + /// The plane an OCS-stored entity's coordinates are read in. /// /// `elevation` is the entity's third stored coordinate — the distance along diff --git a/src/modules/draw/inquiry/divide.rs b/src/modules/draw/inquiry/divide.rs index 1a7842fec..7e07480e0 100644 --- a/src/modules/draw/inquiry/divide.rs +++ b/src/modules/draw/inquiry/divide.rs @@ -5,7 +5,7 @@ use acadrust::{Entity, EntityType, Handle}; use cadkernel::space::PlanarCurve; use glam::DVec3; use crate::command::{CadCommand, CmdOption, CmdResult, CurveMarker, WorkingPlane}; -use crate::entities::curve::entity_curve; +use crate::entities::curve::{entity_curve, entity_spatial_measurement}; use crate::t; const MEASURE: bool = true; @@ -213,9 +213,11 @@ pub fn divide_entity(entity: &EntityType, n: usize) -> Vec { if n < 2 { return vec![]; } - let Some((curve, total)) = measurable(entity) else { + let Some(curve) = entity_curve(entity) else { return vec![]; }; + let total = curve.length(); + if !total.is_finite() || total <= 1e-10 { return vec![]; } let step = total / n as f64; (1..n) .map(|k| make_point(curve.point_at_distance(step * k as f64))) @@ -244,7 +246,7 @@ pub fn measure_entity(entity: &EntityType, segment_length: f64, pick_point: DVec pts } -fn make_marker(curve: &PlanarCurve, distance: f64, marker: Option<&CurveMarker>) -> EntityType { +fn make_marker(curve: &MeasuredCurve, distance: f64, marker: Option<&CurveMarker>) -> EntityType { let pos = curve.point_at_distance(distance); let Some(marker) = marker else { let mut point = PointEnt::new(); @@ -268,9 +270,36 @@ fn make_point(pos: [f64; 3]) -> EntityType { EntityType::Point(p) } -fn measurable(entity: &EntityType) -> Option<(PlanarCurve, f64)> { - let curve = entity_curve(entity)?; - let total = curve.curve.length(); +/// The entity's curve and its length, or `None` for anything that cannot be +/// walked along — a hatch, a block, an unbounded ray. +enum MeasuredCurve { + Planar(PlanarCurve), + Spatial(cadkernel::space::ArcLengthCurve3), +} +impl MeasuredCurve { + fn is_closed(&self) -> bool { + match self { Self::Planar(curve) => curve.is_closed(), Self::Spatial(curve) => curve.is_closed() } + } + fn point_at_distance(&self, distance: f64) -> [f64; 3] { + match self { Self::Planar(curve) => curve.point_at_distance(distance), Self::Spatial(curve) => curve.point_at_distance(distance) } + } + fn parameter_at_distance(&self, distance: f64) -> f64 { + match self { Self::Planar(curve) => curve.parameter_at_distance(distance), Self::Spatial(curve) => curve.parameter_at_distance(distance) } + } + fn tangent_at(&self, parameter: f64) -> [f64; 3] { + match self { Self::Planar(curve) => curve.tangent_at(parameter), Self::Spatial(curve) => curve.tangent_at(parameter) } + } +} + +fn measurable(entity: &EntityType) -> Option<(MeasuredCurve, f64)> { + let (curve, total) = if let Some(curve) = entity_curve(entity) { + let total = curve.length(); + (MeasuredCurve::Planar(curve), total) + } else { + let curve = entity_spatial_measurement(entity)?; + let total = curve.length(); + (MeasuredCurve::Spatial(curve), total) + }; (total.is_finite() && total > 1e-10).then_some((curve, total)) }