Skip to content

Commit 88b5dfa

Browse files
committed
validate mask_scale unconditionally
Remove the mask_mode != Off gate from mask_scale validation so all config values are range-checked regardless of current mask mode, consistent with the unconditional mask_aspect_ratio validation. Updated both docstrings and tests to match.
1 parent 46be846 commit 88b5dfa

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

crates/mujou-pipeline/src/types.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl fmt::Display for StartPointStrategy {
301301
/// Fields are currently public with no construction-time validation.
302302
/// A validated constructor (`try_new`) or builder should be added to
303303
/// enforce invariants such as `blur_sigma > 0`, `canny_low <= canny_high`,
304-
/// `canny_low >= 1.0`, `mask_scale in [0.01, 1.5] when mask is enabled`, and
304+
/// `canny_low >= 1.0`, `mask_scale in [0.01, 1.5]`, and
305305
/// `simplify_tolerance >= 0.0`.
306306
/// Invalid values would return [`PipelineError::InvalidConfig`].
307307
/// See [open-questions: PipelineConfig validation](https://github.com/altendky/mujou/pull/2#discussion_r2778003093).
@@ -484,7 +484,7 @@ impl PipelineConfig {
484484
/// - `canny_high <= canny_max`
485485
/// - `canny_max <= edge::max_gradient_magnitude()`
486486
/// - `simplify_tolerance >= 0`
487-
/// - `mask_scale` in `[0.01, 1.5]` when `mask_mode` is not `Off` (unconstrained when `Off`)
487+
/// - `mask_scale` in `[0.01, 1.5]`
488488
/// - `mask_aspect_ratio` in `[1.0, 4.0]`
489489
/// - `working_resolution > 0`
490490
/// - `mst_neighbours > 0`
@@ -532,9 +532,9 @@ impl PipelineConfig {
532532
self.simplify_tolerance,
533533
)));
534534
}
535-
if self.mask_mode != MaskMode::Off && !(0.01..=1.5).contains(&self.mask_scale) {
535+
if !(0.01..=1.5).contains(&self.mask_scale) {
536536
return Err(PipelineError::InvalidConfig(format!(
537-
"mask_scale must be in [0.01, 1.5] when mask is enabled, got {}",
537+
"mask_scale must be in [0.01, 1.5], got {}",
538538
self.mask_scale,
539539
)));
540540
}
@@ -1243,27 +1243,25 @@ mod tests {
12431243
}
12441244

12451245
#[test]
1246-
fn validate_accepts_mask_scale_zero_when_off() {
1246+
fn validate_rejects_mask_scale_below_minimum() {
12471247
let config = PipelineConfig {
1248-
mask_mode: MaskMode::Off,
12491248
mask_scale: 0.0,
12501249
..PipelineConfig::default()
12511250
};
1252-
assert!(config.validate().is_ok());
1251+
let err = config.validate().unwrap_err();
1252+
assert!(
1253+
matches!(err, PipelineError::InvalidConfig(ref s) if s.contains("mask_scale")),
1254+
"expected InvalidConfig about mask_scale, got {err:?}",
1255+
);
12531256
}
12541257

12551258
#[test]
1256-
fn validate_rejects_mask_scale_below_minimum_when_enabled() {
1259+
fn validate_accepts_mask_scale_minimum() {
12571260
let config = PipelineConfig {
1258-
mask_mode: MaskMode::Circle,
1259-
mask_scale: 0.0,
1261+
mask_scale: 0.01,
12601262
..PipelineConfig::default()
12611263
};
1262-
let err = config.validate().unwrap_err();
1263-
assert!(
1264-
matches!(err, PipelineError::InvalidConfig(ref s) if s.contains("mask_scale")),
1265-
"expected InvalidConfig about mask_scale, got {err:?}",
1266-
);
1264+
assert!(config.validate().is_ok());
12671265
}
12681266

12691267
#[test]

0 commit comments

Comments
 (0)