Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Pathfinder: Crop works on a selected group of shapes

Wadah Badawi6eea3a5178c0
diff --git a/contributors/people.toml b/contributors/people.toml
index 55b5b3860..f3c8629b7 100644
--- a/contributors/people.toml
+++ b/contributors/people.toml
@@ -185,3 +185,7 @@ sync_github_name = true
display_name = "Arshiya"
real_name = "Arshiya Rahgozar"
sync_github_name = false
+
+[people.WadahBadawi]
+display_name = "Wadah Badawi"
+sync_github_name = true
diff --git a/crates/engine/src/cmd/pathops.rs b/crates/engine/src/cmd/pathops.rs
index 66c01f4c5..f002dd7ba 100644
--- a/crates/engine/src/cmd/pathops.rs
+++ b/crates/engine/src/cmd/pathops.rs
@@ -15,8 +15,8 @@ use vectorcraft_pathops::{BoolOp, PathfinderOp};
use super::edit::selected_roots;
use super::{
- CommandSpec, EngineError, Result, Session, always, bad, bool_or, checked_ids_or_selection, cmd, has_doc, has_multi, has_selection, number_or,
- str_param, switch_or,
+ CommandSpec, EngineError, Result, Session, always, bad, bool_or, checked_ids_or_selection, cmd, has_doc, has_selection, number_or, str_param,
+ switch_or,
};
pub fn specs() -> Vec<CommandSpec> {
@@ -90,7 +90,7 @@ pub fn specs() -> Vec<CommandSpec> {
["Window", "Pathfinder"],
None,
"{ids?: [id…] (selected first; default: the selection), precision?: pt 0.001..10, removeRedundantPoints?: bool, removeUnpainted?: bool (default: the Pathfinder Options, see object.pathfinder.options; the values used join the journal entry)} operate on the selected objects (back → front) → {ids}",
- has_multi,
+ has_selection,
|s, p| run_pf(s, p, PathfinderOp::Crop)
),
cmd!(
diff --git a/crates/engine/src/tests/pathops.rs b/crates/engine/src/tests/pathops.rs
index 8b93c4e89..2eaeeb594 100644
--- a/crates/engine/src/tests/pathops.rs
+++ b/crates/engine/src/tests/pathops.rs
@@ -1293,3 +1293,18 @@ fn pathfinder_journal_entries_replay_with_the_options_they_used() {
// Options given as params are checked as object.pathfinder.options checks them.
assert!(s.execute("object.pathfinder.divide", &json!({"precision": 20})).is_err());
}
+
+/// A single group containing multiple overlapping paths is accepted by Crop.
+#[test]
+fn crop_operates_on_a_single_selected_group_of_paths() {
+ let mut s = session();
+ let a = rect(&mut s, 0.0, 0.0, 100.0, 100.0);
+ let b = rect(&mut s, 50.0, 50.0, 100.0, 100.0);
+ s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
+ let g = s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap();
+ s.execute("select.set", &json!({"ids": [g]})).unwrap();
+ assert_eq!(s.doc().unwrap().selection.len(), 1);
+ let out = s.execute("object.pathfinder.crop", &json!({})).unwrap();
+ let cropped_ids = ids(&out);
+ assert!(!cropped_ids.is_empty());
+}