mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 02:36:54 +01:00
linesweeper: visualize_op draws its inputs with the even-odd fill rule
The example's binary_op call uses FillRule::EvenOdd, but it drew the two input paths without a fill-rule attribute, so SVG viewers filled them with the nonzero default. A path with a hole wound the same way as its outer contour was drawn solid while the operation treated the hole as empty. The input paths now carry fill-rule="evenodd", taken from the rule the operation uses. scripts/test-pdf-backends.sh runs the example's tests, and README.craft.md, SOURCE.json and NOTICE record the change.
This commit is contained in:
1 parent
f211604aad
commit
f94872456a
5 files changed
+87
-38
No files matched your search
@@ -218,10 +218,10 @@ applications retain their own document-font selection and licensing policy.
|
||||
linesweeper
|
||||
|
||||
linesweeper 0.5.0 (https://crates.io/crates/linesweeper/0.5.0), MIT OR Apache-2.0, is stored in
|
||||
vendor/linesweeper with its upstream license files and no file changed. Its manifest names Joe Neeman
|
||||
vendor/linesweeper with its upstream license files and one local patch. Its manifest names Joe Neeman
|
||||
as author, and its LICENSE-MIT reads "Copyright (c) 2018 Raph Levien". See
|
||||
vendor/linesweeper/README.craft.md and vendor/linesweeper/SOURCE.json for provenance and the files
|
||||
left out.
|
||||
vendor/linesweeper/README.craft.md and vendor/linesweeper/SOURCE.json for provenance, the local
|
||||
change and the files left out.
|
||||
|
||||
Platform lifecycle source provenance
|
||||
|
||||
|
||||
@@ -19,3 +19,4 @@ cargo test --manifest-path "$test_root/hayro-syntax/Cargo.toml" --lib --no-defau
|
||||
cp -R "$root/vendor/linesweeper" "$test_root/linesweeper"
|
||||
cargo test --manifest-path "$test_root/linesweeper/Cargo.toml" --locked --lib --test regression
|
||||
cargo test --manifest-path "$test_root/linesweeper/Cargo.toml" --locked --doc
|
||||
cargo test --manifest-path "$test_root/linesweeper/Cargo.toml" --locked --example visualize_op
|
||||
Vendored
+22
-11
@@ -1,15 +1,25 @@
|
||||
# Local linesweeper 0.5.0 copy
|
||||
|
||||
This is the crates.io linesweeper 0.5.0 package (MIT OR Apache-2.0) with some files left out and no
|
||||
file changed. `.cargo_vcs_info.json` names the commit it was packaged from,
|
||||
This is the crates.io linesweeper 0.5.0 package (MIT OR Apache-2.0) with some files left out and the
|
||||
changes listed under Local changes. `.cargo_vcs_info.json` names the commit it was packaged from,
|
||||
`824b0791a750f7b27b8edcbb6c6244d0e629875e`. That commit is not in the GitHub repository the manifest
|
||||
names, which is archived; its README says development moved off GitHub.
|
||||
|
||||
Every file here except this one and `SOURCE.json` is byte for byte the file in the `.crate` archive.
|
||||
`SOURCE.json` records the hash of the `.crate` download (`source_archive_sha256`) and, for every file
|
||||
kept, the hash in the package (`source_sha256`) and the hash here (`sha256`). `upstream_repository` is
|
||||
null because no public repository this copy can name holds `upstream_revision`. `local_patches` is
|
||||
empty.
|
||||
Every file here except this one, `SOURCE.json` and the files under Local changes is byte for byte the
|
||||
file in the `.crate` archive. `SOURCE.json` records the hash of the `.crate` download
|
||||
(`source_archive_sha256`) and, for every file kept, the hash in the package (`source_sha256`) and the
|
||||
hash here (`sha256`). `upstream_repository` is null because no public repository this copy can name
|
||||
holds `upstream_revision`. `local_patches` describes each local change.
|
||||
|
||||
## Local changes
|
||||
|
||||
| Change | Code comment label | Touches | Tests |
|
||||
|---|---|---|---|
|
||||
| The `visualize_op` example draws its two input paths with `fill-rule="evenodd"`, the fill rule its operation uses | `Craft patch (example fill rule)` | `examples/visualize_op.rs` | `inputs_are_drawn_with_the_operation_fill_rule`, `svg_fill_rule_names` |
|
||||
|
||||
Every change here updates this table and `SOURCE.json` in the same commit. To take a new linesweeper
|
||||
release, unpack the crates.io package, carry these changes over, regenerate `SOURCE.json`, and run the
|
||||
tests below.
|
||||
|
||||
`omitted_files` lists the 43 files of the package left out here, with their hashes:
|
||||
|
||||
@@ -36,14 +46,15 @@ linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "<rev>" }
|
||||
|
||||
## Tests
|
||||
|
||||
`scripts/test-pdf-backends.sh` runs the package's unit, regression and doc tests. The `craft-prepress`
|
||||
tests with the `flatten` feature run against this copy. `pdf.yml`'s path filter does not list this
|
||||
directory, so a pull request that changes only files here does not start `pdf.yml`. Run the tests from
|
||||
this directory:
|
||||
`scripts/test-pdf-backends.sh` runs the package's unit, regression and doc tests and the tests in the
|
||||
`visualize_op` example. The `craft-prepress` tests with the `flatten` feature run against this copy.
|
||||
`pdf.yml`'s path filter does not list this directory, so a pull request that changes only files here
|
||||
does not start `pdf.yml`. Run the tests from this directory:
|
||||
|
||||
```sh
|
||||
cargo test --locked --lib --test regression
|
||||
cargo test --locked --doc
|
||||
cargo test --locked --example visualize_op
|
||||
```
|
||||
|
||||
`Cargo.toml` leaves out the `kompari`, `linesweeper_util` and `path-bool` dev-dependencies, which
|
||||
|
||||
Vendored
+4
-2
@@ -7,7 +7,9 @@
|
||||
"upstream_repository": null,
|
||||
"upstream_revision": "824b0791a750f7b27b8edcbb6c6244d0e629875e",
|
||||
"upstream_directory": "",
|
||||
"local_patches": [],
|
||||
"local_patches": [
|
||||
"The `visualize_op` example draws its two input paths with `fill-rule=\"evenodd\"`. Its `binary_op` call uses `FillRule::EvenOdd`, and the SVG default fill rule is nonzero."
|
||||
],
|
||||
"files": [
|
||||
{ "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" },
|
||||
{ "path": ".gitignore", "source_sha256": "88b59092499ae05234330eb7d0b01e953e969caf05261530e3765eef02536cf0", "source_git_blob": null, "sha256": "88b59092499ae05234330eb7d0b01e953e969caf05261530e3765eef02536cf0" },
|
||||
@@ -25,7 +27,7 @@
|
||||
{ "path": "examples/boolean_op.rs", "source_sha256": "3b38a1ccda7e736cce4b191a3a45ab4824c4c365190e3eb637b2fb39b5996c9f", "source_git_blob": null, "sha256": "3b38a1ccda7e736cce4b191a3a45ab4824c4c365190e3eb637b2fb39b5996c9f" },
|
||||
{ "path": "examples/bus.rs", "source_sha256": "e206a08be73899f564188052c8ecc15526b54606e52ee2935a64ce6b5723da33", "source_git_blob": null, "sha256": "e206a08be73899f564188052c8ecc15526b54606e52ee2935a64ce6b5723da33" },
|
||||
{ "path": "examples/curve_metrics.rs", "source_sha256": "0db6a5327fd2119a03a9a66624fea3e04b6bbb519655667ad30487aee6c787d2", "source_git_blob": null, "sha256": "0db6a5327fd2119a03a9a66624fea3e04b6bbb519655667ad30487aee6c787d2" },
|
||||
{ "path": "examples/visualize_op.rs", "source_sha256": "a5210ed389ceb1e9c43b952b992e29e65065d129d2b2f4be62fffc747376bf79", "source_git_blob": null, "sha256": "a5210ed389ceb1e9c43b952b992e29e65065d129d2b2f4be62fffc747376bf79" },
|
||||
{ "path": "examples/visualize_op.rs", "source_sha256": "a5210ed389ceb1e9c43b952b992e29e65065d129d2b2f4be62fffc747376bf79", "source_git_blob": null, "sha256": "e9343f0ab4c51796a054b0f99eb5f961365d26bcb2f62fe3c0ddaf614bbb7702" },
|
||||
{ "path": "examples/winding-numbers.rs", "source_sha256": "4a756c908564703b165257001e73d2f7235476cd536580091f3a7a70d2eab242", "source_git_blob": null, "sha256": "4a756c908564703b165257001e73d2f7235476cd536580091f3a7a70d2eab242" },
|
||||
{ "path": "proptest-regressions/sweep/sweep_line.txt", "source_sha256": "f5311edf1c0c4d1574bb7b24ed1d1c66106d9949214014d0a8479f685938dc98", "source_git_blob": null, "sha256": "f5311edf1c0c4d1574bb7b24ed1d1c66106d9949214014d0a8479f685938dc98" },
|
||||
{ "path": "proptest-regressions/sweep/weak_ordering.txt", "source_sha256": "b5b183ab470399c15246457d8a1a35cafb49fee120d6777dfdd563bfdbadda52", "source_git_blob": null, "sha256": "b5b183ab470399c15246457d8a1a35cafb49fee120d6777dfdd563bfdbadda52" },
|
||||
|
||||
+57
-22
@@ -10,6 +10,8 @@ use linesweeper::{
|
||||
topology::{Contours, Topology},
|
||||
};
|
||||
|
||||
const FILL_RULE: FillRule = FillRule::EvenOdd;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Cli {
|
||||
#[arg(long)]
|
||||
@@ -45,7 +47,7 @@ pub fn main() -> anyhow::Result<()> {
|
||||
let shape_b = BezPath::from_svg(shape_b)?;
|
||||
|
||||
let eps = 1e-5;
|
||||
let contours = binary_op(&shape_a, &shape_b, FillRule::EvenOdd, op)?;
|
||||
let contours = binary_op(&shape_a, &shape_b, FILL_RULE, op)?;
|
||||
let top = Topology::from_paths_binary(&shape_a, &shape_b, eps)?;
|
||||
let bbox = top.bounding_box();
|
||||
let min_x = bbox.min_x();
|
||||
@@ -64,27 +66,7 @@ pub fn main() -> anyhow::Result<()> {
|
||||
|
||||
// Draw the original document.
|
||||
for (c, color) in [(&shape_a, "green"), (&shape_b, "blue")] {
|
||||
let mut data = svg::node::element::path::Data::new();
|
||||
for el in c {
|
||||
let p = |point: kurbo::Point| (point.x, point.y);
|
||||
data = match el {
|
||||
kurbo::PathEl::MoveTo(p0) => data.move_to(p(p0)),
|
||||
kurbo::PathEl::LineTo(p0) => data.line_to(p(p0)),
|
||||
kurbo::PathEl::QuadTo(p0, p1) => data.quadratic_curve_to((p(p0), p(p1))),
|
||||
kurbo::PathEl::CurveTo(p0, p1, p2) => data.cubic_curve_to((p(p0), p(p1), p(p2))),
|
||||
kurbo::PathEl::ClosePath => data.close(),
|
||||
};
|
||||
}
|
||||
|
||||
let path = svg::node::element::Path::new()
|
||||
.set("stroke", "black")
|
||||
.set("stroke-width", stroke_width)
|
||||
.set("stroke-linecap", "round")
|
||||
.set("stroke-linejoin", "round")
|
||||
.set("opacity", 0.5)
|
||||
.set("fill", color)
|
||||
.set("d", data);
|
||||
document = document.add(path);
|
||||
document = document.add(input_path(c, color, stroke_width));
|
||||
}
|
||||
|
||||
document = add_op(document, &contours, one_width, stroke_width);
|
||||
@@ -94,6 +76,38 @@ pub fn main() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Craft patch (example fill rule): the inputs are drawn with the fill rule the operation uses.
|
||||
fn svg_fill_rule(fill_rule: FillRule) -> &'static str {
|
||||
match fill_rule {
|
||||
FillRule::EvenOdd => "evenodd",
|
||||
FillRule::NonZero => "nonzero",
|
||||
}
|
||||
}
|
||||
|
||||
fn input_path(shape: &BezPath, color: &str, stroke_width: f64) -> svg::node::element::Path {
|
||||
let mut data = svg::node::element::path::Data::new();
|
||||
for el in shape {
|
||||
let p = |point: kurbo::Point| (point.x, point.y);
|
||||
data = match el {
|
||||
kurbo::PathEl::MoveTo(p0) => data.move_to(p(p0)),
|
||||
kurbo::PathEl::LineTo(p0) => data.line_to(p(p0)),
|
||||
kurbo::PathEl::QuadTo(p0, p1) => data.quadratic_curve_to((p(p0), p(p1))),
|
||||
kurbo::PathEl::CurveTo(p0, p1, p2) => data.cubic_curve_to((p(p0), p(p1), p(p2))),
|
||||
kurbo::PathEl::ClosePath => data.close(),
|
||||
};
|
||||
}
|
||||
|
||||
svg::node::element::Path::new()
|
||||
.set("stroke", "black")
|
||||
.set("stroke-width", stroke_width)
|
||||
.set("stroke-linecap", "round")
|
||||
.set("stroke-linejoin", "round")
|
||||
.set("opacity", 0.5)
|
||||
.set("fill", color)
|
||||
.set("fill-rule", svg_fill_rule(FILL_RULE))
|
||||
.set("d", data)
|
||||
}
|
||||
|
||||
fn add_op(mut doc: Document, contours: &Contours, x_off: f64, stroke_width: f64) -> Document {
|
||||
for group in contours.grouped() {
|
||||
let mut data = svg::node::element::path::Data::new();
|
||||
@@ -128,3 +142,24 @@ fn add_op(mut doc: Document, contours: &Contours, x_off: f64, stroke_width: f64)
|
||||
}
|
||||
doc
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn inputs_are_drawn_with_the_operation_fill_rule() {
|
||||
// Two nested squares with the same orientation. Even-odd leaves the inner square
|
||||
// empty, and nonzero fills it.
|
||||
let nested = BezPath::from_svg("M0,0 L10,0 L10,10 L0,10 Z M2,2 L8,2 L8,8 L2,8 Z").unwrap();
|
||||
let drawn = input_path(&nested, "green", 0.1).to_string();
|
||||
assert_eq!(FILL_RULE, FillRule::EvenOdd);
|
||||
assert!(drawn.contains(r#"fill-rule="evenodd""#), "{drawn}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn svg_fill_rule_names() {
|
||||
assert_eq!(svg_fill_rule(FillRule::EvenOdd), "evenodd");
|
||||
assert_eq!(svg_fill_rule(FillRule::NonZero), "nonzero");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user