mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-12-05 19:12:08 -10:00
Compare commits
22
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1db3026a2 | ||
|
|
91c7236e10 | ||
|
|
fa686d5063 | ||
|
|
7d8f124539 | ||
|
|
78a1be4059 | ||
|
|
a7ed5fcf0f | ||
|
|
48fe21ebe3 | ||
|
|
0ab2f21e47 | ||
|
|
d73bd34750 | ||
|
|
4f999ea73b | ||
|
|
80f9dbb992 | ||
|
|
9fd1011e1e | ||
|
|
3d4d7d1058 | ||
|
|
401cf1419a | ||
|
|
369671dc41 | ||
|
|
fe505edeff | ||
|
|
63a8befe4b | ||
|
|
3e380b8cd7 | ||
|
|
634c30bebf | ||
|
|
1e912de804 | ||
|
|
ea9c44e003 | ||
|
|
6a28b82b91 |
No files matched your search
@@ -150,14 +150,20 @@ jobs:
|
||||
run: cargo run build web${{ inputs.debug && ' debug' || '' }}
|
||||
|
||||
- name: 📤 Publish to Cloudflare Pages
|
||||
if: inputs.merge_queue == false && !github.event.pull_request.head.repo.fork
|
||||
if: inputs.merge_queue == false
|
||||
id: cloudflare
|
||||
continue-on-error: ${{ github.event_name != 'push' }}
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
# Passed through the environment so a branch name can't inject shell syntax
|
||||
HEAD_BRANCH: ${{ inputs.checkout_ref || github.head_ref || github.ref_name }}
|
||||
run: |
|
||||
if [ -z "$CLOUDFLARE_API_TOKEN" ]; then
|
||||
echo "No Cloudflare API token available (fork PR), skipping deploy."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "${{ github.event_name }}" = "push" ]; then
|
||||
DEPLOY_BRANCH="master"
|
||||
else
|
||||
|
||||
@@ -7,8 +7,6 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
# Runs the checks on a pushed branch that has no PR yet, such as each branch of a stack
|
||||
workflow_dispatch: {}
|
||||
|
||||
# Cancel a PR's in-progress checks once a newer commit is pushed to it (other runs are keyed by their commit, so those never cancel each other)
|
||||
concurrency:
|
||||
@@ -247,8 +245,7 @@ jobs:
|
||||
permissions:
|
||||
contents: read
|
||||
env:
|
||||
# A manual run has no base commit of its own, so it compares against master
|
||||
BASE_REF: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || 'master' }}
|
||||
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
|
||||
steps:
|
||||
- name: 📥 Clone repository
|
||||
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
|
||||
@@ -262,9 +259,7 @@ jobs:
|
||||
rustflags: ""
|
||||
|
||||
- name: 📥 Fetch the base commit
|
||||
run: |
|
||||
git fetch --depth=1 origin "$BASE_REF"
|
||||
echo "BASE_SHA=$(git rev-parse FETCH_HEAD)" >> "$GITHUB_ENV"
|
||||
run: git fetch --depth=1 origin "$BASE_SHA"
|
||||
|
||||
- name: 🔬 Check migrations against the base commit
|
||||
run: cargo run --locked --package migration-snapshot -- check --baseline "$BASE_SHA"
|
||||
|
||||
@@ -51,8 +51,6 @@ jobs:
|
||||
with:
|
||||
# Cache on Cargo.lock file
|
||||
cache-on-failure: true
|
||||
# Saved only by master pushes, since a PR's saved cache is readable only by that PR yet counts toward the repo's size limit
|
||||
save-if: ${{ github.event_name == 'push' }}
|
||||
|
||||
- name: Install gungraun-runner and valgrind
|
||||
uses: gungraun/setup-gungraun@62591572561bb2f4ed2ae300b8a8bea99ea8ddaf # v1.1.3
|
||||
|
||||
Generated
+173
-25
@@ -590,7 +590,6 @@ dependencies = [
|
||||
"node-macro",
|
||||
"raster-kernels",
|
||||
"serde",
|
||||
"text-nodes",
|
||||
"vector-types",
|
||||
]
|
||||
|
||||
@@ -1227,6 +1226,7 @@ dependencies = [
|
||||
"kurbo",
|
||||
"log",
|
||||
"lyon_geom",
|
||||
"math-parser",
|
||||
"node-macro",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
@@ -1239,7 +1239,7 @@ dependencies = [
|
||||
"rustc-hash 2.1.3",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"skrifa",
|
||||
"skrifa 0.44.0",
|
||||
"tinyvec",
|
||||
"tsify",
|
||||
"wasm-bindgen",
|
||||
@@ -2136,6 +2136,9 @@ name = "float-cmp"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
@@ -2155,6 +2158,15 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
||||
|
||||
[[package]]
|
||||
name = "font-types"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b38ad915f6dadd993ced50848a8291a543bd41ca62bc10740d5e64e2ab4cfd7"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "font-types"
|
||||
version = "0.12.7"
|
||||
@@ -2196,7 +2208,7 @@ dependencies = [
|
||||
"linebender_resource_handle",
|
||||
"memmap2",
|
||||
"parlance",
|
||||
"read-fonts",
|
||||
"read-fonts 0.41.0",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
@@ -2746,9 +2758,8 @@ dependencies = [
|
||||
"fd-lock",
|
||||
"futures",
|
||||
"glam",
|
||||
"graphite-desktop-ui-cef",
|
||||
"graphite-desktop-ui",
|
||||
"graphite-desktop-wrapper",
|
||||
"graphite-wasm-wrapper",
|
||||
"interprocess",
|
||||
"lzma-rust2",
|
||||
"muda",
|
||||
@@ -2779,6 +2790,13 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphite-desktop-embedded-resources"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"include_dir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphite-desktop-platform-linux"
|
||||
version = "0.0.0"
|
||||
@@ -2791,7 +2809,7 @@ name = "graphite-desktop-platform-mac"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"graphite-desktop",
|
||||
"graphite-desktop-ui-cef",
|
||||
"graphite-desktop-ui",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2803,14 +2821,14 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphite-desktop-ui-cef"
|
||||
name = "graphite-desktop-ui"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"ash",
|
||||
"bytemuck",
|
||||
"cef",
|
||||
"dirs",
|
||||
"graphite-desktop-ui-cef-embedded-resources",
|
||||
"graphite-desktop-embedded-resources",
|
||||
"ipc-channel",
|
||||
"libc",
|
||||
"mach2",
|
||||
@@ -2830,13 +2848,6 @@ dependencies = [
|
||||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphite-desktop-ui-cef-embedded-resources"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"include_dir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "graphite-desktop-wrapper"
|
||||
version = "0.0.0"
|
||||
@@ -2844,6 +2855,7 @@ dependencies = [
|
||||
"base64 0.23.1",
|
||||
"graph-craft",
|
||||
"graphite-editor",
|
||||
"graphite-wasm-wrapper",
|
||||
"image",
|
||||
"keyboard-types",
|
||||
"serde",
|
||||
@@ -3040,7 +3052,7 @@ checksum = "c03d949a14aa089bbb282f7dd76a498a7f684428e4257202efc119ec010376f9"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"bytemuck",
|
||||
"read-fonts",
|
||||
"read-fonts 0.41.0",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
@@ -3075,6 +3087,40 @@ dependencies = [
|
||||
"foldhash 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hayro-ccitt"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adbed896e99325bc312778bb9c9c289d795d51c12775c44dd5e4352f679c7e46"
|
||||
|
||||
[[package]]
|
||||
name = "hayro-jbig2"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb5c7f3a4eb551c2bb7fa16e268f728d4bc2a5c9b090554b8dc0ee2503fb5840"
|
||||
dependencies = [
|
||||
"hayro-ccitt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hayro-jpeg2000"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e5e5f2b3de970707fc22fd956d8f44211602939d5e4588603afa919cb7b3740"
|
||||
|
||||
[[package]]
|
||||
name = "hayro-syntax"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6ced8279487b029813f6cc05399099fa34df6fa23d8f7b0d41d972c49d5b30d"
|
||||
dependencies = [
|
||||
"hayro-jbig2",
|
||||
"hayro-jpeg2000",
|
||||
"rustc-hash 2.1.3",
|
||||
"smallvec",
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
@@ -3428,6 +3474,12 @@ dependencies = [
|
||||
"quick-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "imagesize"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09e54e57b4c48b40f7aec75635392b12b3421fa26fe8b4332e63138ed278459c"
|
||||
|
||||
[[package]]
|
||||
name = "imagesize"
|
||||
version = "0.15.0"
|
||||
@@ -3800,6 +3852,33 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "krilla"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27da593198b20eeba65caeb73c2bbeec3e53ab08fa549898312ce81c4fce5e33"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"bumpalo",
|
||||
"flate2",
|
||||
"float-cmp",
|
||||
"gif",
|
||||
"image-webp",
|
||||
"imagesize 0.14.0",
|
||||
"indexmap",
|
||||
"pdf-writer",
|
||||
"png 0.18.1",
|
||||
"rustc-hash 2.1.3",
|
||||
"siphasher",
|
||||
"skrifa 0.42.1",
|
||||
"smallvec",
|
||||
"subsetter",
|
||||
"tiny-skia-path",
|
||||
"xmp-writer",
|
||||
"yoke",
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kurbo"
|
||||
version = "0.13.1"
|
||||
@@ -5033,7 +5112,7 @@ dependencies = [
|
||||
"parlance",
|
||||
"parley_data",
|
||||
"parley_emoji",
|
||||
"skrifa",
|
||||
"skrifa 0.44.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5064,6 +5143,18 @@ dependencies = [
|
||||
"vector-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pdf-writer"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5e456864a7a304047bff84977dc6fb162bd956475d40ba50b2dcecaada7f753"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "peer-transport"
|
||||
version = "0.0.0"
|
||||
@@ -5746,7 +5837,6 @@ dependencies = [
|
||||
"glam",
|
||||
"graphene-resource",
|
||||
"graphic-types",
|
||||
"half",
|
||||
"log",
|
||||
"raster-types",
|
||||
"thiserror 2.0.21",
|
||||
@@ -5867,6 +5957,16 @@ dependencies = [
|
||||
"yasna",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "read-fonts"
|
||||
version = "0.39.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4ed38b89c2c77ff968c524145ad65fb010f38af5c7a224b53b81d47ac2daa81"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"font-types 0.11.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "read-fonts"
|
||||
version = "0.41.0"
|
||||
@@ -5874,7 +5974,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "046a7d674daf459825b32f5062056d6882db0d2f5a479fbd76ccfc870ac18709"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"font-types",
|
||||
"font-types 0.12.7",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
@@ -6020,14 +6120,15 @@ dependencies = [
|
||||
"graphene-hash",
|
||||
"graphene-resource",
|
||||
"graphic-types",
|
||||
"hayro-syntax",
|
||||
"krilla",
|
||||
"kurbo",
|
||||
"linesweeper",
|
||||
"log",
|
||||
"num-traits",
|
||||
"parley",
|
||||
"raster-kernels",
|
||||
"serde",
|
||||
"skrifa",
|
||||
"skrifa 0.44.0",
|
||||
"text-nodes",
|
||||
"usvg",
|
||||
"vector-types",
|
||||
@@ -6605,6 +6706,12 @@ version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
@@ -6966,6 +7073,16 @@ version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33f4fe9184a62d842c9ef383018f3306d8ba224fd9d836f56d7288308847c256"
|
||||
|
||||
[[package]]
|
||||
name = "skrifa"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c34617370ae968efb7161bb2beb517d9084659aae19e24b89e3db25b46e4564"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"read-fonts 0.39.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "skrifa"
|
||||
version = "0.44.0"
|
||||
@@ -6973,7 +7090,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819ab7d62b1d3e72d9d9dea5650bac30424f9111364bb94928dbf5ecad1baa68"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"read-fonts",
|
||||
"read-fonts 0.41.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7152,6 +7269,18 @@ version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "subsetter"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38803281d1c23166c5ebcb455439a5d2afe711cc909cf88af72448c297756ad6"
|
||||
dependencies = [
|
||||
"kurbo",
|
||||
"rustc-hash 2.1.3",
|
||||
"skrifa 0.42.1",
|
||||
"write-fonts",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substring"
|
||||
version = "1.4.5"
|
||||
@@ -7334,7 +7463,7 @@ dependencies = [
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"skrifa",
|
||||
"skrifa 0.44.0",
|
||||
"thiserror 2.0.21",
|
||||
"titlecase",
|
||||
"tsify",
|
||||
@@ -7934,14 +8063,14 @@ dependencies = [
|
||||
"flate2",
|
||||
"fontdb",
|
||||
"harfrust",
|
||||
"imagesize",
|
||||
"imagesize 0.15.0",
|
||||
"kurbo",
|
||||
"log",
|
||||
"pico-args",
|
||||
"roxmltree 0.21.2",
|
||||
"simplecss",
|
||||
"siphasher",
|
||||
"skrifa",
|
||||
"skrifa 0.44.0",
|
||||
"strict-num",
|
||||
"svgtypes",
|
||||
"tiny-skia-path",
|
||||
@@ -9284,6 +9413,19 @@ dependencies = [
|
||||
"toml 0.5.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "write-fonts"
|
||||
version = "0.48.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb731d4c4d93eacc69a1ad2f270f905788a98e4a3438267bcafbe08d3431c8d8"
|
||||
dependencies = [
|
||||
"font-types 0.11.3",
|
||||
"indexmap",
|
||||
"kurbo",
|
||||
"log",
|
||||
"read-fonts 0.39.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "writeable"
|
||||
version = "0.6.4"
|
||||
@@ -9424,6 +9566,12 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9"
|
||||
|
||||
[[package]]
|
||||
name = "xmp-writer"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9440ea3e5aeabb0ac63af70daf835274065238cdd0cec83418f417eae38bacee"
|
||||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "1.0.1"
|
||||
|
||||
+3
-1
@@ -3,7 +3,7 @@ members = [
|
||||
"desktop",
|
||||
"desktop/wrapper",
|
||||
"desktop/ui",
|
||||
"desktop/ui/embedded-resources",
|
||||
"desktop/embedded-resources",
|
||||
"desktop/bundle",
|
||||
"desktop/platform/linux",
|
||||
"desktop/platform/mac",
|
||||
@@ -223,6 +223,8 @@ skrifa = "0.44"
|
||||
polycool = "0.4"
|
||||
color = "0.3"
|
||||
# Linebender ecosystem (END)
|
||||
krilla = { version = "0.8", default-features = false, features = ["raster-images"] }
|
||||
hayro-syntax = { version = "0.9", default-features = false, features = ["std"] }
|
||||
rand = { version = "0.10", default-features = false, features = ["std_rng"] }
|
||||
rand_chacha = "0.10"
|
||||
glam = { version = "0.34", default-features = false, features = [
|
||||
|
||||
+3
-4
@@ -21,14 +21,13 @@ path = "src/main.rs"
|
||||
[features]
|
||||
default = ["recommended", "embedded_resources"]
|
||||
recommended = ["accelerated_paint"]
|
||||
embedded_resources = ["graphite-desktop-ui-cef/embedded_resources"]
|
||||
accelerated_paint = ["graphite-desktop-ui-cef/accelerated_paint"]
|
||||
embedded_resources = ["graphite-desktop-ui/embedded_resources"]
|
||||
accelerated_paint = ["graphite-desktop-ui/accelerated_paint"]
|
||||
|
||||
[dependencies]
|
||||
# Local dependencies
|
||||
graphite-desktop-wrapper = { path = "wrapper" }
|
||||
graphite-desktop-ui-cef = { path = "ui" }
|
||||
graphite-wasm-wrapper = { path = "../frontend/wrapper", default-features = false, features = ["editor"] }
|
||||
graphite-desktop-ui = { path = "ui" }
|
||||
|
||||
wgpu = { workspace = true }
|
||||
winit = { workspace = true, features = [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "graphite-desktop-ui-cef-embedded-resources"
|
||||
name = "graphite-desktop-embedded-resources"
|
||||
description = "Graphite Desktop Embedded Resources"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
@@ -1,5 +1,5 @@
|
||||
const EMBEDDED_RESOURCES_ENV: &str = "EMBEDDED_RESOURCES";
|
||||
const DEFAULT_RESOURCES_DIR: &str = "../../../frontend/dist";
|
||||
const DEFAULT_RESOURCES_DIR: &str = "../../frontend/dist";
|
||||
|
||||
fn main() {
|
||||
let mut embedded_resources: Option<String> = None;
|
||||
File renamed without changes.
@@ -16,7 +16,7 @@ workspace = true
|
||||
|
||||
[features]
|
||||
main = ["dep:graphite-desktop"]
|
||||
helper = ["dep:graphite-desktop-ui-cef"]
|
||||
helper = ["dep:graphite-desktop-ui"]
|
||||
|
||||
[[bin]]
|
||||
name = "graphite"
|
||||
@@ -30,4 +30,4 @@ required-features = ["helper"]
|
||||
|
||||
[dependencies]
|
||||
graphite-desktop = { path = "../..", optional = true }
|
||||
graphite-desktop-ui-cef = { path = "../../ui", optional = true }
|
||||
graphite-desktop-ui = { path = "../../ui", optional = true }
|
||||
@@ -1,3 +1,3 @@
|
||||
fn main() -> std::process::ExitCode {
|
||||
graphite_desktop_ui_cef::run_helper()
|
||||
graphite_desktop_ui::run_helper()
|
||||
}
|
||||
+18
-11
@@ -20,13 +20,13 @@ use crate::dirs;
|
||||
use crate::event::{AppEvent, AppEventScheduler};
|
||||
use crate::input::InputState;
|
||||
use crate::persist;
|
||||
use crate::preferences::{self, Acceleration};
|
||||
use crate::preferences;
|
||||
use crate::render::{RenderError, RenderState};
|
||||
use crate::spawner::TokioSpawner;
|
||||
use crate::ui::{InputEvent, Ui, UiBackend, UiCommand};
|
||||
use crate::ui::{Acceleration, InputEvent, UiCommand, UiConfig, UiInstance};
|
||||
use crate::window::Window;
|
||||
use crate::wrapper::messages::{DataTransfer, DesktopFrontendMessage, DesktopWrapperMessage, FrontendMessage, IngestAction};
|
||||
use crate::wrapper::{DesktopWrapper, FolderStore, MmapResourceStorage, WgpuContext, WgpuExecutor};
|
||||
use crate::wrapper::messages::{DataTransfer, DesktopFrontendMessage, DesktopWrapperMessage, IngestAction};
|
||||
use crate::wrapper::{DesktopWrapper, FolderStore, MmapResourceStorage, WgpuContext, WgpuExecutor, serialize_frontend_messages};
|
||||
|
||||
pub(crate) struct App {
|
||||
render_state: Option<RenderState>,
|
||||
@@ -43,10 +43,10 @@ pub(crate) struct App {
|
||||
app_event_scheduler: AppEventScheduler,
|
||||
desktop_wrapper: DesktopWrapper,
|
||||
runtime_command_sender: Sender<RuntimeCommand>,
|
||||
ui: Ui,
|
||||
ui: UiInstance,
|
||||
ui_initialized: Option<Instant>,
|
||||
ui_frame_received: bool,
|
||||
ui_startup_buffer: Vec<Vec<FrontendMessage>>,
|
||||
ui_startup_buffer: Vec<Vec<u8>>,
|
||||
preferences: preferences::DesktopPreferences,
|
||||
launch_documents: Option<Vec<PathBuf>>,
|
||||
exiting: bool,
|
||||
@@ -59,7 +59,7 @@ impl App {
|
||||
}
|
||||
|
||||
pub(crate) fn new(
|
||||
ui: Ui,
|
||||
ui: UiInstance,
|
||||
wgpu_context: WgpuContext,
|
||||
app_event_receiver: Receiver<AppEvent>,
|
||||
app_event_scheduler: AppEventScheduler,
|
||||
@@ -181,7 +181,8 @@ impl App {
|
||||
}
|
||||
|
||||
fn restart_ui(&mut self) {
|
||||
if let Err(error) = self.ui.restart(&self.preferences) {
|
||||
let acceleration = self.preferences.acceleration;
|
||||
if let Err(error) = self.ui.restart(UiConfig { acceleration }) {
|
||||
tracing::error!("Failed to restart the UI: {error}");
|
||||
self.exit(Some(ExitReason::Shutdown));
|
||||
return;
|
||||
@@ -247,7 +248,13 @@ impl App {
|
||||
|
||||
fn handle_desktop_frontend_message(&mut self, message: DesktopFrontendMessage, responses: &mut Vec<DesktopWrapperMessage>) {
|
||||
match message {
|
||||
DesktopFrontendMessage::ToUi(messages) => self.send_or_queue_ui_message(messages),
|
||||
DesktopFrontendMessage::ToWeb(messages) => {
|
||||
let Some(bytes) = serialize_frontend_messages(messages) else {
|
||||
tracing::error!("Failed to serialize frontend messages");
|
||||
return;
|
||||
};
|
||||
self.send_or_queue_web_message(bytes);
|
||||
}
|
||||
DesktopFrontendMessage::OpenFileDialog { title, options, action } => {
|
||||
let app_event_scheduler = self.app_event_scheduler.clone();
|
||||
let _ = thread::spawn(move || {
|
||||
@@ -458,7 +465,7 @@ impl App {
|
||||
self.handle_desktop_frontend_messages(responses);
|
||||
}
|
||||
|
||||
fn send_or_queue_ui_message(&mut self, message: Vec<FrontendMessage>) {
|
||||
fn send_or_queue_web_message(&mut self, message: Vec<u8>) {
|
||||
if self.ui_initialized.is_some() {
|
||||
self.ui.send(UiCommand::Message(message));
|
||||
} else {
|
||||
@@ -468,7 +475,7 @@ impl App {
|
||||
|
||||
fn user_event(&mut self, event_loop: &dyn ActiveEventLoop, event: AppEvent) {
|
||||
match event {
|
||||
AppEvent::UiInitialized => {
|
||||
AppEvent::WebCommunicationInitialized => {
|
||||
self.ui_initialized = Some(Instant::now());
|
||||
self.ui_frame_received = false;
|
||||
for message in self.ui_startup_buffer.drain(..) {
|
||||
|
||||
@@ -9,6 +9,25 @@ pub(crate) fn ensure_dir_exists(path: &PathBuf) {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn clear_dir(path: &PathBuf) {
|
||||
let Ok(entries) = fs::read_dir(path) else {
|
||||
tracing::error!("Failed to read directory at {path:?}");
|
||||
return;
|
||||
};
|
||||
for entry in entries.flatten() {
|
||||
let entry_path = entry.path();
|
||||
if entry_path.is_dir() {
|
||||
if let Err(e) = fs::remove_dir_all(&entry_path) {
|
||||
tracing::error!("Failed to remove directory at {:?}: {}", entry_path, e);
|
||||
}
|
||||
} else if entry_path.is_file()
|
||||
&& let Err(e) = fs::remove_file(&entry_path)
|
||||
{
|
||||
tracing::error!("Failed to remove file at {:?}: {}", entry_path, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn app_data_dir() -> PathBuf {
|
||||
let path = dirs::data_dir().expect("Failed to get data directory").join(APP_DIRECTORY_NAME);
|
||||
ensure_dir_exists(&path);
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::wrapper::messages::{DataTransfer, DesktopWrapperMessage};
|
||||
pub(crate) enum AppEvent {
|
||||
UiUpdate(wgpu::Texture),
|
||||
CursorChange(Cursor),
|
||||
UiInitialized,
|
||||
WebCommunicationInitialized,
|
||||
DesktopWrapperMessage(DesktopWrapperMessage),
|
||||
ViewportTexture(Option<Texture>),
|
||||
ClipboardRead,
|
||||
|
||||
+29
-9
@@ -3,13 +3,13 @@ use crate::cli::Cli;
|
||||
use crate::consts::APP_LOCK_FILE_NAME;
|
||||
use crate::event::{AppEvent, CreateAppEventSchedulerEventLoopExt};
|
||||
use clap::Parser;
|
||||
use preferences::Acceleration;
|
||||
use std::io::Write;
|
||||
use std::process::ExitCode;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use ui::{Ui, UiBackend, UiEvent};
|
||||
use ui::{Acceleration, UiConfig, UiContext, UiEvent, UiSetupResult};
|
||||
use winit::event_loop::EventLoop;
|
||||
|
||||
pub(crate) use graphite_desktop_ui as ui;
|
||||
pub(crate) use graphite_desktop_wrapper as wrapper;
|
||||
|
||||
mod app;
|
||||
@@ -24,7 +24,6 @@ mod preferences;
|
||||
mod render;
|
||||
mod socket;
|
||||
mod spawner;
|
||||
mod ui;
|
||||
mod window;
|
||||
|
||||
pub(crate) mod consts;
|
||||
@@ -32,9 +31,14 @@ pub(crate) mod consts;
|
||||
pub fn start() -> ExitCode {
|
||||
tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init();
|
||||
|
||||
if let Some(code) = ui::setup() {
|
||||
return code;
|
||||
}
|
||||
let ui_context = match UiContext::setup() {
|
||||
UiSetupResult::Ready(context) => context,
|
||||
UiSetupResult::Helper(code) => return code,
|
||||
UiSetupResult::Failed => {
|
||||
tracing::error!("Failed to set up the UI runtime");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
};
|
||||
|
||||
let cli = Cli::parse();
|
||||
|
||||
@@ -69,6 +73,8 @@ pub fn start() -> ExitCode {
|
||||
}
|
||||
};
|
||||
|
||||
dirs::clear_dir(&ui::temp_dir_root());
|
||||
|
||||
// Must be called before event loop initialization or native window integrations will break
|
||||
App::init();
|
||||
|
||||
@@ -92,7 +98,14 @@ pub fn start() -> ExitCode {
|
||||
println!("UI acceleration is disabled");
|
||||
}
|
||||
|
||||
let ui = match Ui::start(&prefs, &wgpu_context) {
|
||||
let ui_context = match ui_context.start(UiConfig { acceleration: prefs.acceleration }) {
|
||||
Ok(context) => context,
|
||||
Err(error) => {
|
||||
tracing::error!("Failed to start the UI runtime: {error}");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
};
|
||||
let ui = match ui_context.instance(&wgpu_context.device, &wgpu_context.queue) {
|
||||
Ok(ui) => ui,
|
||||
Err(error) => {
|
||||
tracing::error!("Failed to start the UI: {error}");
|
||||
@@ -107,10 +120,17 @@ pub fn start() -> ExitCode {
|
||||
let spawned = std::thread::Builder::new().name("ui-events".to_string()).spawn(move || {
|
||||
while let Some(event) = ui.recv() {
|
||||
match event {
|
||||
UiEvent::Ready => scheduler.schedule(AppEvent::UiInitialized),
|
||||
UiEvent::Ready => scheduler.schedule(AppEvent::WebCommunicationInitialized),
|
||||
UiEvent::Frame(texture) => scheduler.schedule(AppEvent::UiUpdate(texture)),
|
||||
UiEvent::Cursor(cursor) => scheduler.schedule(AppEvent::CursorChange(cursor)),
|
||||
UiEvent::Message(message) => scheduler.schedule(AppEvent::DesktopWrapperMessage(message)),
|
||||
UiEvent::Message(message) => match wrapper::deserialize_editor_message(&message) {
|
||||
Some(message) => scheduler.schedule(AppEvent::DesktopWrapperMessage(message)),
|
||||
None => tracing::error!("Failed to deserialize web message"),
|
||||
},
|
||||
UiEvent::Failure(error) => {
|
||||
tracing::error!("UI failure: {error}");
|
||||
scheduler.schedule(AppEvent::UiCrashed);
|
||||
}
|
||||
UiEvent::Crashed => scheduler.schedule(AppEvent::UiCrashed),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
use graphite_desktop_wrapper::messages::Preferences;
|
||||
use wgpu::PresentMode;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum Acceleration {
|
||||
Auto,
|
||||
Disabled,
|
||||
}
|
||||
use crate::ui::Acceleration;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub(crate) struct DesktopPreferences {
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
use crate::preferences::DesktopPreferences;
|
||||
use crate::wrapper::WgpuContext;
|
||||
use crate::wrapper::messages::{DesktopWrapperMessage, FrontendMessage};
|
||||
|
||||
mod cef;
|
||||
pub(crate) use cef::*;
|
||||
|
||||
pub(crate) trait UiBackend: Sized {
|
||||
fn start(preferences: &DesktopPreferences, wgpu_context: &WgpuContext) -> Result<Self, UiError>;
|
||||
fn send(&self, command: UiCommand);
|
||||
fn recv(&self) -> Option<UiEvent>;
|
||||
fn restart(&self, preferences: &DesktopPreferences) -> Result<(), UiError>;
|
||||
fn shutdown(&self);
|
||||
}
|
||||
|
||||
pub(crate) type UiError = Box<dyn std::error::Error + Send + Sync>;
|
||||
|
||||
pub(crate) enum UiCommand {
|
||||
Input(InputEvent),
|
||||
Resized { width: u32, height: u32 },
|
||||
ScaleChanged(f64),
|
||||
Refresh,
|
||||
Message(Vec<FrontendMessage>),
|
||||
}
|
||||
|
||||
pub(crate) enum UiEvent {
|
||||
Ready,
|
||||
Frame(wgpu::Texture),
|
||||
Cursor(Cursor),
|
||||
Message(DesktopWrapperMessage),
|
||||
Crashed,
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
use super::{UiBackend, UiCommand, UiError, UiEvent};
|
||||
use crate::preferences::{Acceleration, DesktopPreferences};
|
||||
use crate::wrapper::WgpuContext;
|
||||
use crate::wrapper::messages::DesktopWrapperMessage;
|
||||
use graphite_desktop_ui_cef as cef;
|
||||
use graphite_wasm_wrapper::native_communication::{decode_editor_command, encode_frontend_messages};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::process::ExitCode;
|
||||
use std::sync::Mutex;
|
||||
|
||||
pub(crate) use cef::{Cursor, InputEvent, InputEventBuilder, MULTICLICK_ALLOWED_TRAVEL, MULTICLICK_TIMEOUT, PINCH_ZOOM_SPEED, SCROLL_LINE_HEIGHT, SCROLL_LINE_WIDTH, SCROLL_SPEED_X, SCROLL_SPEED_Y};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct Ui {
|
||||
instance: cef::UiInstance,
|
||||
}
|
||||
|
||||
static SETUP: Mutex<Option<cef::UiContext<cef::Setup>>> = Mutex::new(None);
|
||||
|
||||
pub(crate) fn setup() -> Option<ExitCode> {
|
||||
match cef::UiContext::setup() {
|
||||
cef::UiSetupResult::Ready(context) => {
|
||||
*SETUP.lock().unwrap() = Some(context);
|
||||
None
|
||||
}
|
||||
cef::UiSetupResult::Failed => {
|
||||
tracing::error!("Failed to set up the UI runtime");
|
||||
Some(ExitCode::FAILURE)
|
||||
}
|
||||
cef::UiSetupResult::Helper(code) => Some(code),
|
||||
}
|
||||
}
|
||||
|
||||
impl UiBackend for Ui {
|
||||
fn start(preferences: &DesktopPreferences, wgpu_context: &WgpuContext) -> Result<Self, UiError> {
|
||||
let setup = SETUP.lock().unwrap().take().ok_or("The UI was started before it was set up")?;
|
||||
|
||||
clear_dir(&cef::temp_dir_root());
|
||||
|
||||
let context = setup.start(config(preferences))?;
|
||||
let instance = context.instance(&wgpu_context.device, &wgpu_context.queue)?;
|
||||
Ok(Self { instance })
|
||||
}
|
||||
|
||||
fn send(&self, command: UiCommand) {
|
||||
let command = match command {
|
||||
UiCommand::Input(event) => cef::UiCommand::Input(event),
|
||||
UiCommand::Resized { width, height } => cef::UiCommand::Resized { width, height },
|
||||
UiCommand::ScaleChanged(scale) => cef::UiCommand::ScaleChanged(scale),
|
||||
UiCommand::Refresh => cef::UiCommand::Refresh,
|
||||
UiCommand::Message(messages) => {
|
||||
let Some(bytes) = encode_frontend_messages(messages) else {
|
||||
tracing::error!("Failed to serialize frontend messages");
|
||||
return;
|
||||
};
|
||||
cef::UiCommand::Message(bytes)
|
||||
}
|
||||
};
|
||||
self.instance.send(command);
|
||||
}
|
||||
|
||||
fn recv(&self) -> Option<UiEvent> {
|
||||
loop {
|
||||
let event = match self.instance.recv()? {
|
||||
cef::UiEvent::Ready => UiEvent::Ready,
|
||||
cef::UiEvent::Frame(texture) => UiEvent::Frame(texture),
|
||||
cef::UiEvent::Cursor(cursor) => UiEvent::Cursor(cursor),
|
||||
cef::UiEvent::Message(bytes) => {
|
||||
let Some(message) = decode_editor_command(&bytes) else {
|
||||
tracing::error!("Failed to deserialize web message");
|
||||
continue;
|
||||
};
|
||||
UiEvent::Message(DesktopWrapperMessage::FromUi(message.into()))
|
||||
}
|
||||
cef::UiEvent::Failure(error) => {
|
||||
tracing::error!("UI failure: {error}");
|
||||
UiEvent::Crashed
|
||||
}
|
||||
cef::UiEvent::Crashed => UiEvent::Crashed,
|
||||
};
|
||||
return Some(event);
|
||||
}
|
||||
}
|
||||
|
||||
fn restart(&self, preferences: &DesktopPreferences) -> Result<(), UiError> {
|
||||
Ok(self.instance.restart(config(preferences))?)
|
||||
}
|
||||
|
||||
fn shutdown(&self) {
|
||||
self.instance.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
fn config(preferences: &DesktopPreferences) -> cef::UiConfig {
|
||||
let acceleration = match preferences.acceleration {
|
||||
Acceleration::Auto => cef::Acceleration::Auto,
|
||||
Acceleration::Disabled => cef::Acceleration::Disabled,
|
||||
};
|
||||
cef::UiConfig { acceleration }
|
||||
}
|
||||
|
||||
fn clear_dir(path: &PathBuf) {
|
||||
let Ok(entries) = fs::read_dir(path) else {
|
||||
tracing::error!("Failed to read directory at {path:?}");
|
||||
return;
|
||||
};
|
||||
for entry in entries.flatten() {
|
||||
let entry_path = entry.path();
|
||||
if entry_path.is_dir() {
|
||||
if let Err(e) = fs::remove_dir_all(&entry_path) {
|
||||
tracing::error!("Failed to remove directory at {:?}: {}", entry_path, e);
|
||||
}
|
||||
} else if entry_path.is_file()
|
||||
&& let Err(e) = fs::remove_file(&entry_path)
|
||||
{
|
||||
tracing::error!("Failed to remove file at {:?}: {}", entry_path, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "graphite-desktop-ui-cef"
|
||||
name = "graphite-desktop-ui"
|
||||
description = "Renders the Graphite editor frontend UI into wgpu textures"
|
||||
version.workspace = true
|
||||
license.workspace = true
|
||||
@@ -16,12 +16,12 @@ workspace = true
|
||||
|
||||
[features]
|
||||
default = []
|
||||
embedded_resources = ["dep:graphite-desktop-ui-cef-embedded-resources"]
|
||||
embedded_resources = ["dep:graphite-desktop-embedded-resources"]
|
||||
accelerated_paint = ["dep:ash", "dep:bytemuck", "dep:objc2-io-surface", "dep:objc2-metal", "dep:mach2"]
|
||||
|
||||
[dependencies]
|
||||
# Local dependencies
|
||||
graphite-desktop-ui-cef-embedded-resources = { path = "embedded-resources", optional = true }
|
||||
graphite-desktop-embedded-resources = { path = "../embedded-resources", optional = true }
|
||||
|
||||
wgpu = { workspace = true }
|
||||
wgpu-sync = { workspace = true }
|
||||
|
||||
@@ -78,7 +78,7 @@ pub(crate) fn load(path: PathBuf) -> Option<Resource> {
|
||||
WebResources::Embedded => {
|
||||
#[cfg(feature = "embedded_resources")]
|
||||
{
|
||||
if let Some(resources) = &graphite_desktop_ui_cef_embedded_resources::EMBEDDED_RESOURCES
|
||||
if let Some(resources) = &graphite_desktop_embedded_resources::EMBEDDED_RESOURCES
|
||||
&& let Some(file) = resources.get_file(&path)
|
||||
{
|
||||
return Some(Resource {
|
||||
|
||||
@@ -17,6 +17,7 @@ workspace = true
|
||||
[dependencies]
|
||||
# Local dependencies
|
||||
graphite-editor = { workspace = true }
|
||||
graphite-wasm-wrapper = { path = "../../frontend/wrapper", default-features = false, features = ["editor"] }
|
||||
graph-craft = { workspace = true }
|
||||
wgpu-executor = { workspace = true }
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::messages::{DesktopFrontendMessage, DesktopWrapperMessage, EditorMessa
|
||||
|
||||
pub(super) fn handle_desktop_wrapper_message(dispatcher: &mut DesktopWrapperMessageDispatcher, message: DesktopWrapperMessage) {
|
||||
match message {
|
||||
DesktopWrapperMessage::FromUi(message) => {
|
||||
DesktopWrapperMessage::FromWeb(message) => {
|
||||
dispatcher.queue_editor_message(*message);
|
||||
}
|
||||
DesktopWrapperMessage::Wake => {
|
||||
|
||||
@@ -2,6 +2,7 @@ use graph_craft::application_io::PlatformApplicationIo;
|
||||
use graph_craft::application_io::resource::ResourceStorage;
|
||||
use graphite_editor::application::{Editor, Environment, Host, Platform};
|
||||
use graphite_editor::builder::{Builder, EditorBuilder, RuntimeBuilder};
|
||||
use graphite_editor::messages::frontend::FrontendMessage;
|
||||
use graphite_editor::node_graph_executor::NodeRuntime;
|
||||
|
||||
use message_dispatcher::DesktopWrapperMessageDispatcher;
|
||||
@@ -79,3 +80,12 @@ impl DesktopWrapper {
|
||||
executor.execute()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deserialize_editor_message(data: &[u8]) -> Option<DesktopWrapperMessage> {
|
||||
let message = graphite_wasm_wrapper::native_communication::decode_editor_command(data)?;
|
||||
Some(DesktopWrapperMessage::FromWeb(message.into()))
|
||||
}
|
||||
|
||||
pub fn serialize_frontend_messages(messages: Vec<FrontendMessage>) -> Option<Vec<u8>> {
|
||||
graphite_wasm_wrapper::native_communication::encode_frontend_messages(messages)
|
||||
}
|
||||
@@ -60,7 +60,7 @@ impl<'a> DesktopWrapperMessageDispatcher<'a> {
|
||||
}
|
||||
|
||||
if !frontend_messages.is_empty() {
|
||||
self.respond(DesktopFrontendMessage::ToUi(frontend_messages));
|
||||
self.respond(DesktopFrontendMessage::ToWeb(frontend_messages));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
pub use graphite_editor::messages::prelude::FrontendMessage;
|
||||
use graphite_editor::messages::prelude::FrontendMessage;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub(crate) use graphite_editor::messages::prelude::Message as EditorMessage;
|
||||
@@ -12,7 +12,7 @@ pub use graphite_editor::messages::prelude::InputPreprocessorMessage as InputMes
|
||||
pub use graphite_editor::messages::prelude::PreferencesMessageHandler as Preferences;
|
||||
|
||||
pub enum DesktopFrontendMessage {
|
||||
ToUi(Vec<FrontendMessage>),
|
||||
ToWeb(Vec<FrontendMessage>),
|
||||
OpenLaunchDocuments,
|
||||
OpenFileDialog {
|
||||
title: String,
|
||||
@@ -69,7 +69,7 @@ pub enum DesktopFrontendMessage {
|
||||
}
|
||||
|
||||
pub enum DesktopWrapperMessage {
|
||||
FromUi(Box<EditorMessage>),
|
||||
FromWeb(Box<EditorMessage>),
|
||||
Wake,
|
||||
Input(InputMessage),
|
||||
Ingest { content: DataTransfer, action: IngestAction },
|
||||
|
||||
@@ -57,6 +57,10 @@ pub mod network {
|
||||
pub const IMPORT_METADATA: &str = "ui::import_metadata";
|
||||
pub const EXPORT_NAMES: &str = "ui::export_names";
|
||||
pub const EXPORT_DESCRIPTIONS: &str = "ui::export_descriptions";
|
||||
|
||||
/// How many pixels make an inch in the network's document, which sizes lengths typed in a physical unit. Absent where it
|
||||
/// is the default, CSS's 96. Only the root network's applies.
|
||||
pub const PIXELS_PER_INCH: &str = "pixels_per_inch";
|
||||
}
|
||||
|
||||
pub mod delta {
|
||||
|
||||
@@ -473,6 +473,12 @@ fn write_ui_network_attributes<M: NodeMetadataSource + ?Sized>(
|
||||
.map_err(map_serialization_error(network::PINNED_ORDER))?;
|
||||
}
|
||||
|
||||
if let Some(pixels_per_inch) = metadata.pixels_per_inch(location) {
|
||||
attributes
|
||||
.set_serialized(network::PIXELS_PER_INCH, &pixels_per_inch, timestamp)
|
||||
.map_err(map_serialization_error(network::PIXELS_PER_INCH))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ pub struct NetworkMetadataEntry {
|
||||
pub import_metadata: Vec<InputMetadataEntry>,
|
||||
pub export_names: Vec<String>,
|
||||
pub export_descriptions: Vec<String>,
|
||||
/// The document's pixels per inch, where it differs from the default.
|
||||
pub pixels_per_inch: Option<f64>,
|
||||
}
|
||||
|
||||
/// Editor metadata for one import of a subgraph. Mirrors `InputPersistentMetadata` but wraps strings in `Option` so
|
||||
@@ -78,6 +80,11 @@ pub trait NodeMetadataSource {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// The network's pixels per inch, where it differs from the default.
|
||||
fn pixels_per_inch(&self, _network: NetworkLocation) -> Option<f64> {
|
||||
None
|
||||
}
|
||||
|
||||
fn import_metadata(&self, _network: NetworkLocation) -> Vec<InputMetadataEntry> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
@@ -406,11 +406,9 @@ fn set(registry: &mut Registry, ops: &mut Vec<RegistryDelta>, slot: Slot, input:
|
||||
match slot {
|
||||
Slot::Input(id, index) => {
|
||||
let Some(input) = input else { return };
|
||||
// A chain the line no longer holds the slot for, as shrinking a node's inputs leaves, is not written back
|
||||
let Some(slot) = registry.node_instances.get_mut(&id).and_then(|node| node.inputs.get_mut(index as usize)) else {
|
||||
return;
|
||||
};
|
||||
slot.input = input.clone();
|
||||
if let Some(slot) = registry.node_instances.get_mut(&id).and_then(|node| node.inputs.get_mut(index as usize)) {
|
||||
slot.input = input.clone();
|
||||
}
|
||||
ops.push(RegistryDelta::ChangeNodeInput { id, index, new_input: input });
|
||||
}
|
||||
Slot::Export(id, index) => {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! operation mixed in. After every operation nothing may name a node the document no longer has.
|
||||
|
||||
use super::simulation::{LEAF, Random, Scenario, below, empty_export, from_env, on, simulate, stack, value};
|
||||
use crate::{Implementation, InputSlot, Network, Node, NodeId, NodeInput, ROOT_NETWORK, Registry, RegistryDelta, Session, TimeStamp};
|
||||
use crate::{Implementation, Network, Node, NodeId, NodeInput, ROOT_NETWORK, Registry, RegistryDelta, Session};
|
||||
|
||||
/// A slot that can name a node.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
@@ -94,16 +94,14 @@ impl Scenario for Branching {
|
||||
node.inputs[1].input = second;
|
||||
node
|
||||
};
|
||||
// Nodes that still have an input past the primary one, the only ones an edit may write there
|
||||
let wide: Vec<NodeId> = nodes.iter().copied().filter(|id| registry.node_instances[id].inputs.len() > 1).collect();
|
||||
// Nodes with nothing hanging off their second input, so taking one does not leave a chain behind
|
||||
let plain: Vec<NodeId> = wide
|
||||
let plain: Vec<NodeId> = nodes
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|id| !matches!(place_value(®istry, Place::Input(*id, 1)), Some(NodeInput::Node { .. })))
|
||||
.collect();
|
||||
|
||||
match random.below(14) {
|
||||
match random.below(12) {
|
||||
// Draw a node on top of the chain off the export
|
||||
0..=2 => {
|
||||
let id = session.next_node_id();
|
||||
@@ -124,7 +122,7 @@ impl Scenario for Branching {
|
||||
}
|
||||
// Hang a node on an input past the primary one, over whatever is there already
|
||||
3..=5 => {
|
||||
let Some(host) = random.pick(&wide) else { return Vec::new() };
|
||||
let Some(host) = random.pick(&nodes) else { return Vec::new() };
|
||||
let id = session.next_node_id();
|
||||
let first = match place_value(®istry, Place::Input(host, 1)) {
|
||||
Some(NodeInput::Node { id: under, index }) => NodeInput::Node { id: under, index },
|
||||
@@ -181,25 +179,6 @@ impl Scenario for Branching {
|
||||
new_input: value(random.below(100)),
|
||||
}]
|
||||
}
|
||||
// Rewrite a node's whole input list, which an index-addressed write cannot express
|
||||
11..=12 => {
|
||||
let Some(node) = random.pick(&nodes) else { return Vec::new() };
|
||||
let mut inputs = registry.node_instances[&node].inputs.clone();
|
||||
match random.below(3) {
|
||||
// Swap the first two, so what the node rested on moves past its primary input
|
||||
0 if inputs.len() > 1 => inputs.swap(0, 1),
|
||||
// One input more, holding a value
|
||||
1 if inputs.len() < 4 => inputs.push(InputSlot {
|
||||
input: value(random.below(100)),
|
||||
timestamp: TimeStamp::ORIGIN,
|
||||
attributes: Default::default(),
|
||||
}),
|
||||
// One input fewer, as removing a subgraph's import slot leaves the nodes wrapping it
|
||||
_ if inputs.len() > 1 => _ = inputs.pop(),
|
||||
_ => return Vec::new(),
|
||||
}
|
||||
vec![RegistryDelta::SetNodeInputs { id: node, inputs }]
|
||||
}
|
||||
// Cut the chain off an input past the primary one, taking its nodes with it
|
||||
_ => {
|
||||
let hosts: Vec<NodeId> = nodes
|
||||
|
||||
@@ -12,9 +12,25 @@ use crate::{NetworkId, NodeMetadataSource, PeerId, Position, Registry, from_valu
|
||||
/// Note: This only works for complete networks with all inputs resolved.
|
||||
/// Test networks with Import inputs will fail compilation (which is expected).
|
||||
fn verify_network_compiles(network: &NodeNetwork) -> Result<(), String> {
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
|
||||
let mut network = network.clone();
|
||||
network.inline_definitions().map_err(|e| format!("Inlining failed: {e}"))?;
|
||||
|
||||
// Nodes measuring in physical units read the document's resolution from the scope the runtime wraps every document in
|
||||
let resolution_node = NodeId(u64::MAX);
|
||||
network.nodes.insert(
|
||||
resolution_node,
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::value(TaggedValue::Number(core_types::units::DEFAULT_PIXELS_PER_INCH), false)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::PassthroughNode")),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
network
|
||||
.scope_injections
|
||||
.insert(core_types::units::PIXELS_PER_INCH_SCOPE.to_string(), (resolution_node, core_types::item!(f64)));
|
||||
|
||||
let compiler = Compiler {};
|
||||
compiler.compile_single(network).map_err(|e| format!("Compilation failed: {:?}", e))?;
|
||||
Ok(())
|
||||
|
||||
@@ -417,6 +417,7 @@ fn extract_network_metadata(registry: &Registry, attributes: &crate::Attributes,
|
||||
import_metadata: attributes.get_or_default(network::IMPORT_METADATA),
|
||||
export_names: attributes.get_or_default(network::EXPORT_NAMES),
|
||||
export_descriptions: attributes.get_or_default(network::EXPORT_DESCRIPTIONS),
|
||||
pixels_per_inch: attributes.get_typed(network::PIXELS_PER_INCH),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
use migration_core::{Inputs, NodeInput, literal, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
Bool(bool),
|
||||
DAffine2([f64; 6]),
|
||||
}
|
||||
|
||||
/// 'Bevel & Emboss' defaults to fitting gradient textures without a transform across the content.
|
||||
#[migration("blending_nodes::effects::BevelAndEmbossNode"@2 => @3)]
|
||||
pub fn bevel_and_emboss_v2(inputs: &mut Inputs) {
|
||||
for input in added_inputs() {
|
||||
inputs.push(input);
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether an unplaced gradient uses an explicit transform, and the transform itself.
|
||||
fn added_inputs() -> [NodeInput; 2] {
|
||||
[literal(Tagged::Bool(false)), literal(Tagged::DAffine2([1., 0., 0., 1., 0., 0.]))]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(20, |random, _slot| literal(random.below(10) as f64))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&BevelAndEmbossV2, &contract());
|
||||
check_undo(&BevelAndEmbossV2, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_the_inputs_and_adds_an_unset_texture_placement() {
|
||||
let inputs: Vec<_> = (0..20).map(|index| literal(index as f64)).collect();
|
||||
|
||||
let mut fixture = Fixture::new(&BevelAndEmbossV2);
|
||||
let bevel = fixture.add(decl!("blending_nodes::effects::BevelAndEmbossNode"@2), inputs.clone());
|
||||
let migrated = fixture.migrate(&BevelAndEmbossV2).unwrap();
|
||||
|
||||
let mut expected = inputs;
|
||||
expected.extend(added_inputs());
|
||||
assert_eq!(fixture.declaration_of(&migrated, bevel), Some(decl!("blending_nodes::effects::BevelAndEmbossNode"@3)));
|
||||
assert_eq!(fixture.inputs(&migrated, bevel), expected);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,50 @@
|
||||
use migration_core::{Inputs, NodeInput, encode, migration};
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variant this migration writes.
|
||||
const RADIUS: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
TypeDefault(Type),
|
||||
}
|
||||
|
||||
/// Frozen mirror of the `Type` an empty list of graphics stores.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Type {
|
||||
Concrete(TypeDescriptor),
|
||||
List(Box<Type>),
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypeDescriptor {
|
||||
name: String,
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
/// 'Blur' gained a radius mask after its radius, left empty to keep blurring the whole content by the radius.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The radius is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("blending_nodes::effects::BlurNode"@2 => @3)]
|
||||
pub fn blur_v2(inputs: &mut Inputs) {
|
||||
inputs.insert(2, empty_radius_mask());
|
||||
}
|
||||
pub fn blur_v2(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(RADIUS) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
/// The radius mask input with nothing connected and not exposed, as the node's definition gives it.
|
||||
fn empty_radius_mask() -> NodeInput {
|
||||
let no_graphics = Tagged::TypeDefault(Type::List(Box::new(Type::Concrete(TypeDescriptor {
|
||||
name: "graphic_types::graphic::Graphic".to_string(),
|
||||
}))));
|
||||
NodeInput::Value {
|
||||
value: encode(&no_graphics),
|
||||
exposed: false,
|
||||
}
|
||||
inputs.set(
|
||||
RADIUS as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::{decl, literal};
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(4, |random, _slot| literal(random.below(10) as f64))
|
||||
SourceContract::new(4, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -53,17 +54,13 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_the_inputs_and_inserts_an_empty_radius_mask_after_the_radius() {
|
||||
let inputs: Vec<_> = (0..4).map(|index| literal(index as f64)).collect();
|
||||
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&BlurV2);
|
||||
let blur = fixture.add(decl!("blending_nodes::effects::BlurNode"@2), inputs.clone());
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let blur = fixture.add(decl!("blending_nodes::effects::BlurNode"@2), vec![literal(Tagged::None), number(10.), number(0.), number(0.)]);
|
||||
let migrated = fixture.migrate(&BlurV2).unwrap();
|
||||
|
||||
let mut expected = inputs;
|
||||
expected.insert(2, empty_radius_mask());
|
||||
assert_eq!(fixture.declaration_of(&migrated, blur), Some(decl!("blending_nodes::effects::BlurNode"@3)));
|
||||
assert_eq!(fixture.inputs(&migrated, blur), expected);
|
||||
assert!(matches!(expected[2], NodeInput::Value { exposed: false, .. }), "the radius mask is not exposed");
|
||||
let radius = literal(Tagged::Length(TypedLength { value: 10., unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, blur), [literal(Tagged::None), radius, number(0.), number(0.)]);
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
use migration_core::{Inputs, literal, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variant this migration writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
Bool(bool),
|
||||
}
|
||||
|
||||
/// 'Convolution Kernel' gained Apply to Alpha after its offset, left off to keep the content's coverage as it is.
|
||||
#[migration("blending_nodes::filters::ConvolutionKernelNode"@1 => @2)]
|
||||
pub fn convolution_kernel_v1(inputs: &mut Inputs) {
|
||||
inputs.push(literal(Tagged::Bool(false)));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(5, |random, _slot| literal(random.below(10) as f64))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&ConvolutionKernelV1, &contract());
|
||||
check_undo(&ConvolutionKernelV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_the_inputs_and_appends_apply_to_alpha_turned_off() {
|
||||
let inputs: Vec<_> = (0..5).map(|index| literal(index as f64)).collect();
|
||||
|
||||
let mut fixture = Fixture::new(&ConvolutionKernelV1);
|
||||
let kernel = fixture.add(decl!("blending_nodes::filters::ConvolutionKernelNode"@1), inputs.clone());
|
||||
let migrated = fixture.migrate(&ConvolutionKernelV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.declaration_of(&migrated, kernel), Some(decl!("blending_nodes::filters::ConvolutionKernelNode"@2)));
|
||||
assert_eq!(fixture.inputs(&migrated, kernel), [inputs, vec![literal(Tagged::Bool(false))]].concat());
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
use migration_core::{Inputs, literal, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
Number(f64),
|
||||
Integer(i64),
|
||||
}
|
||||
|
||||
/// 'Inner Glow' gained Jitter, Noise, and a seed before its contour, set to none to keep the glow smooth.
|
||||
#[migration("blending_nodes::effects::InnerGlowNode"@2 => @3)]
|
||||
pub fn inner_glow_v2(inputs: &mut Inputs) {
|
||||
inputs.insert(8, literal(Tagged::Number(0.)));
|
||||
inputs.insert(9, literal(Tagged::Number(0.)));
|
||||
inputs.insert(10, literal(Tagged::Integer(0)));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(9, |random, _slot| literal(random.below(10) as f64))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&InnerGlowV2, &contract());
|
||||
check_undo(&InnerGlowV2, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_the_inputs_and_adds_no_noise_or_jitter() {
|
||||
let inputs: Vec<_> = (0..9).map(|index| literal(index as f64)).collect();
|
||||
|
||||
let mut fixture = Fixture::new(&InnerGlowV2);
|
||||
let inner_glow = fixture.add(decl!("blending_nodes::effects::InnerGlowNode"@2), inputs.clone());
|
||||
let migrated = fixture.migrate(&InnerGlowV2).unwrap();
|
||||
|
||||
let mut expected = inputs;
|
||||
expected.splice(8..8, [literal(Tagged::Number(0.)), literal(Tagged::Number(0.)), literal(Tagged::Integer(0))]);
|
||||
assert_eq!(fixture.declaration_of(&migrated, inner_glow), Some(decl!("blending_nodes::effects::InnerGlowNode"@3)));
|
||||
assert_eq!(fixture.inputs(&migrated, inner_glow), expected);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,14 @@
|
||||
//! Migrations of the nodes in `blending_nodes`.
|
||||
|
||||
mod bevel_and_emboss_v1;
|
||||
mod bevel_and_emboss_v2;
|
||||
mod blur_v2;
|
||||
mod convolution_kernel_v1;
|
||||
mod drop_shadow_v1;
|
||||
mod inner_glow_v1;
|
||||
mod inner_glow_v2;
|
||||
mod inner_shadow_v1;
|
||||
mod mask_by_any_graphic;
|
||||
mod outer_glow_v1;
|
||||
mod outer_glow_v2;
|
||||
mod outline_v1;
|
||||
mod outline_v2;
|
||||
mod outline_v3;
|
||||
mod paint_overlay_from_color_overlay;
|
||||
mod paint_overlay_v2;
|
||||
mod radial_blur_v1;
|
||||
mod renames;
|
||||
mod satin_v1;
|
||||
@@ -1,48 +0,0 @@
|
||||
use migration_core::{Inputs, literal, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
Number(f64),
|
||||
Integer(i64),
|
||||
}
|
||||
|
||||
/// 'Outer Glow' gained Jitter, Noise, and a seed before its contour, set to none to keep the glow smooth.
|
||||
#[migration("blending_nodes::effects::OuterGlowNode"@2 => @3)]
|
||||
pub fn outer_glow_v2(inputs: &mut Inputs) {
|
||||
inputs.insert(7, literal(Tagged::Number(0.)));
|
||||
inputs.insert(8, literal(Tagged::Number(0.)));
|
||||
inputs.insert(9, literal(Tagged::Integer(0)));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(8, |random, _slot| literal(random.below(10) as f64))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&OuterGlowV2, &contract());
|
||||
check_undo(&OuterGlowV2, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_the_inputs_and_adds_no_noise_or_jitter() {
|
||||
let inputs: Vec<_> = (0..8).map(|index| literal(index as f64)).collect();
|
||||
|
||||
let mut fixture = Fixture::new(&OuterGlowV2);
|
||||
let outer_glow = fixture.add(decl!("blending_nodes::effects::OuterGlowNode"@2), inputs.clone());
|
||||
let migrated = fixture.migrate(&OuterGlowV2).unwrap();
|
||||
|
||||
let mut expected = inputs;
|
||||
expected.splice(7..7, [literal(Tagged::Number(0.)), literal(Tagged::Number(0.)), literal(Tagged::Integer(0))]);
|
||||
assert_eq!(fixture.declaration_of(&migrated, outer_glow), Some(decl!("blending_nodes::effects::OuterGlowNode"@3)));
|
||||
assert_eq!(fixture.inputs(&migrated, outer_glow), expected);
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
use migration_core::{Inputs, NodeInput, literal, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
Bool(bool),
|
||||
DAffine2([f64; 6]),
|
||||
}
|
||||
|
||||
/// 'Outline' defaults to fitting gradients without a transform across the content.
|
||||
#[migration("blending_nodes::effects::OutlineNode"@3 => @4)]
|
||||
pub fn outline_v3(inputs: &mut Inputs) {
|
||||
for input in added_inputs() {
|
||||
inputs.push(input);
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether an unplaced gradient uses an explicit transform, and the transform itself.
|
||||
fn added_inputs() -> [NodeInput; 2] {
|
||||
[literal(Tagged::Bool(false)), literal(Tagged::DAffine2([1., 0., 0., 1., 0., 0.]))]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(6, |random, _slot| literal(random.below(10) as f64))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&OutlineV3, &contract());
|
||||
check_undo(&OutlineV3, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_the_inputs_and_adds_an_unset_placement() {
|
||||
let inputs: Vec<_> = (0..6).map(|index| literal(index as f64)).collect();
|
||||
|
||||
let mut fixture = Fixture::new(&OutlineV3);
|
||||
let outline = fixture.add(decl!("blending_nodes::effects::OutlineNode"@3), inputs.clone());
|
||||
let migrated = fixture.migrate(&OutlineV3).unwrap();
|
||||
|
||||
let mut expected = inputs;
|
||||
expected.extend(added_inputs());
|
||||
assert_eq!(fixture.declaration_of(&migrated, outline), Some(decl!("blending_nodes::effects::OutlineNode"@4)));
|
||||
assert_eq!(fixture.inputs(&migrated, outline), expected);
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
use migration_core::{Inputs, NodeInput, literal, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
Bool(bool),
|
||||
DAffine2([f64; 6]),
|
||||
}
|
||||
|
||||
/// 'Paint Overlay' defaults to fitting gradients without a transform across the content.
|
||||
#[migration("blending_nodes::effects::PaintOverlayNode"@2 => @3)]
|
||||
pub fn paint_overlay_v2(inputs: &mut Inputs) {
|
||||
for input in added_inputs() {
|
||||
inputs.push(input);
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether an unplaced gradient uses an explicit transform, and the transform itself.
|
||||
fn added_inputs() -> [NodeInput; 2] {
|
||||
[literal(Tagged::Bool(false)), literal(Tagged::DAffine2([1., 0., 0., 1., 0., 0.]))]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(4, |random, _slot| literal(random.below(10) as f64))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&PaintOverlayV2, &contract());
|
||||
check_undo(&PaintOverlayV2, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_the_inputs_and_adds_an_unset_placement() {
|
||||
let inputs: Vec<_> = (0..4).map(|index| literal(index as f64)).collect();
|
||||
|
||||
let mut fixture = Fixture::new(&PaintOverlayV2);
|
||||
let overlay = fixture.add(decl!("blending_nodes::effects::PaintOverlayNode"@2), inputs.clone());
|
||||
let migrated = fixture.migrate(&PaintOverlayV2).unwrap();
|
||||
|
||||
let mut expected = inputs;
|
||||
expected.extend(added_inputs());
|
||||
assert_eq!(fixture.declaration_of(&migrated, overlay), Some(decl!("blending_nodes::effects::PaintOverlayNode"@3)));
|
||||
assert_eq!(fixture.inputs(&migrated, overlay), expected);
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
use migration_core::{Inputs, MigrationError, Node, NodeInput, encode, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const CENTER: u32 = 3;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
DVec2([f64; 2]),
|
||||
DAffine2([f64; 6]),
|
||||
}
|
||||
|
||||
/// 'Radial Blur' takes a transform placing a circle in place of its center, which the transform's translation keeps.
|
||||
/// A wired center can't be read before it runs, so it becomes the identity, the circle at the content's origin.
|
||||
#[migration("blending_nodes::distortions::RadialBlurNode"@1 => @2)]
|
||||
pub fn radial_blur_v1(node: &Node, inputs: &mut Inputs) -> Result<(), MigrationError> {
|
||||
let Some(center) = node.inputs().get(CENTER as usize) else {
|
||||
return Err(MigrationError::invariant("Radial Blur has a Center input"));
|
||||
};
|
||||
|
||||
inputs.set(CENTER, transform_input(¢er.input));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The transform input placing the circle at the old `center`, shown in the graph if it was exposed or wired.
|
||||
fn transform_input(center: &NodeInput) -> NodeInput {
|
||||
let ([x, y], exposed) = match center {
|
||||
NodeInput::Value { exposed, .. } => match literal_of::<Tagged>(center) {
|
||||
Some(Tagged::DVec2(center)) => (center, *exposed),
|
||||
_ => ([0., 0.], *exposed),
|
||||
},
|
||||
_ => ([0., 0.], true),
|
||||
};
|
||||
|
||||
NodeInput::Value {
|
||||
value: encode(&Tagged::DAffine2([1., 0., 0., 1., x, y])),
|
||||
exposed,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::{decl, literal};
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
const CENTER_SLOT: usize = CENTER as usize;
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(5, |random, slot| match slot {
|
||||
CENTER_SLOT => literal(Tagged::DVec2([random.below(10) as f64, random.below(10) as f64])),
|
||||
_ => literal(random.below(10) as f64),
|
||||
})
|
||||
}
|
||||
|
||||
fn radial_blur_inputs(center: NodeInput) -> Vec<NodeInput> {
|
||||
let mut inputs: Vec<_> = (0..5).map(|index| literal(index as f64)).collect();
|
||||
inputs[CENTER_SLOT] = center;
|
||||
inputs
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&RadialBlurV1, &contract());
|
||||
check_undo(&RadialBlurV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_center_becomes_the_translation_of_the_transform_in_its_place() {
|
||||
let mut fixture = Fixture::new(&RadialBlurV1);
|
||||
let radial_blur = fixture.add(decl!("blending_nodes::distortions::RadialBlurNode"@1), radial_blur_inputs(literal(Tagged::DVec2([12.5, -4.]))));
|
||||
let migrated = fixture.migrate(&RadialBlurV1).unwrap();
|
||||
|
||||
let expected = radial_blur_inputs(literal(Tagged::DAffine2([1., 0., 0., 1., 12.5, -4.])));
|
||||
assert_eq!(fixture.declaration_of(&migrated, radial_blur), Some(decl!("blending_nodes::distortions::RadialBlurNode"@2)));
|
||||
assert_eq!(fixture.inputs(&migrated, radial_blur), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wired_center_becomes_the_identity_shown_in_the_graph() {
|
||||
let mut fixture = Fixture::new(&RadialBlurV1);
|
||||
let source = fixture.add(decl!("migration_testing::consumer"@1), Vec::new());
|
||||
let radial_blur = fixture.add(decl!("blending_nodes::distortions::RadialBlurNode"@1), radial_blur_inputs(NodeInput::Node { id: source, index: 0 }));
|
||||
let migrated = fixture.migrate(&RadialBlurV1).unwrap();
|
||||
|
||||
let identity = NodeInput::Value {
|
||||
value: encode(&Tagged::DAffine2([1., 0., 0., 1., 0., 0.])),
|
||||
exposed: true,
|
||||
};
|
||||
assert_eq!(fixture.inputs(&migrated, radial_blur), radial_blur_inputs(identity));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const DIAMETER: usize = 2;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The diameter is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("brush_nodes::BrushStrokesNode"@1 => @2)]
|
||||
pub fn brush_strokes_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(DIAMETER) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
DIAMETER as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(5, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&BrushStrokesV1, &contract());
|
||||
check_undo(&BrushStrokesV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&BrushStrokesV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let brush_strokes = fixture.add(decl!("brush_nodes::BrushStrokesNode"@1), vec![literal(Tagged::None), number(0.), number(40.), number(0.), number(100.)]);
|
||||
let migrated = fixture.migrate(&BrushStrokesV1).unwrap();
|
||||
|
||||
let diameter = literal(Tagged::Length(TypedLength { value: 40., unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, brush_strokes), [literal(Tagged::None), number(0.), diameter, number(0.), number(100.)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
//! Migrations of the nodes in `brush_nodes`.
|
||||
|
||||
mod brush_strokes_v1;
|
||||
@@ -0,0 +1,66 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const DISTANCE: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The distance is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("core_types::vector::BevelNode"@1 => @2)]
|
||||
pub fn bevel_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(DISTANCE) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
DISTANCE as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(2, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&BevelV1, &contract());
|
||||
check_undo(&BevelV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&BevelV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let bevel = fixture.add(decl!("core_types::vector::BevelNode"@1), vec![literal(Tagged::None), number(10.)]);
|
||||
let migrated = fixture.migrate(&BevelV1).unwrap();
|
||||
|
||||
let distance = literal(Tagged::Length(TypedLength { value: 10., unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, bevel), [literal(Tagged::None), distance]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const TOLERANCE: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The tolerance is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("core_types::vector::DecimateNode"@1 => @2)]
|
||||
pub fn decimate_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(TOLERANCE) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
TOLERANCE as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(2, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&DecimateV1, &contract());
|
||||
check_undo(&DecimateV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&DecimateV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let decimate = fixture.add(decl!("core_types::vector::DecimateNode"@1), vec![literal(Tagged::None), number(5.)]);
|
||||
let migrated = fixture.migrate(&DecimateV1).unwrap();
|
||||
|
||||
let tolerance = literal(Tagged::Length(TypedLength { value: 5., unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, decimate), [literal(Tagged::None), tolerance]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const DIRECTION: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
DVec2([f64; 2]),
|
||||
LengthVec2(TypedLengthVec2),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLengthVec2 {
|
||||
value: [f64; 2],
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The direction is a pair of lengths, which keeps the pixels it held. A wired Vec2 still feeds it, read as pixels.
|
||||
#[migration("core_types::vector::ExtrudeNode"@1 => @2)]
|
||||
pub fn extrude_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(DIRECTION) else { return };
|
||||
let Some(Tagged::DVec2(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(DIRECTION as u32, lengths(pixels));
|
||||
}
|
||||
|
||||
fn lengths(pixels: [f64; 2]) -> NodeInput {
|
||||
literal(Tagged::LengthVec2(TypedLengthVec2 {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(3, |random, slot| match slot {
|
||||
DIRECTION => literal(Tagged::DVec2([random.below(100) as f64, random.below(100) as f64])),
|
||||
_ => literal(Tagged::None),
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&ExtrudeV1, &contract());
|
||||
check_undo(&ExtrudeV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_vec2_of_pixels_becomes_lengths_in_pixels() {
|
||||
let mut fixture = Fixture::new(&ExtrudeV1);
|
||||
let node = fixture.add(
|
||||
decl!("core_types::vector::ExtrudeNode"@1),
|
||||
vec![literal(Tagged::None), literal(Tagged::DVec2([30., 40.])), literal(Tagged::None)],
|
||||
);
|
||||
let migrated = fixture.migrate(&ExtrudeV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, node), [literal(Tagged::None), lengths([30., 40.]), literal(Tagged::None)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const MAX_DISTANCE: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The max distance is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("core_types::vector::JitterPointsNode"@1 => @2)]
|
||||
pub fn jitter_points_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(MAX_DISTANCE) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
MAX_DISTANCE as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(4, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&JitterPointsV1, &contract());
|
||||
check_undo(&JitterPointsV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&JitterPointsV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let jitter_points = fixture.add(decl!("core_types::vector::JitterPointsNode"@1), vec![literal(Tagged::None), number(5.), number(0.), number(1.)]);
|
||||
let migrated = fixture.migrate(&JitterPointsV1).unwrap();
|
||||
|
||||
let max_distance = literal(Tagged::Length(TypedLength { value: 5., unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, jitter_points), [literal(Tagged::None), max_distance, number(0.), number(1.)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
//! Migrations of the nodes in `core_types`.
|
||||
|
||||
mod bevel_v1;
|
||||
mod decimate_v1;
|
||||
mod extrude_v1;
|
||||
mod jitter_points_v1;
|
||||
mod offset_path_v1;
|
||||
mod offset_points_v1;
|
||||
mod point_inside_v1;
|
||||
mod round_corners_v1;
|
||||
mod sample_polyline_v1;
|
||||
mod scatter_points_v2;
|
||||
mod simplify_v1;
|
||||
mod weld_v1;
|
||||
@@ -0,0 +1,66 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const DISTANCE: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The distance is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("core_types::vector::OffsetPathNode"@1 => @2)]
|
||||
pub fn offset_path_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(DISTANCE) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
DISTANCE as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(4, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&OffsetPathV1, &contract());
|
||||
check_undo(&OffsetPathV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&OffsetPathV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let offset_path = fixture.add(decl!("core_types::vector::OffsetPathNode"@1), vec![literal(Tagged::None), number(10.), number(0.), number(4.)]);
|
||||
let migrated = fixture.migrate(&OffsetPathV1).unwrap();
|
||||
|
||||
let distance = literal(Tagged::Length(TypedLength { value: 10., unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, offset_path), [literal(Tagged::None), distance, number(0.), number(4.)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const DISTANCE: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The distance is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("core_types::vector::OffsetPointsNode"@1 => @2)]
|
||||
pub fn offset_points_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(DISTANCE) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
DISTANCE as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(2, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&OffsetPointsV1, &contract());
|
||||
check_undo(&OffsetPointsV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&OffsetPointsV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let offset_points = fixture.add(decl!("core_types::vector::OffsetPointsNode"@1), vec![literal(Tagged::None), number(10.)]);
|
||||
let migrated = fixture.migrate(&OffsetPointsV1).unwrap();
|
||||
|
||||
let distance = literal(Tagged::Length(TypedLength { value: 10., unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, offset_points), [literal(Tagged::None), distance]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const POINT: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
DVec2([f64; 2]),
|
||||
LengthVec2(TypedLengthVec2),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLengthVec2 {
|
||||
value: [f64; 2],
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The point is a pair of lengths, which keeps the pixels it held. A wired Vec2 still feeds it, read as pixels.
|
||||
#[migration("core_types::vector::PointInsideNode"@1 => @2)]
|
||||
pub fn point_inside_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(POINT) else { return };
|
||||
let Some(Tagged::DVec2(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(POINT as u32, lengths(pixels));
|
||||
}
|
||||
|
||||
fn lengths(pixels: [f64; 2]) -> NodeInput {
|
||||
literal(Tagged::LengthVec2(TypedLengthVec2 {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(2, |random, slot| match slot {
|
||||
POINT => literal(Tagged::DVec2([random.below(100) as f64, random.below(100) as f64])),
|
||||
_ => literal(Tagged::None),
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&PointInsideV1, &contract());
|
||||
check_undo(&PointInsideV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_vec2_of_pixels_becomes_lengths_in_pixels() {
|
||||
let mut fixture = Fixture::new(&PointInsideV1);
|
||||
let node = fixture.add(decl!("core_types::vector::PointInsideNode"@1), vec![literal(Tagged::None), literal(Tagged::DVec2([30., 40.]))]);
|
||||
let migrated = fixture.migrate(&PointInsideV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, node), [literal(Tagged::None), lengths([30., 40.])]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const RADIUS: usize = 1;
|
||||
const MIN_ANGLE_THRESHOLD: usize = 4;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
Angle(TypedAngle),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedAngle {
|
||||
value: f64,
|
||||
unit: AngleUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum AngleUnit {
|
||||
Degree,
|
||||
}
|
||||
|
||||
/// The radius is a length and the minimum angle threshold is an angle, which keep the numbers of pixels and degrees they held. Wired numbers still feed them, read as pixels and degrees.
|
||||
#[migration("core_types::vector::RoundCornersNode"@1 => @2)]
|
||||
pub fn round_corners_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(pixels) = number_at(RADIUS) {
|
||||
inputs.set(RADIUS as u32, length(pixels));
|
||||
}
|
||||
if let Some(degrees) = number_at(MIN_ANGLE_THRESHOLD) {
|
||||
inputs.set(MIN_ANGLE_THRESHOLD as u32, angle(degrees));
|
||||
}
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
fn angle(degrees: f64) -> NodeInput {
|
||||
literal(Tagged::Angle(TypedAngle {
|
||||
value: degrees,
|
||||
unit: AngleUnit::Degree,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(5, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&RoundCornersV1, &contract());
|
||||
check_undo(&RoundCornersV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_pixels_and_degrees_become_a_length_and_an_angle() {
|
||||
let mut fixture = Fixture::new(&RoundCornersV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let round_corners = fixture.add(
|
||||
decl!("core_types::vector::RoundCornersNode"@1),
|
||||
vec![literal(Tagged::None), number(10.), number(0.5), number(100.), number(5.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&RoundCornersV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, round_corners), [literal(Tagged::None), length(10.), number(0.5), number(100.), angle(5.)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const SEPARATION: usize = 2;
|
||||
const START_OFFSET: usize = 4;
|
||||
const STOP_OFFSET: usize = 5;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The separation and start and stop offsets are lengths, which keep the numbers of pixels they held. Wired numbers still feed them, read as pixels.
|
||||
#[migration("core_types::vector::SamplePolylineNode"@1 => @2)]
|
||||
pub fn sample_polyline_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
for slot in [SEPARATION, START_OFFSET, STOP_OFFSET] {
|
||||
if let Some(pixels) = number_at(slot) {
|
||||
inputs.set(slot as u32, length(pixels));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(7, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&SamplePolylineV1, &contract());
|
||||
check_undo(&SamplePolylineV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_pixels_become_lengths_in_pixels() {
|
||||
let mut fixture = Fixture::new(&SamplePolylineV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let sample_polyline = fixture.add(
|
||||
decl!("core_types::vector::SamplePolylineNode"@1),
|
||||
vec![literal(Tagged::None), number(0.), number(100.), number(100.), number(10.), number(20.), number(0.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&SamplePolylineV1).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
fixture.inputs(&migrated, sample_polyline),
|
||||
[literal(Tagged::None), number(0.), length(100.), number(100.), length(10.), length(20.), number(0.)]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const SEPARATION: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The separation is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("core_types::vector::ScatterPointsNode"@2 => @3)]
|
||||
pub fn scatter_points_v2(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(SEPARATION) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
SEPARATION as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(3, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&ScatterPointsV2, &contract());
|
||||
check_undo(&ScatterPointsV2, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&ScatterPointsV2);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let scatter_points = fixture.add(decl!("core_types::vector::ScatterPointsNode"@2), vec![literal(Tagged::None), number(10.), number(0.)]);
|
||||
let migrated = fixture.migrate(&ScatterPointsV2).unwrap();
|
||||
|
||||
let separation = literal(Tagged::Length(TypedLength { value: 10., unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, scatter_points), [literal(Tagged::None), separation, number(0.)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const TOLERANCE: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The tolerance is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("core_types::vector::SimplifyNode"@1 => @2)]
|
||||
pub fn simplify_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(TOLERANCE) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
TOLERANCE as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(2, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&SimplifyV1, &contract());
|
||||
check_undo(&SimplifyV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&SimplifyV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let simplify = fixture.add(decl!("core_types::vector::SimplifyNode"@1), vec![literal(Tagged::None), number(5.)]);
|
||||
let migrated = fixture.migrate(&SimplifyV1).unwrap();
|
||||
|
||||
let tolerance = literal(Tagged::Length(TypedLength { value: 5., unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, simplify), [literal(Tagged::None), tolerance]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const DISTANCE: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The distance is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("core_types::vector::WeldNode"@1 => @2)]
|
||||
pub fn weld_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(DISTANCE) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
DISTANCE as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(3, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&WeldV1, &contract());
|
||||
check_undo(&WeldV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&WeldV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let weld = fixture.add(decl!("core_types::vector::WeldNode"@1), vec![literal(Tagged::None), number(0.1), number(0.)]);
|
||||
let migrated = fixture.migrate(&WeldV1).unwrap();
|
||||
|
||||
let distance = literal(Tagged::Length(TypedLength { value: 0.1, unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, weld), [literal(Tagged::None), distance, number(0.)]);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
//! Migrations of the nodes in `graphene_core`.
|
||||
|
||||
mod pack_strips_v1;
|
||||
mod passthrough_from_upload_texture_node;
|
||||
mod renames;
|
||||
mod stroke_v1;
|
||||
mod vary_colors_from_assign_colors;
|
||||
@@ -0,0 +1,73 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const SEPARATION: usize = 1;
|
||||
const STRIP_MAX_LENGTH: usize = 2;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The separation and strip max length are lengths, which keep the numbers of pixels they held. Wired numbers still feed them, read as pixels.
|
||||
#[migration("graphene_core::vector::PackStripsNode"@1 => @2)]
|
||||
pub fn pack_strips_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
for slot in [SEPARATION, STRIP_MAX_LENGTH] {
|
||||
if let Some(pixels) = number_at(slot) {
|
||||
inputs.set(slot as u32, length(pixels));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(4, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&PackStripsV1, &contract());
|
||||
check_undo(&PackStripsV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_pixels_become_lengths_in_pixels() {
|
||||
let mut fixture = Fixture::new(&PackStripsV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let pack_strips = fixture.add(decl!("graphene_core::vector::PackStripsNode"@1), vec![literal(Tagged::None), number(10.), number(1000.), number(0.)]);
|
||||
let migrated = fixture.migrate(&PackStripsV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, pack_strips), [literal(Tagged::None), length(10.), length(1000.), number(0.)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const WEIGHT: usize = 2;
|
||||
const DASH_OFFSET: usize = 8;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The weight and dash offset are lengths, which keep the numbers of pixels they held. Wired numbers still feed them, read as pixels.
|
||||
#[migration("graphene_core::vector::StrokeNode"@1 => @2)]
|
||||
pub fn stroke_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
for slot in [WEIGHT, DASH_OFFSET] {
|
||||
if let Some(pixels) = number_at(slot) {
|
||||
inputs.set(slot as u32, length(pixels));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(9, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&StrokeV1, &contract());
|
||||
check_undo(&StrokeV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_pixels_become_lengths_in_pixels() {
|
||||
let mut fixture = Fixture::new(&StrokeV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let stroke = fixture.add(
|
||||
decl!("graphene_core::vector::StrokeNode"@1),
|
||||
vec![literal(Tagged::None), number(0.), number(2.), number(0.), number(0.), number(0.), number(4.), number(0.), number(5.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&StrokeV1).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
fixture.inputs(&migrated, stroke),
|
||||
[literal(Tagged::None), number(0.), length(2.), number(0.), number(0.), number(0.), number(4.), number(0.), length(5.)]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Migrations of the nodes in `graphene_std`.
|
||||
|
||||
mod renames;
|
||||
mod text_v1;
|
||||
@@ -0,0 +1,130 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const SIZE: usize = 3;
|
||||
const LETTER_SPACING: usize = 5;
|
||||
const LETTER_TILT: usize = 6;
|
||||
const MAX_WIDTH: usize = 8;
|
||||
const MAX_HEIGHT: usize = 10;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
Angle(TypedAngle),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedAngle {
|
||||
value: f64,
|
||||
unit: AngleUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum AngleUnit {
|
||||
Degree,
|
||||
}
|
||||
|
||||
/// The size, letter spacing, and max sizes are lengths and the letter tilt is an angle, which keep the numbers of pixels and degrees they held. Wired numbers still feed them, read as pixels and degrees.
|
||||
#[migration("graphene_std::text::TextNode"@1 => @2)]
|
||||
pub fn text_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
for slot in [SIZE, LETTER_SPACING, MAX_WIDTH, MAX_HEIGHT] {
|
||||
if let Some(pixels) = number_at(slot) {
|
||||
inputs.set(slot as u32, length(pixels));
|
||||
}
|
||||
}
|
||||
if let Some(degrees) = number_at(LETTER_TILT) {
|
||||
inputs.set(LETTER_TILT as u32, angle(degrees));
|
||||
}
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
fn angle(degrees: f64) -> NodeInput {
|
||||
literal(Tagged::Angle(TypedAngle {
|
||||
value: degrees,
|
||||
unit: AngleUnit::Degree,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(12, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&TextV1, &contract());
|
||||
check_undo(&TextV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_pixels_and_degrees_become_lengths_and_an_angle() {
|
||||
let mut fixture = Fixture::new(&TextV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let text = fixture.add(
|
||||
decl!("graphene_std::text::TextNode"@1),
|
||||
vec![
|
||||
literal(Tagged::None),
|
||||
number(0.),
|
||||
number(0.),
|
||||
number(24.),
|
||||
number(1.2),
|
||||
number(2.),
|
||||
number(10.),
|
||||
number(0.),
|
||||
number(100.),
|
||||
number(0.),
|
||||
number(100.),
|
||||
number(0.),
|
||||
],
|
||||
);
|
||||
let migrated = fixture.migrate(&TextV1).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
fixture.inputs(&migrated, text),
|
||||
[
|
||||
literal(Tagged::None),
|
||||
number(0.),
|
||||
number(0.),
|
||||
length(24.),
|
||||
number(1.2),
|
||||
length(2.),
|
||||
angle(10.),
|
||||
number(0.),
|
||||
length(100.),
|
||||
number(0.),
|
||||
length(100.),
|
||||
number(0.)
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const LOCATION: usize = 1;
|
||||
const DIMENSIONS: usize = 2;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
DVec2([f64; 2]),
|
||||
LengthVec2(TypedLengthVec2),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLengthVec2 {
|
||||
value: [f64; 2],
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The location and dimensions are pairs of lengths, which keep the pixels they held. Wired Vec2s still feed them, read as pixels.
|
||||
#[migration("graphic_nodes::artboard::CreateArtboardNode"@1 => @2)]
|
||||
pub fn create_artboard_v1(node: &Node, inputs: &mut Inputs) {
|
||||
for slot in [LOCATION, DIMENSIONS] {
|
||||
if let Some(Tagged::DVec2(pixels)) = node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
inputs.set(slot as u32, lengths(pixels));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lengths(pixels: [f64; 2]) -> NodeInput {
|
||||
literal(Tagged::LengthVec2(TypedLengthVec2 {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(5, |random, slot| match slot {
|
||||
LOCATION | DIMENSIONS => literal(Tagged::DVec2([random.below(100) as f64, random.below(100) as f64])),
|
||||
_ => literal(Tagged::None),
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&CreateArtboardV1, &contract());
|
||||
check_undo(&CreateArtboardV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec2s_of_pixels_become_lengths_in_pixels() {
|
||||
let mut fixture = Fixture::new(&CreateArtboardV1);
|
||||
let none = || literal(Tagged::None);
|
||||
let artboard = fixture.add(
|
||||
decl!("graphic_nodes::artboard::CreateArtboardNode"@1),
|
||||
vec![none(), literal(Tagged::DVec2([10., 20.])), literal(Tagged::DVec2([1920., 1080.])), none(), none()],
|
||||
);
|
||||
let migrated = fixture.migrate(&CreateArtboardV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, artboard), [none(), lengths([10., 20.]), lengths([1920., 1080.]), none(), none()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const OFFSET: usize = 2;
|
||||
const ANGLE: usize = 3;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
Angle(TypedAngle),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedAngle {
|
||||
value: f64,
|
||||
unit: AngleUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum AngleUnit {
|
||||
Degree,
|
||||
}
|
||||
|
||||
/// The offset is a length and the angle is an angle, which keep the numbers of pixels and degrees they held. Wired numbers still feed them, read as pixels and degrees.
|
||||
#[migration("graphic_nodes::graphic::MirrorNode"@1 => @2)]
|
||||
pub fn mirror_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(pixels) = number_at(OFFSET) {
|
||||
inputs.set(OFFSET as u32, length(pixels));
|
||||
}
|
||||
if let Some(degrees) = number_at(ANGLE) {
|
||||
inputs.set(ANGLE as u32, angle(degrees));
|
||||
}
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
fn angle(degrees: f64) -> NodeInput {
|
||||
literal(Tagged::Angle(TypedAngle {
|
||||
value: degrees,
|
||||
unit: AngleUnit::Degree,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(5, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&MirrorV1, &contract());
|
||||
check_undo(&MirrorV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_pixels_and_degrees_become_a_length_and_an_angle() {
|
||||
let mut fixture = Fixture::new(&MirrorV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let mirror = fixture.add(
|
||||
decl!("graphic_nodes::graphic::MirrorNode"@1),
|
||||
vec![literal(Tagged::None), number(0.), number(20.), number(45.), number(1.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&MirrorV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, mirror), [literal(Tagged::None), number(0.), length(20.), angle(45.), number(1.)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
//! Migrations of the nodes in `graphic_nodes`.
|
||||
|
||||
mod create_artboard_v1;
|
||||
mod mirror_v1;
|
||||
@@ -2,8 +2,13 @@
|
||||
//! `cargo run migration new <identifier>` after bumping a node's `version(N)`.
|
||||
|
||||
mod blending_nodes;
|
||||
mod brush_nodes;
|
||||
mod core_types;
|
||||
mod graphene_core;
|
||||
mod graphene_std;
|
||||
mod graphic_nodes;
|
||||
mod math_nodes;
|
||||
mod raster_nodes;
|
||||
mod repeat_nodes;
|
||||
mod transform_nodes;
|
||||
mod vector_nodes;
|
||||
@@ -0,0 +1,47 @@
|
||||
use migration_core::{Inputs, NodeInput, migration};
|
||||
|
||||
/// Reads the document's resolution from the scope, which sizes the physical lengths an expression measures.
|
||||
#[migration("math_nodes::MathFormulaNode"@2 => @3)]
|
||||
pub fn math_formula_v2(inputs: &mut Inputs) {
|
||||
inputs.push(NodeInput::Scope("pixels-per-inch".into()));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::{decl, literal};
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants the node's inputs hold in version 2.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
Number(f64),
|
||||
String(String),
|
||||
}
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(3, |random, slot| match slot {
|
||||
1 => literal(Tagged::String("a + b".to_string())),
|
||||
_ => literal(Tagged::Number(random.below(10) as f64)),
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&MathFormulaV2, &contract());
|
||||
check_undo(&MathFormulaV2, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_resolution_is_read_from_the_scope() {
|
||||
let inputs = vec![literal(Tagged::Number(2.)), literal(Tagged::String("a * 2".to_string())), literal(Tagged::Number(0.))];
|
||||
|
||||
let mut fixture = Fixture::new(&MathFormulaV2);
|
||||
let formula = fixture.add(decl!("math_nodes::MathFormulaNode"@2), inputs.clone());
|
||||
let migrated = fixture.migrate(&MathFormulaV2).unwrap();
|
||||
|
||||
let expected: Vec<NodeInput> = inputs.into_iter().chain([NodeInput::Scope("pixels-per-inch".into())]).collect();
|
||||
assert_eq!(fixture.inputs(&migrated, formula), expected);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
use migration_core::{Inputs, NodeInput, migration};
|
||||
|
||||
/// Reads the document's resolution from the scope, which sizes the physical lengths an expression measures.
|
||||
#[migration("math_nodes::MathFunctionNode"@2 => @3)]
|
||||
pub fn math_function_v2(inputs: &mut Inputs) {
|
||||
inputs.push(NodeInput::Scope("pixels-per-inch".into()));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::{decl, literal};
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants the node's inputs hold in version 2.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
Number(f64),
|
||||
String(String),
|
||||
}
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(3, |random, slot| match slot {
|
||||
1 => literal(Tagged::String("x".to_string())),
|
||||
_ => literal(Tagged::Number(random.below(10) as f64)),
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&MathFunctionV2, &contract());
|
||||
check_undo(&MathFunctionV2, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_resolution_is_read_from_the_scope() {
|
||||
let inputs = vec![literal(Tagged::Number(2.)), literal(Tagged::String("x * 2".to_string())), literal(Tagged::Number(0.))];
|
||||
|
||||
let mut fixture = Fixture::new(&MathFunctionV2);
|
||||
let function = fixture.add(decl!("math_nodes::MathFunctionNode"@2), inputs.clone());
|
||||
let migrated = fixture.migrate(&MathFunctionV2).unwrap();
|
||||
|
||||
let expected: Vec<NodeInput> = inputs.into_iter().chain([NodeInput::Scope("pixels-per-inch".into())]).collect();
|
||||
assert_eq!(fixture.inputs(&migrated, function), expected);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
//! Migrations of the nodes in `math_nodes`.
|
||||
|
||||
mod math_formula_from_math_f;
|
||||
mod math_formula_v2;
|
||||
mod math_function_v2;
|
||||
mod renames;
|
||||
@@ -3,3 +3,21 @@
|
||||
use migration_core::rename;
|
||||
|
||||
rename!("math_nodes::MathFxNode"@1 => "math_nodes::MathFunctionNode"@2);
|
||||
|
||||
// Version 2 takes lengths and angles too, with its output type following them, and stored nodes already have its layout
|
||||
rename!("math_nodes::SineNode"@1 => @2);
|
||||
rename!("math_nodes::CosineNode"@1 => @2);
|
||||
rename!("math_nodes::TangentNode"@1 => @2);
|
||||
rename!("math_nodes::SignNode"@1 => @2);
|
||||
rename!("math_nodes::SumNode"@1 => @2);
|
||||
rename!("math_nodes::AverageNode"@1 => @2);
|
||||
rename!("math_nodes::MinimumNode"@1 => @2);
|
||||
rename!("math_nodes::MaximumNode"@1 => @2);
|
||||
|
||||
// Version 2 reads a number beside a length or angle in pixels or degrees, and stored nodes already have its layout
|
||||
rename!("math_nodes::LerpNode"@1 => @2);
|
||||
rename!("math_nodes::ClampNode"@1 => @2);
|
||||
rename!("math_nodes::LessThanNode"@1 => @2);
|
||||
rename!("math_nodes::GreaterThanNode"@1 => @2);
|
||||
rename!("math_nodes::EqualsNode"@1 => @2);
|
||||
rename!("math_nodes::NotEqualsNode"@1 => @2);
|
||||
@@ -1,43 +0,0 @@
|
||||
use migration_core::{Inputs, literal, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variant this migration writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
Number(f64),
|
||||
}
|
||||
|
||||
/// 'Make Opaque' gained a Strength percentage, set to 100% to keep making the content fully opaque.
|
||||
#[migration("raster_nodes::adjustments::MakeOpaqueNode"@1 => @2)]
|
||||
pub fn make_opaque_v1(inputs: &mut Inputs) {
|
||||
inputs.push(literal(Tagged::Number(100.)));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(1, |random, _slot| literal(random.below(10) as f64))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&MakeOpaqueV1, &contract());
|
||||
check_undo(&MakeOpaqueV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_the_content_and_adds_full_strength() {
|
||||
let content = literal(1.);
|
||||
|
||||
let mut fixture = Fixture::new(&MakeOpaqueV1);
|
||||
let make_opaque = fixture.add(decl!("raster_nodes::adjustments::MakeOpaqueNode"@1), vec![content.clone()]);
|
||||
let migrated = fixture.migrate(&MakeOpaqueV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.declaration_of(&migrated, make_opaque), Some(decl!("raster_nodes::adjustments::MakeOpaqueNode"@2)));
|
||||
assert_eq!(fixture.inputs(&migrated, make_opaque), [content, literal(Tagged::Number(100.))]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const RADIUS: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The radius is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("raster_nodes::filter::MedianFilterNode"@1 => @2)]
|
||||
pub fn median_filter_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(RADIUS) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
RADIUS as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(2, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&MedianFilterV1, &contract());
|
||||
check_undo(&MedianFilterV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&MedianFilterV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let median_filter = fixture.add(decl!("raster_nodes::filter::MedianFilterNode"@1), vec![literal(Tagged::None), number(5.)]);
|
||||
let migrated = fixture.migrate(&MedianFilterV1).unwrap();
|
||||
|
||||
let radius = literal(Tagged::Length(TypedLength { value: 5., unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, median_filter), [literal(Tagged::None), radius]);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
//! Migrations of the nodes in `raster_nodes`.
|
||||
|
||||
mod make_opaque_v1;
|
||||
mod mandelbrot_v1;
|
||||
mod mandelbrot_v2;
|
||||
mod median_filter_v1;
|
||||
mod mix_colors_from_mix_node;
|
||||
mod noise_pattern_v1;
|
||||
mod noise_pattern_v2;
|
||||
mod pattern_square;
|
||||
mod renames;
|
||||
@@ -1,185 +0,0 @@
|
||||
use migration_core::attr::node::VISIBLE;
|
||||
use migration_core::attr::node::ui::POSITION;
|
||||
use migration_core::{Attributes, CHAIN_WIDTH, Downstream, NewNode, Node, NodeInput, OutputConnector, Position, decl, literal, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
Number(f64),
|
||||
Bool(bool),
|
||||
}
|
||||
|
||||
/// 'Noise Pattern' writes its value as the gray at that gamma-encoded level rather than as linear light, so whatever read it reads it through a
|
||||
/// 'Gamma Correction' at its default gamma of 2.2, which turns the new gray back into about the old one.
|
||||
#[migration("raster_nodes::std_nodes::NoisePatternNode"@2 => @3)]
|
||||
pub fn noise_pattern_v2(node: &Node, downstream: &mut Downstream, attributes: &mut Attributes) {
|
||||
let consumers = downstream.consumers(0);
|
||||
if consumers.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let gamma_correction = downstream.add_node(NewNode {
|
||||
declaration: decl!("raster_nodes::adjustments::GammaCorrectionNode"@1),
|
||||
inputs: vec![NodeInput::Node { id: node.id(), index: 0 }, literal(Tagged::Number(2.2)), literal(Tagged::Bool(false))],
|
||||
});
|
||||
for consumer in consumers {
|
||||
downstream.connect(OutputConnector { node: gamma_correction, output: 0 }, consumer);
|
||||
}
|
||||
|
||||
// A disabled pattern passes its primary input through, so its Gamma Correction is disabled too
|
||||
if !node.attributes().get_or(VISIBLE, true) {
|
||||
attributes.set(gamma_correction, VISIBLE, &false);
|
||||
}
|
||||
|
||||
// The Gamma Correction takes the pattern's place, with the pattern before it
|
||||
if let Some(stored) = node.attributes().get_typed::<Position>(POSITION) {
|
||||
attributes.set(gamma_correction, POSITION, &stored);
|
||||
}
|
||||
attributes.set(node.id(), POSITION, &Position::Relative([-CHAIN_WIDTH, 0]));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use document_graph_storage::{Implementation, Network, NetworkId, NodeId, ROOT_NETWORK, TimeStamp};
|
||||
use migration_core::Declaration;
|
||||
use migration_core::attr::node::ui::IS_LAYER;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
const NOISE_PATTERN: Declaration = decl!("raster_nodes::std_nodes::NoisePatternNode"@2);
|
||||
const GAMMA_CORRECTION: Declaration = decl!("raster_nodes::adjustments::GammaCorrectionNode"@1);
|
||||
const CONSUMER: Declaration = decl!("migration_testing::consumer"@1);
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(15, |random, _| literal(Tagged::Number(random.below(10) as f64)))
|
||||
}
|
||||
|
||||
fn noise_inputs() -> Vec<NodeInput> {
|
||||
(0..15).map(|slot| literal(Tagged::Number(slot as f64))).collect()
|
||||
}
|
||||
|
||||
fn wire(id: NodeId) -> NodeInput {
|
||||
NodeInput::Node { id, index: 0 }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&NoisePatternV2, &contract());
|
||||
check_undo(&NoisePatternV2, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_reader_reads_the_pattern_through_one_gamma_correction() {
|
||||
let mut fixture = Fixture::new(&NoisePatternV2);
|
||||
let noise = fixture.add(NOISE_PATTERN, noise_inputs());
|
||||
let both_slots = fixture.add(CONSUMER, vec![wire(noise), wire(noise)]);
|
||||
let second_slot = fixture.add(CONSUMER, vec![literal(Tagged::Number(0.)), wire(noise)]);
|
||||
fixture.export(wire(noise));
|
||||
let migrated = fixture.migrate(&NoisePatternV2).unwrap();
|
||||
|
||||
assert_eq!(fixture.declaration_of(&migrated, noise), Some(decl!("raster_nodes::std_nodes::NoisePatternNode"@3)));
|
||||
assert_eq!(fixture.inputs(&migrated, noise), noise_inputs());
|
||||
|
||||
let NodeInput::Node { id: gamma_correction, .. } = fixture.inputs(&migrated, second_slot)[1] else {
|
||||
panic!("the consumer should read a node")
|
||||
};
|
||||
assert_eq!(fixture.declaration_of(&migrated, gamma_correction), Some(GAMMA_CORRECTION));
|
||||
assert_eq!(fixture.inputs(&migrated, gamma_correction), [wire(noise), literal(Tagged::Number(2.2)), literal(Tagged::Bool(false))]);
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, both_slots), [wire(gamma_correction), wire(gamma_correction)]);
|
||||
assert_eq!(fixture.inputs(&migrated, second_slot)[0], literal(Tagged::Number(0.)));
|
||||
assert_eq!(migrated.networks[&ROOT_NETWORK].exports[0].target, Some(wire(gamma_correction)));
|
||||
assert_eq!(migrated.node_instances.len(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_disabled_pattern_is_read_through_a_disabled_gamma_correction() {
|
||||
let visibility_of_gamma_correction = |visible: bool| {
|
||||
let mut fixture = Fixture::new(&NoisePatternV2);
|
||||
let noise = fixture.add(NOISE_PATTERN, noise_inputs());
|
||||
if !visible {
|
||||
let attributes = fixture.registry.node_instances.get_mut(&noise).unwrap().attributes_mut();
|
||||
attributes.set_serialized(VISIBLE, &false, TimeStamp::ORIGIN).unwrap();
|
||||
}
|
||||
let consumer = fixture.add(CONSUMER, vec![wire(noise)]);
|
||||
let migrated = fixture.migrate(&NoisePatternV2).unwrap();
|
||||
|
||||
let NodeInput::Node { id: gamma_correction, .. } = fixture.inputs(&migrated, consumer)[0] else {
|
||||
panic!("the consumer should read a node")
|
||||
};
|
||||
migrated.node_instances[&gamma_correction].attributes().get_typed::<bool>(VISIBLE)
|
||||
};
|
||||
|
||||
// Visible is the default, so only a disabled pattern writes it
|
||||
assert_eq!(visibility_of_gamma_correction(false), Some(false));
|
||||
assert_eq!(visibility_of_gamma_correction(true), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unread_pattern_gains_no_gamma_correction() {
|
||||
let mut fixture = Fixture::new(&NoisePatternV2);
|
||||
let noise = fixture.add(NOISE_PATTERN, noise_inputs());
|
||||
let migrated = fixture.migrate(&NoisePatternV2).unwrap();
|
||||
|
||||
assert_eq!(fixture.declaration_of(&migrated, noise), Some(decl!("raster_nodes::std_nodes::NoisePatternNode"@3)));
|
||||
assert_eq!(migrated.node_instances.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pattern_in_a_subgraph_is_read_through_a_gamma_correction_inside_it() {
|
||||
let mut fixture = Fixture::new(&NoisePatternV2);
|
||||
|
||||
// A custom subgraph exporting the pattern, read by the root network's export
|
||||
let (subgraph, instance) = (NetworkId(100), NodeId(100));
|
||||
fixture.registry.networks.insert(subgraph, Network::default());
|
||||
let instance_node = document_graph_storage::Node::new(ROOT_NETWORK, Implementation::Network(subgraph), 0);
|
||||
fixture.registry.node_instances.insert(instance, instance_node);
|
||||
let noise = fixture.add_in(subgraph, NOISE_PATTERN, noise_inputs());
|
||||
fixture.export_from(subgraph, wire(noise));
|
||||
fixture.export(wire(instance));
|
||||
|
||||
let migrated = fixture.migrate(&NoisePatternV2).unwrap();
|
||||
|
||||
let Some(NodeInput::Node { id: gamma_correction, .. }) = migrated.networks[&subgraph].exports[0].target else {
|
||||
panic!("the subgraph's export should read a node")
|
||||
};
|
||||
assert_eq!(fixture.declaration_of(&migrated, gamma_correction), Some(GAMMA_CORRECTION));
|
||||
assert_eq!(migrated.node_instances[&gamma_correction].network(), subgraph);
|
||||
assert_eq!(fixture.inputs(&migrated, gamma_correction)[0], wire(noise));
|
||||
assert_eq!(migrated.networks[&ROOT_NETWORK].exports[0].target, Some(wire(instance)));
|
||||
}
|
||||
|
||||
/// The positions of the pattern and its Gamma Correction after migrating a pattern at `position`, read by a layer's chain or by another node.
|
||||
fn placed_gamma_correction(position: Position, read_by_layer: bool) -> [Option<Position>; 2] {
|
||||
let mut fixture = Fixture::new(&NoisePatternV2);
|
||||
let noise = fixture.add(NOISE_PATTERN, noise_inputs());
|
||||
let attributes = fixture.registry.node_instances.get_mut(&noise).unwrap().attributes_mut();
|
||||
attributes.set_serialized(POSITION, &position, TimeStamp::ORIGIN).unwrap();
|
||||
|
||||
let (reader, slot) = if read_by_layer {
|
||||
let layer = fixture.add(decl!("graphic_nodes::layer"@1), vec![literal(Tagged::Number(0.)), wire(noise)]);
|
||||
let attributes = fixture.registry.node_instances.get_mut(&layer).unwrap().attributes_mut();
|
||||
attributes.set_serialized(IS_LAYER, &true, TimeStamp::ORIGIN).unwrap();
|
||||
(layer, 1)
|
||||
} else {
|
||||
(fixture.add(CONSUMER, vec![wire(noise)]), 0)
|
||||
};
|
||||
|
||||
let migrated = fixture.migrate(&NoisePatternV2).unwrap();
|
||||
let NodeInput::Node { id: gamma_correction, .. } = fixture.inputs(&migrated, reader)[slot] else {
|
||||
panic!("slot {slot} of the reader should read a node")
|
||||
};
|
||||
assert_eq!(fixture.declaration_of(&migrated, gamma_correction), Some(GAMMA_CORRECTION));
|
||||
|
||||
[noise, gamma_correction].map(|node| migrated.node_instances[&node].attributes().get_typed::<Position>(POSITION))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_gamma_correction_takes_the_place_of_a_chained_or_placed_pattern() {
|
||||
let chained = Position::Relative([-CHAIN_WIDTH, 0]);
|
||||
for (position, read_by_layer) in [(chained, true), (Position::Absolute([5, 5]), false)] {
|
||||
assert_eq!(placed_gamma_correction(position, read_by_layer), [Some(chained), Some(position)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
//! Migrations of the nodes in `repeat_nodes`.
|
||||
|
||||
mod repeat_array_v1;
|
||||
mod repeat_radial_v1;
|
||||
@@ -0,0 +1,98 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const DIRECTION: usize = 1;
|
||||
const ANGLE: usize = 2;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
DVec2([f64; 2]),
|
||||
Angle(TypedAngle),
|
||||
LengthVec2(TypedLengthVec2),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLengthVec2 {
|
||||
value: [f64; 2],
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedAngle {
|
||||
value: f64,
|
||||
unit: AngleUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum AngleUnit {
|
||||
Degree,
|
||||
}
|
||||
|
||||
/// The direction is a pair of lengths and the angle is an angle, which keep the pixels and degrees they held. Wired values still feed them, read in those units.
|
||||
#[migration("repeat_nodes::repeat_nodes::RepeatArrayNode"@1 => @2)]
|
||||
pub fn repeat_array_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let literal_at = |slot: usize| node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input));
|
||||
|
||||
if let Some(Tagged::DVec2(pixels)) = literal_at(DIRECTION) {
|
||||
inputs.set(DIRECTION as u32, direction(pixels));
|
||||
}
|
||||
if let Some(Tagged::Number(degrees)) = literal_at(ANGLE) {
|
||||
inputs.set(ANGLE as u32, angle(degrees));
|
||||
}
|
||||
}
|
||||
|
||||
fn direction(pixels: [f64; 2]) -> NodeInput {
|
||||
literal(Tagged::LengthVec2(TypedLengthVec2 {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
fn angle(degrees: f64) -> NodeInput {
|
||||
literal(Tagged::Angle(TypedAngle {
|
||||
value: degrees,
|
||||
unit: AngleUnit::Degree,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(4, |random, slot| match slot {
|
||||
0 => literal(Tagged::None),
|
||||
DIRECTION => literal(Tagged::DVec2([random.below(100) as f64, random.below(100) as f64])),
|
||||
_ => literal(Tagged::Number(random.below(100) as f64)),
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&RepeatArrayV1, &contract());
|
||||
check_undo(&RepeatArrayV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_degrees_becomes_an_angle_in_degrees() {
|
||||
let mut fixture = Fixture::new(&RepeatArrayV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let repeat_array = fixture.add(
|
||||
decl!("repeat_nodes::repeat_nodes::RepeatArrayNode"@1),
|
||||
vec![literal(Tagged::None), literal(Tagged::DVec2([100., 50.])), number(90.), number(5.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&RepeatArrayV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, repeat_array), [literal(Tagged::None), direction([100., 50.]), angle(90.), number(5.)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const START_ANGLE: usize = 1;
|
||||
const RADIUS: usize = 2;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
Angle(TypedAngle),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedAngle {
|
||||
value: f64,
|
||||
unit: AngleUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum AngleUnit {
|
||||
Degree,
|
||||
}
|
||||
|
||||
/// The start angle is an angle and the radius is a length, which keep the numbers of degrees and pixels they held. Wired numbers still feed them, read as degrees and pixels.
|
||||
#[migration("repeat_nodes::repeat_nodes::RepeatRadialNode"@1 => @2)]
|
||||
pub fn repeat_radial_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(pixels) = number_at(RADIUS) {
|
||||
inputs.set(RADIUS as u32, length(pixels));
|
||||
}
|
||||
if let Some(degrees) = number_at(START_ANGLE) {
|
||||
inputs.set(START_ANGLE as u32, angle(degrees));
|
||||
}
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
fn angle(degrees: f64) -> NodeInput {
|
||||
literal(Tagged::Angle(TypedAngle {
|
||||
value: degrees,
|
||||
unit: AngleUnit::Degree,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(4, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&RepeatRadialV1, &contract());
|
||||
check_undo(&RepeatRadialV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_degrees_and_pixels_become_an_angle_and_a_length() {
|
||||
let mut fixture = Fixture::new(&RepeatRadialV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let repeat_radial = fixture.add(
|
||||
decl!("repeat_nodes::repeat_nodes::RepeatRadialNode"@1),
|
||||
vec![literal(Tagged::None), number(45.), number(5.), number(5.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&RepeatRadialV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, repeat_radial), [literal(Tagged::None), angle(45.), length(5.), number(5.)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
//! Migrations of the nodes in `transform_nodes`.
|
||||
|
||||
mod transform_v1;
|
||||
mod vary_rotations_v2;
|
||||
@@ -0,0 +1,125 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const TRANSLATION: usize = 1;
|
||||
const ROTATION: usize = 2;
|
||||
const SKEW: usize = 4;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
DVec2([f64; 2]),
|
||||
Angle(TypedAngle),
|
||||
LengthVec2(TypedLengthVec2),
|
||||
AngleVec2(TypedAngleVec2),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedAngle {
|
||||
value: f64,
|
||||
unit: AngleUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLengthVec2 {
|
||||
value: [f64; 2],
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedAngleVec2 {
|
||||
value: [f64; 2],
|
||||
unit: AngleUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum AngleUnit {
|
||||
Degree,
|
||||
}
|
||||
|
||||
/// The translation is a pair of lengths and the rotation and skew are angles, which keep the pixels and degrees they held. Wired values still feed them, read in those units.
|
||||
#[migration("transform_nodes::transform_nodes::TransformNode"@1 => @2)]
|
||||
pub fn transform_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let literal_at = |slot: usize| node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input));
|
||||
|
||||
if let Some(Tagged::DVec2(pixels)) = literal_at(TRANSLATION) {
|
||||
inputs.set(TRANSLATION as u32, translation(pixels));
|
||||
}
|
||||
if let Some(Tagged::Number(degrees)) = literal_at(ROTATION) {
|
||||
inputs.set(ROTATION as u32, rotation(degrees));
|
||||
}
|
||||
if let Some(Tagged::DVec2(degrees)) = literal_at(SKEW) {
|
||||
inputs.set(SKEW as u32, skew(degrees));
|
||||
}
|
||||
}
|
||||
|
||||
/// The whole-list counterpart of the Transform node, with parameters that migrate the same way.
|
||||
#[migration("transform_nodes::transform_nodes::TransformListNode"@1 => @2)]
|
||||
pub fn transform_list_v1(node: &Node, inputs: &mut Inputs) {
|
||||
transform_v1(node, inputs);
|
||||
}
|
||||
|
||||
fn translation(pixels: [f64; 2]) -> NodeInput {
|
||||
literal(Tagged::LengthVec2(TypedLengthVec2 {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
fn rotation(degrees: f64) -> NodeInput {
|
||||
literal(Tagged::Angle(TypedAngle {
|
||||
value: degrees,
|
||||
unit: AngleUnit::Degree,
|
||||
}))
|
||||
}
|
||||
|
||||
fn skew(degrees: [f64; 2]) -> NodeInput {
|
||||
literal(Tagged::AngleVec2(TypedAngleVec2 {
|
||||
value: degrees,
|
||||
unit: AngleUnit::Degree,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(5, |random, slot| match slot {
|
||||
0 => literal(Tagged::None),
|
||||
ROTATION => literal(Tagged::Number(random.below(360) as f64)),
|
||||
_ => literal(Tagged::DVec2([random.below(100) as f64, random.below(100) as f64])),
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&TransformV1, &contract());
|
||||
check_undo(&TransformV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pixels_and_degrees_become_typed_lengths_and_angles() {
|
||||
let mut fixture = Fixture::new(&TransformV1);
|
||||
let vec2 = |x: f64, y: f64| literal(Tagged::DVec2([x, y]));
|
||||
let transform = fixture.add(
|
||||
decl!("transform_nodes::transform_nodes::TransformNode"@1),
|
||||
vec![literal(Tagged::None), vec2(10., 20.), literal(Tagged::Number(45.)), vec2(2., 3.), vec2(15., 0.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&TransformV1).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
fixture.inputs(&migrated, transform),
|
||||
[literal(Tagged::None), translation([10., 20.]), rotation(45.), vec2(2., 3.), skew([15., 0.])]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const MIN: usize = 1;
|
||||
const MAX: usize = 2;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Angle(TypedAngle),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedAngle {
|
||||
value: f64,
|
||||
unit: AngleUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum AngleUnit {
|
||||
Degree,
|
||||
}
|
||||
|
||||
/// The ends of the range are angles, which keep the numbers of degrees they held. Wired numbers still feed them, read as degrees.
|
||||
#[migration("transform_nodes::transform_nodes::VaryRotationsNode"@2 => @3)]
|
||||
pub fn vary_rotations_v2(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
for slot in [MIN, MAX] {
|
||||
if let Some(degrees) = number_at(slot) {
|
||||
inputs.set(slot as u32, angle(degrees));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn angle(degrees: f64) -> NodeInput {
|
||||
literal(Tagged::Angle(TypedAngle {
|
||||
value: degrees,
|
||||
unit: AngleUnit::Degree,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(8, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&VaryRotationsV2, &contract());
|
||||
check_undo(&VaryRotationsV2, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_degrees_become_angles_in_degrees() {
|
||||
let mut fixture = Fixture::new(&VaryRotationsV2);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let vary_rotations = fixture.add(
|
||||
decl!("transform_nodes::transform_nodes::VaryRotationsNode"@2),
|
||||
vec![literal(Tagged::None), number(-180.), number(180.), number(0.5), number(0.), number(1.), number(0.), number(0.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&VaryRotationsV2).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
fixture.inputs(&migrated, vary_rotations),
|
||||
[literal(Tagged::None), angle(-180.), angle(180.), number(0.5), number(0.), number(1.), number(0.), number(0.)]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const RADIUS: usize = 1;
|
||||
const START_ANGLE: usize = 2;
|
||||
const SWEEP_ANGLE: usize = 3;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
Angle(TypedAngle),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedAngle {
|
||||
value: f64,
|
||||
unit: AngleUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum AngleUnit {
|
||||
Degree,
|
||||
}
|
||||
|
||||
/// The radius is a length and the start and sweep angles are angles, which keep the numbers of pixels and degrees they held. Wired numbers still feed them, read as pixels and degrees.
|
||||
#[migration("vector_nodes::generator_nodes::ArcNode"@1 => @2)]
|
||||
pub fn arc_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(pixels) = number_at(RADIUS) {
|
||||
inputs.set(RADIUS as u32, length(pixels));
|
||||
}
|
||||
for slot in [START_ANGLE, SWEEP_ANGLE] {
|
||||
if let Some(degrees) = number_at(slot) {
|
||||
inputs.set(slot as u32, angle(degrees));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
fn angle(degrees: f64) -> NodeInput {
|
||||
literal(Tagged::Angle(TypedAngle {
|
||||
value: degrees,
|
||||
unit: AngleUnit::Degree,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(5, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&ArcV1, &contract());
|
||||
check_undo(&ArcV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_pixels_and_degrees_become_a_length_and_angles() {
|
||||
let mut fixture = Fixture::new(&ArcV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let arc = fixture.add(
|
||||
decl!("vector_nodes::generator_nodes::ArcNode"@1),
|
||||
vec![literal(Tagged::None), number(50.), number(0.), number(270.), number(1.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&ArcV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, arc), [literal(Tagged::None), length(50.), angle(0.), angle(270.), number(1.)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const ARROW_TO: usize = 1;
|
||||
const SHAFT_WIDTH: usize = 2;
|
||||
const HEAD_WIDTH: usize = 3;
|
||||
const HEAD_LENGTH: usize = 4;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
DVec2([f64; 2]),
|
||||
Length(TypedLength),
|
||||
LengthVec2(TypedLengthVec2),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLengthVec2 {
|
||||
value: [f64; 2],
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The end point is a pair of lengths and the shaft and head sizes are lengths, which keep the pixels they held. Wired values still feed them, read as pixels.
|
||||
#[migration("vector_nodes::generator_nodes::ArrowNode"@1 => @2)]
|
||||
pub fn arrow_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(Tagged::DVec2(pixels)) = node.inputs().get(ARROW_TO).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
inputs.set(ARROW_TO as u32, lengths(pixels));
|
||||
}
|
||||
for slot in [SHAFT_WIDTH, HEAD_WIDTH, HEAD_LENGTH] {
|
||||
if let Some(pixels) = number_at(slot) {
|
||||
inputs.set(slot as u32, length(pixels));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lengths(pixels: [f64; 2]) -> NodeInput {
|
||||
literal(Tagged::LengthVec2(TypedLengthVec2 {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(5, |random, slot| match slot {
|
||||
0 => literal(Tagged::None),
|
||||
ARROW_TO => literal(Tagged::DVec2([random.below(100) as f64, random.below(100) as f64])),
|
||||
_ => literal(Tagged::Number(random.below(100) as f64)),
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&ArrowV1, &contract());
|
||||
check_undo(&ArrowV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_pixels_become_lengths_in_pixels() {
|
||||
let mut fixture = Fixture::new(&ArrowV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let arrow = fixture.add(
|
||||
decl!("vector_nodes::generator_nodes::ArrowNode"@1),
|
||||
vec![literal(Tagged::None), literal(Tagged::DVec2([100., 0.])), number(10.), number(30.), number(20.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&ArrowV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, arrow), [literal(Tagged::None), lengths([100., 0.]), length(10.), length(30.), length(20.)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const RADIUS: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The radius is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("vector_nodes::generator_nodes::CircleNode"@1 => @2)]
|
||||
pub fn circle_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(RADIUS) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
RADIUS as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(2, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&CircleV1, &contract());
|
||||
check_undo(&CircleV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&CircleV1);
|
||||
let circle = fixture.add(decl!("vector_nodes::generator_nodes::CircleNode"@1), vec![literal(Tagged::None), literal(Tagged::Number(50.))]);
|
||||
let migrated = fixture.migrate(&CircleV1).unwrap();
|
||||
|
||||
let radius = literal(Tagged::Length(TypedLength { value: 50., unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, circle), [literal(Tagged::None), radius]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const RADIUS_X: usize = 1;
|
||||
const RADIUS_Y: usize = 2;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The radii are lengths, which keep the numbers of pixels they held. Wired numbers still feed them, read as pixels.
|
||||
#[migration("vector_nodes::generator_nodes::EllipseNode"@1 => @2)]
|
||||
pub fn ellipse_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
for slot in [RADIUS_X, RADIUS_Y] {
|
||||
if let Some(pixels) = number_at(slot) {
|
||||
inputs.set(slot as u32, length(pixels));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(3, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&EllipseV1, &contract());
|
||||
check_undo(&EllipseV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_pixels_become_lengths_in_pixels() {
|
||||
let mut fixture = Fixture::new(&EllipseV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let ellipse = fixture.add(decl!("vector_nodes::generator_nodes::EllipseNode"@1), vec![literal(Tagged::None), number(50.), number(25.)]);
|
||||
let migrated = fixture.migrate(&EllipseV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, ellipse), [literal(Tagged::None), length(50.), length(25.)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const SPACING: usize = 6;
|
||||
const ANGLES: usize = 7;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
DVec2([f64; 2]),
|
||||
LengthVec2(TypedLengthVec2),
|
||||
AngleVec2(TypedAngleVec2),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLengthVec2 {
|
||||
value: [f64; 2],
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedAngleVec2 {
|
||||
value: [f64; 2],
|
||||
unit: AngleUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum AngleUnit {
|
||||
Degree,
|
||||
}
|
||||
|
||||
/// The spacing is a pair of lengths, filled from one number in both axes, and the isometric angles are a pair of angles, which keep the pixels and degrees they held. Wired values still feed them, read in those units.
|
||||
#[migration("vector_nodes::generator_nodes::GridNode"@1 => @2)]
|
||||
pub fn grid_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let literal_at = |slot: usize| node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input));
|
||||
|
||||
match literal_at(SPACING) {
|
||||
Some(Tagged::Number(pixels)) => inputs.set(SPACING as u32, lengths([pixels, pixels])),
|
||||
Some(Tagged::DVec2(pixels)) => inputs.set(SPACING as u32, lengths(pixels)),
|
||||
_ => {}
|
||||
}
|
||||
if let Some(Tagged::DVec2(degrees)) = literal_at(ANGLES) {
|
||||
inputs.set(ANGLES as u32, angles(degrees));
|
||||
}
|
||||
}
|
||||
|
||||
fn lengths(pixels: [f64; 2]) -> NodeInput {
|
||||
literal(Tagged::LengthVec2(TypedLengthVec2 {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
fn angles(degrees: [f64; 2]) -> NodeInput {
|
||||
literal(Tagged::AngleVec2(TypedAngleVec2 {
|
||||
value: degrees,
|
||||
unit: AngleUnit::Degree,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(8, |random, slot| match slot {
|
||||
SPACING if random.below(2) == 0 => literal(Tagged::Number(random.below(100) as f64)),
|
||||
SPACING | ANGLES => literal(Tagged::DVec2([random.below(100) as f64, random.below(100) as f64])),
|
||||
_ => literal(Tagged::None),
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&GridV1, &contract());
|
||||
check_undo(&GridV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pixels_and_degrees_become_typed_lengths_and_angles() {
|
||||
let mut fixture = Fixture::new(&GridV1);
|
||||
let none = || literal(Tagged::None);
|
||||
let square = fixture.add(
|
||||
decl!("vector_nodes::generator_nodes::GridNode"@1),
|
||||
vec![none(), none(), none(), none(), none(), none(), literal(Tagged::Number(10.)), literal(Tagged::DVec2([30., 30.]))],
|
||||
);
|
||||
let rectangular = fixture.add(
|
||||
decl!("vector_nodes::generator_nodes::GridNode"@1),
|
||||
vec![none(), none(), none(), none(), none(), none(), literal(Tagged::DVec2([10., 20.])), literal(Tagged::DVec2([30., 60.]))],
|
||||
);
|
||||
let migrated = fixture.migrate(&GridV1).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
fixture.inputs(&migrated, square),
|
||||
[none(), none(), none(), none(), none(), none(), lengths([10., 10.]), angles([30., 30.])]
|
||||
);
|
||||
assert_eq!(
|
||||
fixture.inputs(&migrated, rectangular),
|
||||
[none(), none(), none(), none(), none(), none(), lengths([10., 20.]), angles([30., 60.])]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const TIP_ANGLE: usize = 6;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Angle(TypedAngle),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedAngle {
|
||||
value: f64,
|
||||
unit: AngleUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum AngleUnit {
|
||||
Degree,
|
||||
}
|
||||
|
||||
/// The tip angle is an angle, which keeps the number of degrees it held. A wired number still feeds it, read as degrees.
|
||||
#[migration("vector_nodes::generator_nodes::HeartNode"@1 => @2)]
|
||||
pub fn heart_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(TIP_ANGLE) else { return };
|
||||
let Some(Tagged::Number(degrees)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
TIP_ANGLE as u32,
|
||||
literal(Tagged::Angle(TypedAngle {
|
||||
value: degrees,
|
||||
unit: AngleUnit::Degree,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(7, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&HeartV1, &contract());
|
||||
check_undo(&HeartV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_degrees_becomes_an_angle_in_degrees() {
|
||||
let mut fixture = Fixture::new(&HeartV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let heart = fixture.add(
|
||||
decl!("vector_nodes::generator_nodes::HeartNode"@1),
|
||||
vec![literal(Tagged::None), number(70.), number(0.), number(0.), number(70.), number(50.), number(75.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&HeartV1).unwrap();
|
||||
|
||||
let tip_angle = literal(Tagged::Angle(TypedAngle { value: 75., unit: AngleUnit::Degree }));
|
||||
assert_eq!(
|
||||
fixture.inputs(&migrated, heart),
|
||||
[literal(Tagged::None), number(70.), number(0.), number(0.), number(70.), number(50.), tip_angle]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const LINE_TO: usize = 1;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
DVec2([f64; 2]),
|
||||
LengthVec2(TypedLengthVec2),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLengthVec2 {
|
||||
value: [f64; 2],
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The end point is a pair of lengths, which keeps the pixels it held. A wired Vec2 still feeds it, read as pixels.
|
||||
#[migration("vector_nodes::generator_nodes::LineNode"@1 => @2)]
|
||||
pub fn line_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(LINE_TO) else { return };
|
||||
let Some(Tagged::DVec2(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(LINE_TO as u32, lengths(pixels));
|
||||
}
|
||||
|
||||
fn lengths(pixels: [f64; 2]) -> NodeInput {
|
||||
literal(Tagged::LengthVec2(TypedLengthVec2 {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(2, |random, slot| match slot {
|
||||
LINE_TO => literal(Tagged::DVec2([random.below(100) as f64, random.below(100) as f64])),
|
||||
_ => literal(Tagged::None),
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&LineV1, &contract());
|
||||
check_undo(&LineV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_vec2_of_pixels_becomes_lengths_in_pixels() {
|
||||
let mut fixture = Fixture::new(&LineV1);
|
||||
let node = fixture.add(decl!("vector_nodes::generator_nodes::LineNode"@1), vec![literal(Tagged::None), literal(Tagged::DVec2([30., 40.]))]);
|
||||
let migrated = fixture.migrate(&LineV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, node), [literal(Tagged::None), lengths([30., 40.])]);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,16 @@
|
||||
//! Migrations of the nodes in `vector_nodes`.
|
||||
|
||||
mod arc_v1;
|
||||
mod arrow_v1;
|
||||
mod circle_v1;
|
||||
mod ellipse_v1;
|
||||
mod grid_v1;
|
||||
mod heart_v1;
|
||||
mod line_v1;
|
||||
mod path_from_path_network;
|
||||
mod qr_code_v1;
|
||||
mod rectangle_v1;
|
||||
mod regular_polygon_v1;
|
||||
mod renames;
|
||||
mod spiral_v1;
|
||||
mod star_v1;
|
||||
@@ -0,0 +1,69 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const SIZE: usize = 3;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The size is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("vector_nodes::generator_nodes::QrCodeNode"@1 => @2)]
|
||||
pub fn qr_code_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(SIZE) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(SIZE as u32, length(pixels));
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(6, |random, slot| if slot == SIZE { literal(Tagged::Number(random.below(100) as f64)) } else { literal(Tagged::None) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&QrCodeV1, &contract());
|
||||
check_undo(&QrCodeV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&QrCodeV1);
|
||||
let none = || literal(Tagged::None);
|
||||
let qr_code = fixture.add(
|
||||
decl!("vector_nodes::generator_nodes::QrCodeNode"@1),
|
||||
vec![none(), none(), none(), literal(Tagged::Number(200.)), none(), none()],
|
||||
);
|
||||
let migrated = fixture.migrate(&QrCodeV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, qr_code), [none(), none(), none(), length(200.), none(), none()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const WIDTH: usize = 1;
|
||||
const HEIGHT: usize = 2;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The width and height are lengths, which keep the numbers of pixels they held. Wired numbers still feed them, read as pixels.
|
||||
#[migration("vector_nodes::generator_nodes::RectangleNode"@1 => @2)]
|
||||
pub fn rectangle_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
for slot in [WIDTH, HEIGHT] {
|
||||
if let Some(pixels) = number_at(slot) {
|
||||
inputs.set(slot as u32, length(pixels));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(6, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&RectangleV1, &contract());
|
||||
check_undo(&RectangleV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_pixels_become_lengths_in_pixels() {
|
||||
let mut fixture = Fixture::new(&RectangleV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let rectangle = fixture.add(
|
||||
decl!("vector_nodes::generator_nodes::RectangleNode"@1),
|
||||
vec![literal(Tagged::None), number(100.), number(80.), number(0.), number(1.), number(0.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&RectangleV1).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
fixture.inputs(&migrated, rectangle),
|
||||
[literal(Tagged::None), length(100.), length(80.), number(0.), number(1.), number(0.)]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
use migration_core::{Inputs, Node, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const RADIUS: usize = 2;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The radius is a length, which keeps the number of pixels it held. A wired number still feeds it, read as pixels.
|
||||
#[migration("vector_nodes::generator_nodes::RegularPolygonNode"@1 => @2)]
|
||||
pub fn regular_polygon_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let Some(slot) = node.inputs().get(RADIUS) else { return };
|
||||
let Some(Tagged::Number(pixels)) = literal_of::<Tagged>(&slot.input) else { return };
|
||||
|
||||
inputs.set(
|
||||
RADIUS as u32,
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(3, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&RegularPolygonV1, &contract());
|
||||
check_undo(&RegularPolygonV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_number_of_pixels_becomes_a_length_in_pixels() {
|
||||
let mut fixture = Fixture::new(&RegularPolygonV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let polygon = fixture.add(decl!("vector_nodes::generator_nodes::RegularPolygonNode"@1), vec![literal(Tagged::None), number(6.), number(50.)]);
|
||||
let migrated = fixture.migrate(&RegularPolygonV1).unwrap();
|
||||
|
||||
let radius = literal(Tagged::Length(TypedLength { value: 50., unit: LengthUnit::Pixel }));
|
||||
assert_eq!(fixture.inputs(&migrated, polygon), [literal(Tagged::None), number(6.), radius]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const START_ANGLE: usize = 3;
|
||||
const INNER_RADIUS: usize = 4;
|
||||
const OUTER_RADIUS: usize = 5;
|
||||
const ANGULAR_RESOLUTION: usize = 6;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
Angle(TypedAngle),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedAngle {
|
||||
value: f64,
|
||||
unit: AngleUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum AngleUnit {
|
||||
Degree,
|
||||
}
|
||||
|
||||
/// The radii are lengths and the start angle and angular resolution are angles, which keep the numbers of pixels and degrees they held. Wired numbers still feed them, read as pixels and degrees.
|
||||
#[migration("vector_nodes::generator_nodes::SpiralNode"@1 => @2)]
|
||||
pub fn spiral_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
for slot in [INNER_RADIUS, OUTER_RADIUS] {
|
||||
if let Some(pixels) = number_at(slot) {
|
||||
inputs.set(slot as u32, length(pixels));
|
||||
}
|
||||
}
|
||||
for slot in [START_ANGLE, ANGULAR_RESOLUTION] {
|
||||
if let Some(degrees) = number_at(slot) {
|
||||
inputs.set(slot as u32, angle(degrees));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
fn angle(degrees: f64) -> NodeInput {
|
||||
literal(Tagged::Angle(TypedAngle {
|
||||
value: degrees,
|
||||
unit: AngleUnit::Degree,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(7, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&SpiralV1, &contract());
|
||||
check_undo(&SpiralV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_pixels_and_degrees_become_lengths_and_angles() {
|
||||
let mut fixture = Fixture::new(&SpiralV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let spiral = fixture.add(
|
||||
decl!("vector_nodes::generator_nodes::SpiralNode"@1),
|
||||
vec![literal(Tagged::None), number(0.), number(5.), number(0.), number(0.), number(25.), number(90.)],
|
||||
);
|
||||
let migrated = fixture.migrate(&SpiralV1).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
fixture.inputs(&migrated, spiral),
|
||||
[literal(Tagged::None), number(0.), number(5.), angle(0.), length(0.), length(25.), angle(90.)]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
use migration_core::{Inputs, Node, NodeInput, literal, literal_of, migration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const RADIUS_1: usize = 2;
|
||||
const RADIUS_2: usize = 3;
|
||||
|
||||
/// Frozen mirror of the `TaggedValue` variants this migration reads and writes.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum Tagged {
|
||||
None,
|
||||
Number(f64),
|
||||
Length(TypedLength),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct TypedLength {
|
||||
value: f64,
|
||||
unit: LengthUnit,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
enum LengthUnit {
|
||||
Pixel,
|
||||
}
|
||||
|
||||
/// The radii are lengths, which keep the numbers of pixels they held. Wired numbers still feed them, read as pixels.
|
||||
#[migration("vector_nodes::generator_nodes::StarNode"@1 => @2)]
|
||||
pub fn star_v1(node: &Node, inputs: &mut Inputs) {
|
||||
let number_at = |slot: usize| match node.inputs().get(slot).and_then(|slot| literal_of::<Tagged>(&slot.input)) {
|
||||
Some(Tagged::Number(number)) => Some(number),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
for slot in [RADIUS_1, RADIUS_2] {
|
||||
if let Some(pixels) = number_at(slot) {
|
||||
inputs.set(slot as u32, length(pixels));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn length(pixels: f64) -> NodeInput {
|
||||
literal(Tagged::Length(TypedLength {
|
||||
value: pixels,
|
||||
unit: LengthUnit::Pixel,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use migration_core::decl;
|
||||
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};
|
||||
|
||||
fn contract() -> SourceContract {
|
||||
SourceContract::new(4, |random, slot| if slot == 0 { literal(Tagged::None) } else { literal(Tagged::Number(random.below(100) as f64)) })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rewrites_history() {
|
||||
check_commutation(&StarV1, &contract());
|
||||
check_undo(&StarV1, &contract());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_of_pixels_become_lengths_in_pixels() {
|
||||
let mut fixture = Fixture::new(&StarV1);
|
||||
let number = |number: f64| literal(Tagged::Number(number));
|
||||
let star = fixture.add(decl!("vector_nodes::generator_nodes::StarNode"@1), vec![literal(Tagged::None), number(5.), number(50.), number(25.)]);
|
||||
let migrated = fixture.migrate(&StarV1).unwrap();
|
||||
|
||||
assert_eq!(fixture.inputs(&migrated, star), [literal(Tagged::None), number(5.), length(50.), length(25.)]);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ use crate::messages::prelude::*;
|
||||
pub enum DialogMessage {
|
||||
// Sub-messages
|
||||
#[child]
|
||||
DocumentSetupDialog(DocumentSetupDialogMessage),
|
||||
#[child]
|
||||
ExportDialog(ExportDialogMessage),
|
||||
#[child]
|
||||
NewDocumentDialog(NewDocumentDialogMessage),
|
||||
@@ -34,6 +36,7 @@ pub enum DialogMessage {
|
||||
localized_commit_year: String,
|
||||
},
|
||||
RequestDemoArtworkDialog,
|
||||
RequestDocumentSetupDialog,
|
||||
RequestExportDialog,
|
||||
RequestLicensesDialogWithLocalizedCommitDate {
|
||||
localized_commit_year: String,
|
||||
|
||||
@@ -4,6 +4,7 @@ use crate::messages::dialog::simple_dialogs::{ConfirmRestartDialog, LicensesThir
|
||||
use crate::messages::frontend::utility_types::ExportBounds;
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::prelude::*;
|
||||
use graphene_std::units::{DEFAULT_PIXELS_PER_INCH, TypedLength};
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct DialogMessageContext<'a> {
|
||||
@@ -16,6 +17,7 @@ pub struct DialogMessageContext<'a> {
|
||||
pub struct DialogMessageHandler {
|
||||
on_dismiss: Option<Message>,
|
||||
redisplay: Option<Message>,
|
||||
document_setup_dialog: DocumentSetupDialogMessageHandler,
|
||||
export_dialog: ExportDialogMessageHandler,
|
||||
new_document_dialog: NewDocumentDialogMessageHandler,
|
||||
preferences_dialog: PreferencesDialogMessageHandler,
|
||||
@@ -27,6 +29,7 @@ impl MessageHandler<DialogMessage, DialogMessageContext<'_>> for DialogMessageHa
|
||||
let DialogMessageContext { portfolio, preferences } = context;
|
||||
|
||||
match message {
|
||||
DialogMessage::DocumentSetupDialog(message) => self.document_setup_dialog.process_message(message, responses, ()),
|
||||
DialogMessage::ExportDialog(message) => self.export_dialog.process_message(message, responses, ExportDialogMessageContext { portfolio }),
|
||||
DialogMessage::NewDocumentDialog(message) => self.new_document_dialog.process_message(message, responses, ()),
|
||||
DialogMessage::PreferencesDialog(message) => self.preferences_dialog.process_message(message, responses, PreferencesDialogMessageContext { preferences }),
|
||||
@@ -100,30 +103,25 @@ impl MessageHandler<DialogMessage, DialogMessageContext<'_>> for DialogMessageHa
|
||||
let dialog = DemoArtworkDialog;
|
||||
dialog.send_dialog_to_frontend(responses);
|
||||
}
|
||||
DialogMessage::RequestDocumentSetupDialog => {
|
||||
self.on_dismiss = Some(DialogMessage::Close.into());
|
||||
if let Some(document) = portfolio.active_document() {
|
||||
self.document_setup_dialog = DocumentSetupDialogMessageHandler {
|
||||
pixels_per_inch: document.network_interface.pixels_per_inch(),
|
||||
};
|
||||
self.document_setup_dialog.send_dialog_to_frontend(responses);
|
||||
}
|
||||
}
|
||||
DialogMessage::RequestExportDialog => {
|
||||
self.on_dismiss = Some(DialogMessage::Close.into());
|
||||
if let Some(document) = portfolio.active_document() {
|
||||
let artboards = document
|
||||
.metadata()
|
||||
.all_layers()
|
||||
.filter(|&layer| document.network_interface.is_artboard(&layer.to_node(), &[]))
|
||||
.map(|layer| {
|
||||
let name = document
|
||||
.network_interface
|
||||
.node_metadata(&layer.to_node(), &[])
|
||||
.map(|node| node.persistent_metadata.display_name.clone())
|
||||
.filter(|name| !name.is_empty())
|
||||
.unwrap_or_else(|| "Artboard".to_string());
|
||||
(layer, name)
|
||||
})
|
||||
.collect();
|
||||
|
||||
self.export_dialog.artboards = artboards;
|
||||
self.export_dialog.artboards = document.artboard_names();
|
||||
|
||||
if let ExportBounds::Artboard(layer) = self.export_dialog.bounds
|
||||
&& !self.export_dialog.artboards.contains_key(&layer)
|
||||
&& !self.export_dialog.artboards.iter().any(|(artboard, _)| *artboard == layer)
|
||||
{
|
||||
self.export_dialog.bounds = ExportBounds::AllArtwork;
|
||||
self.export_dialog.bounds = self.export_dialog.default_bounds();
|
||||
self.export_dialog.bounds_chosen = false;
|
||||
}
|
||||
|
||||
self.export_dialog.has_selection = document.network_interface.selected_nodes().selected_layers(document.metadata()).next().is_some();
|
||||
@@ -145,7 +143,9 @@ impl MessageHandler<DialogMessage, DialogMessageContext<'_>> for DialogMessageHa
|
||||
self.new_document_dialog = NewDocumentDialogMessageHandler {
|
||||
name: portfolio.generate_new_document_name(None),
|
||||
infinite: false,
|
||||
dimensions: glam::UVec2::new(1920, 1080),
|
||||
width: TypedLength::pixels(1920.),
|
||||
height: TypedLength::pixels(1080.),
|
||||
pixels_per_inch: DEFAULT_PIXELS_PER_INCH,
|
||||
};
|
||||
self.new_document_dialog.send_dialog_to_frontend(responses);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
#[impl_message(Message, DialogMessage, DocumentSetupDialog)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum DocumentSetupDialogMessage {
|
||||
Resolution { pixels_per_inch: f64 },
|
||||
|
||||
Submit,
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::prelude::*;
|
||||
use graphene_std::units::DEFAULT_PIXELS_PER_INCH;
|
||||
|
||||
/// A dialog to allow users to change the settings of the active document.
|
||||
#[derive(Debug, Clone, ExtractField)]
|
||||
pub struct DocumentSetupDialogMessageHandler {
|
||||
pub pixels_per_inch: f64,
|
||||
}
|
||||
|
||||
impl Default for DocumentSetupDialogMessageHandler {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pixels_per_inch: DEFAULT_PIXELS_PER_INCH,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<DocumentSetupDialogMessage, ()> for DocumentSetupDialogMessageHandler {
|
||||
fn process_message(&mut self, message: DocumentSetupDialogMessage, responses: &mut VecDeque<Message>, _: ()) {
|
||||
match message {
|
||||
DocumentSetupDialogMessage::Resolution { pixels_per_inch } => self.pixels_per_inch = pixels_per_inch,
|
||||
|
||||
DocumentSetupDialogMessage::Submit => {
|
||||
// The settings apply as one undo step, which ending the transaction drops if nothing changed
|
||||
responses.add(DocumentMessage::StartTransaction);
|
||||
responses.add(DocumentMessage::SetPixelsPerInch {
|
||||
pixels_per_inch: self.pixels_per_inch,
|
||||
});
|
||||
responses.add(DocumentMessage::EndTransaction);
|
||||
}
|
||||
}
|
||||
|
||||
self.send_dialog_to_frontend(responses);
|
||||
}
|
||||
|
||||
advertise_actions!(DocumentSetupDialogUpdate;
|
||||
);
|
||||
}
|
||||
|
||||
impl DialogLayoutHolder for DocumentSetupDialogMessageHandler {
|
||||
const ICON: &'static str = "File";
|
||||
const TITLE: &'static str = "Document Setup";
|
||||
|
||||
fn layout_buttons(&self) -> Layout {
|
||||
let widgets = vec![
|
||||
TextButton::new("OK")
|
||||
.emphasized(true)
|
||||
.on_update(|_| {
|
||||
DialogMessage::CloseAndThen {
|
||||
followups: vec![DocumentSetupDialogMessage::Submit.into()],
|
||||
}
|
||||
.into()
|
||||
})
|
||||
.widget_instance(),
|
||||
TextButton::new("Cancel").on_update(|_| DialogMessage::Close.into()).widget_instance(),
|
||||
];
|
||||
|
||||
Layout(vec![LayoutGroup::row(widgets)])
|
||||
}
|
||||
}
|
||||
|
||||
impl LayoutHolder for DocumentSetupDialogMessageHandler {
|
||||
fn layout(&self) -> Layout {
|
||||
let resolution = resolution_row(self.pixels_per_inch, |pixels_per_inch| DocumentSetupDialogMessage::Resolution { pixels_per_inch }.into());
|
||||
|
||||
Layout(vec![LayoutGroup::row(resolution)])
|
||||
}
|
||||
}
|
||||
|
||||
/// The labeled field for a document's resolution in pixels per inch, shared by the dialogs that set it.
|
||||
pub fn resolution_row(pixels_per_inch: f64, on_update: impl Fn(f64) -> Message + Send + Sync + 'static) -> Vec<WidgetInstance> {
|
||||
let description = "How many pixels make an inch, which sizes the lengths typed in physical units like millimeters and inches, and the physical size of exported files.";
|
||||
|
||||
vec![
|
||||
TextLabel::new("Resolution")
|
||||
.table_align(true)
|
||||
.sizing(WidgetSizing::fixed(90))
|
||||
.tooltip_label("Resolution")
|
||||
.tooltip_description(description)
|
||||
.widget_instance(),
|
||||
Separator::new(SeparatorStyle::Unrelated).widget_instance(),
|
||||
NumberInput::new(Some(pixels_per_inch))
|
||||
.unit(" PPI")
|
||||
.min(1.)
|
||||
.max(100_000.)
|
||||
.tooltip_label("Resolution")
|
||||
.tooltip_description(description)
|
||||
// Matches the width of the New Document dialog's Name field
|
||||
.sizing(WidgetSizing::default().min_width(204))
|
||||
.on_update(move |number_input: &NumberInput| on_update(number_input.value.unwrap_or(DEFAULT_PIXELS_PER_INCH)))
|
||||
.widget_instance(),
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::test_utils::test_prelude::*;
|
||||
|
||||
fn pixels_per_inch(editor: &EditorTestUtils) -> f64 {
|
||||
editor.active_document().network_interface.pixels_per_inch()
|
||||
}
|
||||
|
||||
async fn open_and_set_resolution(editor: &mut EditorTestUtils, pixels_per_inch: f64) {
|
||||
editor.handle_message(DialogMessage::RequestDocumentSetupDialog).await;
|
||||
editor.handle_message(DocumentSetupDialogMessage::Resolution { pixels_per_inch }).await;
|
||||
}
|
||||
|
||||
async fn confirm(editor: &mut EditorTestUtils) {
|
||||
editor
|
||||
.handle_message(DialogMessage::CloseAndThen {
|
||||
followups: vec![DocumentSetupDialogMessage::Submit.into()],
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn confirming_a_resolution_applies_it_as_one_undo_step() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
editor.draw_rect(0., 0., 100., 100.).await;
|
||||
let layer_count = editor.active_document().metadata().all_layers().count();
|
||||
|
||||
open_and_set_resolution(&mut editor, 300.).await;
|
||||
assert_eq!(pixels_per_inch(&editor), 96., "the dialog applies nothing before it is confirmed");
|
||||
confirm(&mut editor).await;
|
||||
assert_eq!(pixels_per_inch(&editor), 300.);
|
||||
|
||||
// Undoing reverts only the resolution, leaving the rectangle drawn before it
|
||||
editor.handle_message(DocumentMessage::Undo).await;
|
||||
assert_eq!(pixels_per_inch(&editor), 96.);
|
||||
assert_eq!(editor.active_document().metadata().all_layers().count(), layer_count);
|
||||
|
||||
editor.handle_message(DocumentMessage::Redo).await;
|
||||
assert_eq!(pixels_per_inch(&editor), 300.);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn canceling_or_confirming_an_unchanged_resolution_adds_no_undo_step() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
editor.new_document().await;
|
||||
open_and_set_resolution(&mut editor, 300.).await;
|
||||
confirm(&mut editor).await;
|
||||
|
||||
open_and_set_resolution(&mut editor, 150.).await;
|
||||
editor.handle_message(DialogMessage::Close).await;
|
||||
assert_eq!(pixels_per_inch(&editor), 300., "canceling discards the dialog's resolution");
|
||||
|
||||
// Reopening starts from the document's resolution, so confirming it unchanged has nothing to apply
|
||||
editor.handle_message(DialogMessage::RequestDocumentSetupDialog).await;
|
||||
confirm(&mut editor).await;
|
||||
assert_eq!(pixels_per_inch(&editor), 300.);
|
||||
|
||||
editor.handle_message(DocumentMessage::Undo).await;
|
||||
assert_eq!(pixels_per_inch(&editor), 96., "the one undo step is the resolution's first change");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
mod document_setup_dialog_message;
|
||||
mod document_setup_dialog_message_handler;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use document_setup_dialog_message::{DocumentSetupDialogMessage, DocumentSetupDialogMessageDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use document_setup_dialog_message_handler::{DocumentSetupDialogMessageHandler, resolution_row};
|
||||
@@ -14,7 +14,10 @@ pub struct ExportDialogMessageHandler {
|
||||
pub file_type: FileType,
|
||||
pub scale_factor: f64,
|
||||
pub bounds: ExportBounds,
|
||||
pub artboards: HashMap<LayerNodeIdentifier, String>,
|
||||
/// Whether the bounds were picked in the dialog, rather than left at the default of the file type, which a change of file type replaces.
|
||||
pub bounds_chosen: bool,
|
||||
/// Each artboard with its name, from the top of the Layers panel down.
|
||||
pub artboards: Vec<(LayerNodeIdentifier, String)>,
|
||||
pub has_selection: bool,
|
||||
}
|
||||
|
||||
@@ -24,6 +27,7 @@ impl Default for ExportDialogMessageHandler {
|
||||
file_type: Default::default(),
|
||||
scale_factor: 1.,
|
||||
bounds: Default::default(),
|
||||
bounds_chosen: false,
|
||||
artboards: Default::default(),
|
||||
has_selection: false,
|
||||
}
|
||||
@@ -36,20 +40,23 @@ impl MessageHandler<ExportDialogMessage, ExportDialogMessageContext<'_>> for Exp
|
||||
let ExportDialogMessageContext { portfolio } = context;
|
||||
|
||||
match message {
|
||||
ExportDialogMessage::FileType { file_type } => self.file_type = file_type,
|
||||
ExportDialogMessage::FileType { file_type } => {
|
||||
self.file_type = file_type;
|
||||
if !self.bounds_chosen {
|
||||
self.bounds = self.default_bounds();
|
||||
}
|
||||
}
|
||||
ExportDialogMessage::ScaleFactor { factor } => self.scale_factor = factor,
|
||||
ExportDialogMessage::ExportBounds { bounds } => self.bounds = bounds,
|
||||
ExportDialogMessage::ExportBounds { bounds } => {
|
||||
self.bounds = bounds;
|
||||
self.bounds_chosen = true;
|
||||
}
|
||||
|
||||
ExportDialogMessage::Submit => {
|
||||
// Fall back to "All Artwork" if "Selection" was chosen but nothing is currently selected
|
||||
let bounds = if !self.has_selection && self.bounds == ExportBounds::Selection {
|
||||
ExportBounds::AllArtwork
|
||||
} else {
|
||||
self.bounds
|
||||
};
|
||||
let bounds = self.current_bounds();
|
||||
|
||||
let artboard_name = match bounds {
|
||||
ExportBounds::Artboard(layer) => self.artboards.get(&layer).cloned(),
|
||||
ExportBounds::Artboard(layer) => self.artboards.iter().find(|(artboard, _)| *artboard == layer).map(|(_, name)| name.clone()),
|
||||
_ => None,
|
||||
};
|
||||
responses.add_front(PortfolioMessage::SubmitDocumentExport {
|
||||
@@ -70,6 +77,23 @@ impl MessageHandler<ExportDialogMessage, ExportDialogMessageContext<'_>> for Exp
|
||||
);
|
||||
}
|
||||
|
||||
impl ExportDialogMessageHandler {
|
||||
/// The bounds a file type starts with: each artboard as its own page for a PDF, or otherwise all the artwork.
|
||||
pub fn default_bounds(&self) -> ExportBounds {
|
||||
if self.file_type == FileType::Pdf { ExportBounds::AllArtboards } else { ExportBounds::AllArtwork }
|
||||
}
|
||||
|
||||
/// The chosen bounds, falling back to the default and then "All Artwork" in place of a choice that isn't currently available.
|
||||
fn current_bounds(&self) -> ExportBounds {
|
||||
let available = |bounds: &ExportBounds| match bounds {
|
||||
ExportBounds::Selection => self.has_selection,
|
||||
ExportBounds::AllArtboards => self.file_type == FileType::Pdf && !self.artboards.is_empty(),
|
||||
ExportBounds::AllArtwork | ExportBounds::Artboard(_) => true,
|
||||
};
|
||||
[self.bounds, self.default_bounds()].into_iter().find(available).unwrap_or(ExportBounds::AllArtwork)
|
||||
}
|
||||
}
|
||||
|
||||
impl DialogLayoutHolder for ExportDialogMessageHandler {
|
||||
const ICON: &'static str = "File";
|
||||
const TITLE: &'static str = "Export";
|
||||
@@ -94,9 +118,9 @@ impl DialogLayoutHolder for ExportDialogMessageHandler {
|
||||
|
||||
impl LayoutHolder for ExportDialogMessageHandler {
|
||||
fn layout(&self) -> Layout {
|
||||
// The vector type, then the raster ones
|
||||
// The vector types, then the raster ones
|
||||
let file_types = [
|
||||
vec![(FileType::Svg, "SVG")],
|
||||
vec![(FileType::Svg, "SVG"), (FileType::Pdf, "PDF")],
|
||||
vec![
|
||||
(FileType::Png, "PNG"),
|
||||
(FileType::Jpg, "JPG"),
|
||||
@@ -139,7 +163,7 @@ impl LayoutHolder for ExportDialogMessageHandler {
|
||||
.min(0.)
|
||||
.max((1_u64 << f64::MANTISSA_DIGITS) as f64)
|
||||
.increment_step(0.5)
|
||||
.disabled(self.file_type == FileType::Svg)
|
||||
.disabled(matches!(self.file_type, FileType::Svg | FileType::Pdf))
|
||||
.on_update(|number_input: &NumberInput| ExportDialogMessage::ScaleFactor { factor: number_input.value.unwrap() }.into())
|
||||
.sizing(WidgetSizing::default().min_width(200))
|
||||
.widget_instance(),
|
||||
@@ -149,15 +173,12 @@ impl LayoutHolder for ExportDialogMessageHandler {
|
||||
(ExportBounds::AllArtwork, "All Artwork".to_string(), false),
|
||||
(ExportBounds::Selection, "Selection".to_string(), !self.has_selection),
|
||||
];
|
||||
let artboards = self.artboards.iter().map(|(&layer, name)| (ExportBounds::Artboard(layer), name.to_string(), false)).collect();
|
||||
let choices = [standard_bounds, artboards];
|
||||
// Only a PDF can hold every artboard, each as its own page
|
||||
let all_artboards = (!self.artboards.is_empty()).then(|| (ExportBounds::AllArtboards, "All Artboards".to_string(), self.file_type != FileType::Pdf));
|
||||
let artboards = self.artboards.iter().map(|(layer, name)| (ExportBounds::Artboard(*layer), name.to_string(), false));
|
||||
let choices = [standard_bounds, all_artboards.into_iter().chain(artboards).collect()];
|
||||
|
||||
// Fall back to "All Artwork" if "Selection" was chosen but nothing is currently selected
|
||||
let current_bounds = if !self.has_selection && self.bounds == ExportBounds::Selection {
|
||||
ExportBounds::AllArtwork
|
||||
} else {
|
||||
self.bounds
|
||||
};
|
||||
let current_bounds = self.current_bounds();
|
||||
let index = choices.iter().flatten().position(|(bounds, _, _)| *bounds == current_bounds).unwrap_or(0);
|
||||
|
||||
let mut entries = choices
|
||||
@@ -188,3 +209,44 @@ impl LayoutHolder for ExportDialogMessageHandler {
|
||||
Layout(vec![LayoutGroup::row(export_type), LayoutGroup::row(resolution), LayoutGroup::row(export_area)])
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::test_utils::EditorTestUtils;
|
||||
use graphene_std::uuid::NodeId;
|
||||
|
||||
#[test]
|
||||
fn a_pdf_defaults_to_every_artboard_as_a_page() {
|
||||
let editor = EditorTestUtils::create();
|
||||
let portfolio = editor.portfolio_message_handler();
|
||||
let mut dialog = ExportDialogMessageHandler {
|
||||
artboards: vec![(LayerNodeIdentifier::new_unchecked(NodeId(1)), "Artboard".to_string())],
|
||||
has_selection: true,
|
||||
..Default::default()
|
||||
};
|
||||
let send = |dialog: &mut ExportDialogMessageHandler, message: ExportDialogMessage| dialog.process_message(message, &mut VecDeque::new(), ExportDialogMessageContext { portfolio });
|
||||
|
||||
// Bounds left at the default follow the file type between PDF and a single image
|
||||
send(&mut dialog, ExportDialogMessage::FileType { file_type: FileType::Pdf });
|
||||
assert_eq!(dialog.current_bounds(), ExportBounds::AllArtboards);
|
||||
send(&mut dialog, ExportDialogMessage::FileType { file_type: FileType::Png });
|
||||
assert_eq!(dialog.current_bounds(), ExportBounds::AllArtwork);
|
||||
|
||||
// A choice of other bounds stays through a change of file type
|
||||
send(&mut dialog, ExportDialogMessage::ExportBounds { bounds: ExportBounds::Selection });
|
||||
send(&mut dialog, ExportDialogMessage::FileType { file_type: FileType::Pdf });
|
||||
assert_eq!(dialog.current_bounds(), ExportBounds::Selection);
|
||||
|
||||
// Even a choice of the bounds another file type defaults to
|
||||
send(&mut dialog, ExportDialogMessage::ExportBounds { bounds: ExportBounds::AllArtwork });
|
||||
send(&mut dialog, ExportDialogMessage::FileType { file_type: FileType::Png });
|
||||
send(&mut dialog, ExportDialogMessage::FileType { file_type: FileType::Pdf });
|
||||
assert_eq!(dialog.current_bounds(), ExportBounds::AllArtwork);
|
||||
|
||||
// Without artboards, a PDF falls back to one page of all the artwork
|
||||
send(&mut dialog, ExportDialogMessage::ExportBounds { bounds: ExportBounds::AllArtboards });
|
||||
dialog.artboards.clear();
|
||||
assert_eq!(dialog.current_bounds(), ExportBounds::AllArtwork);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
mod dialog_message;
|
||||
mod dialog_message_handler;
|
||||
|
||||
pub mod document_setup_dialog;
|
||||
pub mod export_dialog;
|
||||
pub mod new_document_dialog;
|
||||
pub mod preferences_dialog;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
use crate::messages::prelude::*;
|
||||
use graphene_std::units::TypedLength;
|
||||
|
||||
#[impl_message(Message, DialogMessage, NewDocumentDialog)]
|
||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum NewDocumentDialogMessage {
|
||||
Name { name: String },
|
||||
Infinite { infinite: bool },
|
||||
DimensionsX { width: f64 },
|
||||
DimensionsY { height: f64 },
|
||||
DimensionsX { width: TypedLength },
|
||||
DimensionsY { height: TypedLength },
|
||||
Resolution { pixels_per_inch: f64 },
|
||||
|
||||
Submit,
|
||||
}
|
||||
Loaded 100 of 335 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user