Merge #652 (fix/linesweeper-arbitrary-range-overflow) into integration/linesweeper

This commit is contained in:
dotCooCoo committed 2026-11-09 13:43:18 -08:00
commit f665d87e86
3 files changed
+35 -1

No files matched your search

+4
View File
@@ -72,6 +72,9 @@ names, which is archived; its README says development moved off GitHub.
`824b0791a750f7b27b8edcbb6c6244d0e629875e`. That commit is not in the GitHub repository the manifest
names, which is archived; its README says development moved off GitHub.
`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, `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
@@ -97,6 +100,7 @@ Every change here updates this table and `SOURCE.json` in the same commit.
| `Segment::lower` and `Segment::upper` bound a horizontal line by both of its endpoints | `Craft patch (horizontal line bounds)` | `src/geom.rs` | `horizontal_line_bounds_cover_both_endpoints` |
| 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` |
| The `Ish` entry that `CurveOrder::push` inserts between opposite `Left` and `Right` intervals ends where the earlier interval ends, so it has zero height | `Craft patch (zero-height Ish)` | `src/curve/mod.rs` | `opposite_orders_get_a_zero_height_ish` |
| `float_in_range` interpolates as `start * (1 - t) + end * t`, so a range such as `-1e308..1e308` gives a value in the range instead of NaN | `Craft patch (wide float range)` | `src/arbitrary.rs` | `float_in_range_handles_a_range_wider_than_f64_max` |
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
+2
View File
@@ -26,6 +26,7 @@
"Start the `viewBox` in `examples/curve_metrics.rs` at x = -1.5 instead of 0, so the left half of each curve is drawn, and add a test that every curve fits in it."
"End the `Ish` entry that `CurveOrder::push` inserts between opposite `Left` and `Right` intervals at the earlier interval's end, so it has zero height and the new order covers its own interval."
"In `src/curve/mod.rs`, `quadratic_signs` calls the new `balance_quadratic`, which multiplies the coefficients by one power of two when `b * b` or `a * c` would underflow or overflow, keeping every coefficient below `2^1021`. Without it, the discriminant underflows to zero or overflows for very small or very large coefficients: for the cubic with y coordinates `[0, -s, -2s, s]`, `monotonic_cubic_pieces` splits at t = 0.5 when s = 1 but returns one piece that is not monotonic when s = 1e-200 or s = 1e160. `curve::test::quadratic_signs_at_extreme_scales` covers it."
"`float_in_range` interpolates as `start * (1 - t) + end * t` instead of `start + t * (end - start)`, so a range wider than `f64::MAX`, such as `-1e308..1e308`, gives a value in the range instead of NaN."
],
"files": [
{ "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" },
@@ -59,6 +60,7 @@
{ "path": "src/arbitrary.rs", "source_sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750", "source_git_blob": null, "sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750" },
{ "path": "src/curve/line.rs", "source_sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e", "source_git_blob": null, "sha256": "8cc91b25daebcf311b3fd11650a5996057017ea66eba2836ffc3c7742e7b5f0d" },
{ "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "815aafe3b4bfb518fb05298374ced58a7c86349f47bc65506c5d64c25997c81d" },
{ "path": "src/arbitrary.rs", "source_sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750", "source_git_blob": null, "sha256": "437384973710909ec13e9267601580c6b3072fb04795138d9aa1a9ab8eb07176" },
{ "path": "src/curve/line.rs", "source_sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e", "source_git_blob": null, "sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e" },
{ "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "0b1be70901b2bbf0244fccb0a599f0e9615eb30c21758a4d0efda97254bfb059" },
{ "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "00ac2cab19a570aefdd2121d621742f113842b9566e7b7718923b337d9c79005" },
+29 -1
View File
@@ -17,7 +17,9 @@ pub fn float_in_range(
}
let num: u32 = u.arbitrary()?;
let t = num as f64 / u32::MAX as f64;
Ok((start + t * (end - start)).clamp(start, end))
// Craft patch (wide float range): `end - start` overflows for a range wider
// than `f64::MAX`, so the value is interpolated from each end.
Ok((start * (1.0 - t) + end * t).clamp(start, end))
}
fn float(u: &mut Unstructured<'_>) -> Result<f64, arbitrary::Error> {
@@ -132,3 +134,29 @@ pub fn quadratic(size: f64, u: &mut Unstructured<'_>) -> Result<Quadratic, arbit
Ok(Quadratic::new([scale * r1 * r2, -scale * (r1 + r2), scale]))
}
}
// Craft patch (wide float range).
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn float_in_range_handles_a_range_wider_than_f64_max() {
let (start, end) = (-1e308, 1e308);
for bytes in [[0u8; 4], [0x80, 0, 0, 0], [0, 0, 0, 0x80], [0xff; 4]] {
let x = float_in_range(start, end, &mut Unstructured::new(&bytes)).unwrap();
assert!(
x.is_finite() && (start..=end).contains(&x),
"{x} for {bytes:?}"
);
}
assert_eq!(
float_in_range(start, end, &mut Unstructured::new(&[0u8; 4])).unwrap(),
start
);
assert_eq!(
float_in_range(start, end, &mut Unstructured::new(&[0xff; 4])).unwrap(),
end
);
}
}