From 925701a1cea5fb38304da2cf7e06d16f34fdc42e Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 25 Oct 2026 04:04:52 +0100 Subject: [PATCH] ScalingSettings::MinPartiality: validate the argument, not the value it replaces Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu (cherry picked from commit df5f2ae22f979a5569f4d569fe2a8cdd5999d242) --- common/ScalingSettings.cpp | 2 +- tests/MergeScaleTest.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/common/ScalingSettings.cpp b/common/ScalingSettings.cpp index 2016afba5..8b70c6ac9 100644 --- a/common/ScalingSettings.cpp +++ b/common/ScalingSettings.cpp @@ -90,7 +90,7 @@ std::optional ScalingSettings::GetRotationWedgeForScaling() const { } ScalingSettings &ScalingSettings::MinPartiality(double input) { - if (min_partiality < 0.0 || min_partiality > 1.0) + if (!(input >= 0.0 && input <= 1.0)) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Min partiality must be between 0 and 1"); min_partiality = input; return *this; diff --git a/tests/MergeScaleTest.cpp b/tests/MergeScaleTest.cpp index 0d42c77aa..c2c930911 100644 --- a/tests/MergeScaleTest.cpp +++ b/tests/MergeScaleTest.cpp @@ -1143,3 +1143,12 @@ TEST_CASE("MergeOnTheFly_CaptureTermDownweightsPartials") { CHECK(with < without); CHECK(with < 1.08f); } + +// The setter checks the value it is given, not the one it replaces. +TEST_CASE("ScalingSettings_MinPartialityRange") { + ScalingSettings s; + CHECK_THROWS(s.MinPartiality(1.5)); + CHECK_THROWS(s.MinPartiality(-0.1)); + CHECK_NOTHROW(s.MinPartiality(0.5)); + CHECK(s.GetMinPartiality() == 0.5); +}