mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-01 02:04:59 -06:00
Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f032b2c22c | ||
|
|
a07fb30823 | ||
|
|
500a90c77a | ||
|
|
f41ae04700 | ||
|
|
8a9159a401 | ||
|
|
e779415cce | ||
|
|
99b600081f | ||
|
|
996d67c1a6 | ||
|
|
f0c4bd6e6f | ||
|
|
39d8c5d7dd | ||
|
|
0666ef9980 | ||
|
|
6cf5280038 | ||
|
|
ffcb3fe68a | ||
|
|
767221ca06 |
@@ -34,7 +34,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Connect Shapes",
|
||||
[],
|
||||
None,
|
||||
"{from: shape id, to: shape id, fromSite?, toSite?: site index (default: the closest pair), id?: existing line to glue (else a new connector), preset?: straightConnector1|bentConnector3|curvedConnector3} → {id}",
|
||||
"{from: shape id, to: shape id, fromSite?, toSite?: site index (default: with neither given, the sites facing each other along the dominant direction between the shapes, a tie to the lower index; with one given, the closest site of the other shape; a box has 0 top, 1 left, 2 bottom, 3 right; shape.sites lists them), id?: existing line to glue (else a new connector), preset?: straightConnector1|bentConnector3|curvedConnector3} → {id}",
|
||||
has_slide,
|
||||
connect
|
||||
),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{ColorRef, Fill, Geom, Line, NO_ID_SPACE, Result, Session, Value, bad, bool_or, id_param, json, str_param, usize_param};
|
||||
use super::{ColorRef, Fill, Geom, Line, NO_ID_SPACE, Result, Session, Value, bad, bool_or, id_param, json, str_param, usize_param, xfrm_of};
|
||||
|
||||
pub(super) fn sites(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let id = id_param(p, "id", "shape.sites")?.ok_or_else(|| bad("shape.sites", "missing `id`"))?;
|
||||
@@ -24,20 +24,50 @@ pub(super) fn connect(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
return Err(bad("shape.connect", "both shapes need connection sites (lines and groups have none)"));
|
||||
}
|
||||
let pick = |v: &[deckcraft_geom::Point], key: &str| usize_param(p, key).filter(|i| *i < v.len());
|
||||
// A site left unsaid is the one facing the other shape along the dominant direction between
|
||||
// the two (a box mostly below is left from the bottom), which is where a person glues an
|
||||
// arrow; "the closest pair" chose a side site for a diagonal neighbour and crossed boxes.
|
||||
// The direction runs between the shapes' box centres: the mean of the sites is off-centre
|
||||
// for a shape whose sites are not symmetric (a triangle's lie mostly along its base).
|
||||
// In slide space, as the sites are: a shape inside a group is placed where the group draws it.
|
||||
let centre = |id| {
|
||||
crate::connect::locate(&st.doc, &st.selection, st.shapes(), id)
|
||||
.map(|(sh, to_abs)| to_abs * xfrm_of(&st.doc, &st.selection, sh).center())
|
||||
.unwrap_or_default()
|
||||
};
|
||||
let (ca, cb) = (centre(from), centre(to));
|
||||
// A tie goes to the lowest site index: an exact diagonal leaves a box from its bottom (site 2,
|
||||
// before the right side, 3) and enters the other at its top (0, before the left side, 1), and
|
||||
// shapes with one centre, where every direction is as good, both take site 0.
|
||||
let facing = |v: &[deckcraft_geom::Point], c: deckcraft_geom::Point, dx: f64, dy: f64| {
|
||||
let len = dx.hypot(dy).max(1e-9);
|
||||
let cos: Vec<f64> = v
|
||||
.iter()
|
||||
.map(|q| {
|
||||
let (sx, sy) = (q.x - c.x, q.y - c.y);
|
||||
(sx * dx + sy * dy) / (sx.hypot(sy).max(1e-9) * len)
|
||||
})
|
||||
.collect();
|
||||
let best = cos.iter().copied().fold(f64::NEG_INFINITY, f64::max);
|
||||
cos.iter().position(|x| *x >= best - 1e-9).unwrap_or(0)
|
||||
};
|
||||
// With one site given, the other end is the site of the other shape closest to it, as before;
|
||||
// the facing rule is for the case where neither is given.
|
||||
let closest = |v: &[deckcraft_geom::Point], to: deckcraft_geom::Point| {
|
||||
let mut best = (f64::MAX, 0);
|
||||
for (i, q) in v.iter().enumerate() {
|
||||
let d = (*q - to).hypot();
|
||||
if d < best.0 {
|
||||
best = (d, i);
|
||||
}
|
||||
}
|
||||
best.1
|
||||
};
|
||||
let (ia, ib) = match (pick(&a, "fromSite"), pick(&b, "toSite")) {
|
||||
(Some(i), Some(j)) => (i, j),
|
||||
(fi, fj) => {
|
||||
let mut best = (f64::MAX, 0, 0);
|
||||
for (i, pa) in a.iter().enumerate().filter(|(i, _)| fi.is_none_or(|f| f == *i)) {
|
||||
for (j, pb) in b.iter().enumerate().filter(|(j, _)| fj.is_none_or(|f| f == *j)) {
|
||||
let d = (*pa - *pb).hypot();
|
||||
if d < best.0 {
|
||||
best = (d, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
(best.1, best.2)
|
||||
}
|
||||
(Some(i), None) => (i, closest(&b, a[i])),
|
||||
(None, Some(j)) => (closest(&a, b[j]), j),
|
||||
(None, None) => (facing(&a, ca, cb.x - ca.x, cb.y - ca.y), facing(&b, cb, ca.x - cb.x, ca.y - cb.y)),
|
||||
};
|
||||
let (p0, p1) = (a[ia], b[ib]);
|
||||
let id = match id_param(p, "id", "shape.connect")? {
|
||||
|
||||
@@ -7189,6 +7189,50 @@ fn invalid_slide_index_never_falls_back_to_the_selection_in_export_commands() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// G6: with no sites given, shape.connect joins the sites that face each other along the
|
||||
/// dominant direction between the two shapes (a box mostly below leaves from the bottom), not
|
||||
/// "the closest pair", which for a diagonal neighbour picked a side site and crossed boxes.
|
||||
#[test]
|
||||
fn connector_default_sites_follow_the_dominant_direction() {
|
||||
let mut s = session();
|
||||
let a = s.execute("shape.insert", &json!({"preset": "rect", "rect": [0, 0, 100, 50]})).unwrap()["id"].as_u64().unwrap();
|
||||
let diag = s.execute("shape.insert", &json!({"preset": "rect", "rect": [150, 200, 100, 50]})).unwrap()["id"].as_u64().unwrap();
|
||||
let r = s.execute("shape.connect", &json!({"from": a, "to": diag})).unwrap();
|
||||
assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(2), Some(0)), "mostly below: bottom → top, not right → left: {r}");
|
||||
let r = s.execute("shape.connect", &json!({"from": diag, "to": a})).unwrap();
|
||||
assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(0), Some(2)), "and back: top → bottom: {r}");
|
||||
// The direction runs between the shapes' centres, not between the means of their sites: a
|
||||
// triangle's sites lie mostly along its base, which pulled the direction sideways and chose
|
||||
// the box's left site for a box that is mostly below.
|
||||
let tri = s.execute("shape.insert", &json!({"preset": "triangle", "rect": [400, 0, 100, 100]})).unwrap()["id"].as_u64().unwrap();
|
||||
let below = s.execute("shape.insert", &json!({"preset": "rect", "rect": [520, 155, 100, 50]})).unwrap()["id"].as_u64().unwrap();
|
||||
let r = s.execute("shape.connect", &json!({"from": tri, "to": below})).unwrap();
|
||||
assert_eq!(r["toSite"].as_u64(), Some(0), "centre to centre is mostly down: the box's top, not its left: {r}");
|
||||
// An exact diagonal ties the bottom with the right side (and the top with the left): the lower
|
||||
// site index wins, so bottom → top, and top → bottom back.
|
||||
let p = s.execute("shape.insert", &json!({"preset": "rect", "rect": [0, 300, 100, 50]})).unwrap()["id"].as_u64().unwrap();
|
||||
let q = s.execute("shape.insert", &json!({"preset": "rect", "rect": [200, 500, 100, 50]})).unwrap()["id"].as_u64().unwrap();
|
||||
let sites = |s: &mut Session, from: u64, to: u64| {
|
||||
let r = s.execute("shape.connect", &json!({"from": from, "to": to})).unwrap();
|
||||
(r["fromSite"].as_u64(), r["toSite"].as_u64())
|
||||
};
|
||||
assert_eq!(sites(&mut s, p, q), (Some(2), Some(0)));
|
||||
assert_eq!(sites(&mut s, q, p), (Some(0), Some(2)));
|
||||
// Shapes with one centre tie every site: site 0 on both.
|
||||
let big = s.execute("shape.insert", &json!({"preset": "rect", "rect": [600, 300, 200, 100]})).unwrap()["id"].as_u64().unwrap();
|
||||
let small = s.execute("shape.insert", &json!({"preset": "rect", "rect": [650, 325, 100, 50]})).unwrap()["id"].as_u64().unwrap();
|
||||
assert_eq!(sites(&mut s, big, small), (Some(0), Some(0)));
|
||||
// One site given: the other end is the other shape's site closest to it, as before the facing
|
||||
// rule (which is for when neither is given). From a's right side (100, 25) the diagonal box's
|
||||
// top (200, 200) is nearest; to its left side (150, 225), a's bottom (50, 50).
|
||||
let r = s.execute("shape.connect", &json!({"from": a, "to": diag, "fromSite": 3})).unwrap();
|
||||
assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(3), Some(0)), "fromSite only: {r}");
|
||||
let r = s.execute("shape.connect", &json!({"from": a, "to": diag, "toSite": 1})).unwrap();
|
||||
assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(2), Some(1)), "toSite only: {r}");
|
||||
let r = s.execute("shape.connect", &json!({"from": a, "to": diag, "fromSite": 2, "toSite": 3})).unwrap();
|
||||
assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(2), Some(3)), "both given: {r}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn highlight_with_an_invalid_colour_is_rejected_and_keeps_the_highlight() {
|
||||
let mut s = session();
|
||||
|
||||
+34
-10
@@ -44,16 +44,27 @@ overrides:
|
||||
- mesa-vulkan-drivers
|
||||
- xdg-desktop-portal
|
||||
rpm:
|
||||
# Library sonames rather than package names, so the same requirements resolve on Fedora/RHEL
|
||||
# and openSUSE (which has no libxkbcommon, vulkan-loader or libglvnd-egl package). The glibc
|
||||
# floor names libm because the binaries' GLIBC_2.35 symbols (hypot, hypotf) are libm's: RHEL 9's
|
||||
# glibc 2.34 provides libc.so.6(GLIBC_2.35) through backports, but not this, so it refuses.
|
||||
depends:
|
||||
- libxkbcommon
|
||||
- alsa-lib
|
||||
- (vulkan-loader or libglvnd-egl)
|
||||
- libc.so.6()(64bit)
|
||||
- libm.so.6(GLIBC_2.35)(64bit)
|
||||
- libgcc_s.so.1()(64bit)
|
||||
- libxkbcommon.so.0()(64bit)
|
||||
- (libvulkan.so.1()(64bit) or libEGL.so.1()(64bit))
|
||||
- libasound.so.2()(64bit)
|
||||
# The windowing libraries the GUI loads at runtime, by soname too, so the recommendations resolve on
|
||||
# openSUSE as well. Without libX11-xcb and libxkbcommon-x11 the GUI cannot start on X11.
|
||||
recommends:
|
||||
- libwayland-client
|
||||
- libX11
|
||||
- libXcursor
|
||||
- libXi
|
||||
- libXrandr
|
||||
- libwayland-client.so.0()(64bit)
|
||||
- libX11.so.6()(64bit)
|
||||
- libXcursor.so.1()(64bit)
|
||||
- libXi.so.6()(64bit)
|
||||
- libX11-xcb.so.1()(64bit)
|
||||
- libxkbcommon-x11.so.0()(64bit)
|
||||
- libwayland-egl.so.1()(64bit)
|
||||
- mesa-vulkan-drivers
|
||||
- xdg-desktop-portal
|
||||
|
||||
@@ -64,11 +75,24 @@ contents:
|
||||
- src: ${STAGE}/usr/bin/${NFPM_CLI}
|
||||
dst: /usr/bin/${NFPM_CLI}
|
||||
file_info: { mode: 0755 }
|
||||
# Named one by one rather than as a tree of /usr/share: a tree would also own shared directories
|
||||
# such as /usr/share/mime, which openSUSE's filesystem package owns with other modes, and RPM
|
||||
# refuses to install a package that conflicts with it. ${NFPM_DESK_ID} and ${NFPM_NAME} are filled
|
||||
# in by package.sh (a Nightly renames them), which also drops the mime entry when none is staged.
|
||||
- src: ${STAGE}/usr/share/applications/${NFPM_DESK_ID}.desktop
|
||||
dst: /usr/share/applications/${NFPM_DESK_ID}.desktop
|
||||
- src: ${STAGE}/usr/share/mime/packages/ai.storyteller.deckcraft.xml
|
||||
dst: /usr/share/mime/packages/ai.storyteller.deckcraft.xml
|
||||
- src: ${STAGE}/usr/share/metainfo/${NFPM_DESK_ID}.metainfo.xml
|
||||
dst: /usr/share/metainfo/${NFPM_DESK_ID}.metainfo.xml
|
||||
- src: ${STAGE}/usr/share/icons/hicolor/
|
||||
dst: /usr/share/icons/hicolor/
|
||||
type: tree
|
||||
- src: ${STAGE}/usr/lib/
|
||||
dst: /usr/lib/
|
||||
type: tree
|
||||
- src: ${STAGE}/usr/share/
|
||||
dst: /usr/share/
|
||||
- src: ${STAGE}/usr/share/doc/${NFPM_NAME}/
|
||||
dst: /usr/share/doc/${NFPM_NAME}/
|
||||
type: tree
|
||||
|
||||
scripts:
|
||||
|
||||
@@ -151,6 +151,7 @@ if has deb || has rpm; then
|
||||
export NFPM_NAME="deckcraft"
|
||||
export NFPM_BIN="deckcraft"
|
||||
export NFPM_CLI="deckcraft-cli"
|
||||
NFPM_DESK_ID="$APP_ID"
|
||||
if [[ "$IS_NIGHTLY" = 1 ]]; then
|
||||
NIGHTLY_DESK_ID="$APP_ID.nightly-v1"
|
||||
NIGHTLY_ICON="$ROOT/assets/app-icon/deckcraft-nightly.png"
|
||||
@@ -158,6 +159,7 @@ if has deb || has rpm; then
|
||||
export NFPM_NAME="deckcraft-nightly"
|
||||
export NFPM_BIN="deckcraft-nightly"
|
||||
export NFPM_CLI="deckcraft-nightly-cli"
|
||||
NFPM_DESK_ID="$NIGHTLY_DESK_ID"
|
||||
NFPM_STAGE="$WORK/nfpm-root"
|
||||
rm -rf "$NFPM_STAGE"
|
||||
cp -R "$STAGE" "$NFPM_STAGE"
|
||||
@@ -192,8 +194,12 @@ if has deb || has rpm; then
|
||||
DROP_LIB_TREE=
|
||||
# shellcheck disable=SC2016
|
||||
[[ -d "$NFPM_STAGE/usr/lib" ]] || DROP_LIB_TREE='\|^ - src: \${STAGE}/usr/lib/|,+2d;'
|
||||
# nfpm refuses a named file that isn't staged, and a Nightly stages no mime file.
|
||||
DROP_MIME=
|
||||
# shellcheck disable=SC2016
|
||||
sed "${DROP_LIB_TREE}s|\${STAGE}|$NFPM_STAGE|g;s|\${NFPM_BIN}|$NFPM_BIN|g;s|\${NFPM_CLI}|$NFPM_CLI|g" "$HERE/nfpm.yaml" >"$WORK/nfpm.yaml"
|
||||
[[ -d "$NFPM_STAGE/usr/share/mime" ]] || DROP_MIME='\|^ - src: \${STAGE}/usr/share/mime/|,+1d;'
|
||||
# shellcheck disable=SC2016
|
||||
sed "${DROP_LIB_TREE}${DROP_MIME}s|\${STAGE}|$NFPM_STAGE|g;s|\${NFPM_BIN}|$NFPM_BIN|g;s|\${NFPM_CLI}|$NFPM_CLI|g;s|\${NFPM_DESK_ID}|$NFPM_DESK_ID|g;s|\${NFPM_NAME}|$NFPM_NAME|g" "$HERE/nfpm.yaml" >"$WORK/nfpm.yaml"
|
||||
for fmt in deb rpm; do
|
||||
if has "$fmt"; then (cd "$ROOT" && nfpm package -f "$WORK/nfpm.yaml" -p "$fmt" -t "$DIST/$BASENAME.$fmt"); fi
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user