mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-31 15:48:33 +00:00
Follow-up to #2687: an even sample count keeps the Vegas midpoint
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5802cdc6a4
commit
4b7767401b
2 files changed
+6
-3
No files matched your search
@@ -388,10 +388,12 @@ pub(super) fn vegas(ctx: &EffectCtx, mut b: Buf) -> Buf {
|
||||
}
|
||||
|
||||
/// Sub-samples per Vegas segment: at least 12 (opacity ramp), more for long segments so each straight piece stays
|
||||
/// short compared with the stroke width and the segment follows rounded corners smoothly.
|
||||
/// short compared with the stroke width and the segment follows rounded corners smoothly. Always even.
|
||||
pub(super) fn vegas_substeps(each: f64, width: f64) -> usize {
|
||||
let step = width.max(2.0);
|
||||
((each / step).ceil().max(12.0) as usize).min(512)
|
||||
let n = ((each / step).ceil().max(12.0) as usize).min(512);
|
||||
// Even, so the segment's midpoint (0.5) is always one of the samples.
|
||||
n + (n & 1)
|
||||
}
|
||||
|
||||
fn vegas_plan(ctx: &EffectCtx, b: &Buf) -> PaintPlan {
|
||||
|
||||
@@ -401,7 +401,8 @@ fn vegas_long_segments_are_sampled_finely() {
|
||||
// A short segment keeps the 12 samples; a long one gets more so it bends smoothly round rounded corners.
|
||||
assert_eq!(super::paths::vegas_substeps(10.0, 4.0), 12);
|
||||
let n = super::paths::vegas_substeps(400.0, 4.0);
|
||||
assert!(n > 12, "{n}");
|
||||
assert!(n > 12 && n % 2 == 0, "{n}");
|
||||
assert_eq!(super::paths::vegas_substeps(13.0 * 4.0, 4.0) % 2, 0);
|
||||
assert!(400.0 / n as f64 <= 4.0 + 1e-9);
|
||||
assert_eq!(super::paths::vegas_substeps(1.0e9, 4.0), 512);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user