Compare commits

..
Author SHA1 Message Date
Brandon ThomasandClaude Opus 5.5 6995e0c423 Never crash: interactive tools (tools)
Removes every production unwrap/expect/unreachable from the tools crate
and denies the panic lints there: ARAP mesh band/seed selection, liquify
dabs, the anchor-point tool's drag preview (an idle drag now does
nothing) and the type tool's typing session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 14:51:53 -04:00
14 changed files with 30 additions and 50 deletions

No files matched your search

+4 -19
View File
@@ -43,9 +43,7 @@ pub fn synthetic(n: usize) -> Document {
if i % 3 == 1 {
node.opacity = 0.8;
}
if d.insert(Some(l), usize::MAX, node).is_err() {
break;
}
d.insert(Some(l), usize::MAX, node).expect("insert");
}
d
}
@@ -124,17 +122,8 @@ pub fn run(args: &[String]) -> Result<(), String> {
rows.push(("hit test (per click)", hits, 2.0));
let mut bytes = vec![];
let mut failed: Option<String> = None;
rows.push(("save .vectorcraft", median_ms(3, || bytes = vectorcraft_format::save_file(&doc)), 300.0));
rows.push((
"open .vectorcraft",
median_ms(3, || {
if let Err(e) = vectorcraft_format::load(&bytes) {
failed = Some(format!("open .vectorcraft: {e}"));
}
}),
300.0,
));
rows.push(("open .vectorcraft", median_ms(3, || drop(vectorcraft_format::load(&bytes).expect("load"))), 300.0));
let svg_opts = vectorcraft_svg::ExportOptions::default();
rows.push(("export SVG", median_ms(3, || drop(vectorcraft_svg::export(&doc, &svg_opts))), 500.0));
@@ -142,14 +131,10 @@ pub fn run(args: &[String]) -> Result<(), String> {
let unite = median_ms(3, || {
let mut s = vectorcraft_engine::Session::new();
s.add_document(synthetic(1000), None);
if let Err(e) = s.execute("select.all", &json!({})).and_then(|_| s.execute("object.pathfinder.unite", &json!({}))) {
failed = Some(format!("Pathfinder Unite: {e}"));
}
s.execute("select.all", &json!({})).expect("select");
s.execute("object.pathfinder.unite", &json!({})).expect("unite");
});
rows.push(("Pathfinder Unite, 1,000 paths", unite, 150.0));
if let Some(e) = failed {
return Err(e);
}
let mut over = 0;
println!(" {:<40} {:>10} {:>10}", "", "measured", "budget");
-1
View File
@@ -12,7 +12,6 @@
//! - dropped files are read asynchronously by `web::WebShell` and delivered through the inbox.
//!
//! URL query flag: `?webgl` forces the WebGL2 backend instead of WebGPU.
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
#[cfg(target_arch = "wasm32")]
mod web;
-1
View File
@@ -5,7 +5,6 @@
//! `--control <port>` (or `VECTORCRAFT_CONTROL_PORT`) starts a localhost JSON-lines control server:
//! `{"id":1,"method":"ui.inspect","params":{}}` → `{"id":1,"ok":true,"result":…}`.
//! See `vectorcraft_ui_egui::control` for the methods.
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
mod control_server;
#[cfg(target_os = "macos")]
+8 -4
View File
@@ -204,7 +204,7 @@ impl Mesh {
/// Band width (in vertices) of the vertex adjacency.
fn vertex_band(&self) -> usize {
self.tris.iter().map(|t| t.iter().max().unwrap() - t.iter().min().unwrap()).max().unwrap_or(0)
self.tris.iter().filter_map(|t| Some(t.iter().max()? - t.iter().min()?)).max().unwrap_or(0)
}
/// The triangle and barycentric coordinates of `p` (extrapolated from the nearest mesh cell
@@ -448,10 +448,12 @@ pub fn auto_pins(mesh: &Mesh, count: usize) -> Vec<Point> {
return vec![];
}
let c = centres.iter().fold(Vec2::ZERO, |a, p| a + p.to_vec2()) / centres.len() as f64;
let first = *centres.iter().min_by(|a, b| a.distance_squared(c.to_point()).total_cmp(&b.distance_squared(c.to_point()))).unwrap();
let Some(&first) = centres.iter().min_by(|a, b| a.distance_squared(c.to_point()).total_cmp(&b.distance_squared(c.to_point()))) else {
return vec![];
};
let mut out = vec![first];
while out.len() < count.min(centres.len()) {
let next = centres
let Some(next) = centres
.iter()
.max_by(|a, b| {
let da = out.iter().map(|o| o.distance_squared(**a)).fold(f64::MAX, f64::min);
@@ -459,7 +461,9 @@ pub fn auto_pins(mesh: &Mesh, count: usize) -> Vec<Point> {
da.total_cmp(&db)
})
.copied()
.unwrap();
else {
break;
};
out.push(next);
}
out
+1 -1
View File
@@ -218,7 +218,7 @@ pub fn dabs(points: &[Point], spacing: f64) -> Vec<Point> {
break;
}
}
let end = *points.last().unwrap();
let Some(&end) = points.last() else { return out };
if end.distance(last) > spacing * 0.25 {
out.push(end);
}
+8 -6
View File
@@ -128,10 +128,11 @@ impl Tool for AnchorTool {
*began = true;
}
}
out.push(match self.state {
State::Convert { id, si, ai, .. } => {
Action::Preview("path.convertAnchor".into(), json!({"id": id.0, "subpath": si, "anchor": ai, "to": "smooth", "x": p.x, "y": p.y}))
}
let preview = match self.state {
State::Convert { id, si, ai, .. } => Action::Preview(
"path.convertAnchor".into(),
json!({"id": id.0, "subpath": si, "anchor": ai, "to": "smooth", "x": p.x, "y": p.y}),
),
State::Handle { id, si, ai, out, .. } => Action::Preview(
"path.setHandle".into(),
json!({"id": id.0, "subpath": si, "anchor": ai, "which": if out { "out" } else { "in" }, "x": p.x, "y": p.y, "independent": true}),
@@ -140,8 +141,9 @@ impl Tool for AnchorTool {
"path.reshapeSegment".into(),
json!({"id": id.0, "subpath": si, "segment": seg, "t": t, "dx": p.x - start.x, "dy": p.y - start.y}),
),
State::Idle => unreachable!(),
});
State::Idle => return out,
};
out.push(preview);
out
}
("anchorPoint", PointerKind::Up) => {
+1
View File
@@ -6,6 +6,7 @@
//! and journal entry. One-shot `Exec` actions run immediately. This makes every gesture replayable
//! by the control channel and MCP, and keeps tools testable without a UI.
#![forbid(unsafe_code)]
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
pub mod bbox;
pub mod builder;
+1 -2
View File
@@ -137,9 +137,8 @@ impl TypeTool {
}
if self.typing.is_none() {
out.push(Action::Begin("Typing".into()));
self.typing = Some(Typing { base: t.runs.clone(), cur: t.runs.clone() });
}
let ty = self.typing.as_mut().expect("typing session");
let ty = self.typing.get_or_insert_with(|| Typing { base: t.runs.clone(), cur: t.runs.clone() });
let len = edit::runs_len(&ty.cur);
let (a, b) = (self.caret.min(self.anchor).min(len), self.caret.max(self.anchor).min(len));
let caret = match &styled {
+3 -2
View File
@@ -401,8 +401,9 @@ impl Tool for GradientTool {
}
(PointerKind::Drag, Some(g)) => return freeform::drag(cx, g, ev.pos),
(PointerKind::Up, Some(_)) => {
let g = self.free.take().expect("checked");
return freeform::release(cx, FreeformAnnotator::of(cx).as_ref(), g);
if let Some(g) = self.free.take() {
return freeform::release(cx, FreeformAnnotator::of(cx).as_ref(), g);
}
}
(PointerKind::DoubleClick, free) if free.is_some() || FreeformAnnotator::of(cx).is_some() => return vec![],
_ => {}
+1 -1
View File
@@ -107,7 +107,7 @@ pub fn fit(app: &mut VectorcraftApp, how: &str) {
_ => st.doc.artboards.first().map(|a| a.rect),
};
let Some(target) = target else { return };
let Some(v) = app.view_mut() else { return };
let v = app.view_mut().unwrap();
v.center = target.center();
v.fitted = true;
if how == "view.actualSize" {
-1
View File
@@ -4,7 +4,6 @@
//! (view/window) here and everything else to the engine. The same entry point serves menus,
//! shortcuts, the ⌘K palette and the control channel ([`control`]).
#![forbid(unsafe_code)]
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
mod brand;
pub mod canvas;
+1 -8
View File
@@ -1574,14 +1574,7 @@ pub fn pretty_shortcut(s: &str) -> String {
if cfg!(target_os = "macos") {
let mut mods = String::new();
let parts: Vec<&str> = s.split('+').collect();
let (key, ms) = if s.ends_with("++") {
("+", parts.get(..parts.len().saturating_sub(2)).unwrap_or_default())
} else {
match parts.split_last() {
Some((key, ms)) => (*key, ms),
None => (s, &[][..]),
}
};
let (key, ms) = if s.ends_with("++") { ("+", &parts[..parts.len() - 2]) } else { (*parts.last().unwrap(), &parts[..parts.len() - 1]) };
for m in ["Ctrl", "Alt", "Shift", "Cmd"] {
if ms.contains(&m) {
mods.push_str(match m {
+1 -1
View File
@@ -275,7 +275,7 @@ fn row(
}
if has_children && expanded.contains(&n.id.0) {
for (i, c) in n.children().map_or(&[][..], Vec::as_slice).iter().enumerate().rev() {
for (i, c) in n.children().unwrap().iter().enumerate().rev() {
row(ui, doc, c, depth + 1, i == 0 && n.clips(), sel, current, expanded, actions, t);
}
}
+1 -3
View File
@@ -676,9 +676,7 @@ pub(crate) fn tile_grid<'a, T>(ui: &mut Ui, items: &'a [T], view: View, is_folde
if len == per_row || (len > 0 && is_folder(e)) {
rows.push(vec![]);
}
if let Some(row) = rows.last_mut() {
row.push(e);
}
rows.last_mut().expect("a row").push(e);
}
let mut out = Vec::with_capacity(items.len());
for row in rows {