Enforce strictly increasing flow compensation factors

Added a check to ensure that flow compensation factors in SmallAreaInfillFlowCompensator strictly increase with extrusion length, throwing an exception if this condition is not met. This improves input validation and prevents invalid compensation models.
This commit is contained in:
Ian Bassi 2025-12-23 09:47:22 -03:00
parent 0049fd7554
commit e731bfffa8

View file

@ -53,7 +53,7 @@ SmallAreaInfillFlowCompensator::SmallAreaInfillFlowCompensator(const Slic3r::GCo
}
}
for (int i = 0; i < eLengths.size(); i++) {
for (size_t i = 0; i < eLengths.size(); i++) {
if (i == 0) {
if (!nearly_equal(eLengths[i], 0.0)) {
throw Slic3r::InvalidArgument("First extrusion length for small area infill compensation model must be 0");
@ -68,6 +68,12 @@ SmallAreaInfillFlowCompensator::SmallAreaInfillFlowCompensator(const Slic3r::GCo
}
}
for (size_t i = 1; i < flowComps.size(); ++i) {
if (flowComps[i] <= flowComps[i - 1]) {
throw Slic3r::InvalidArgument("Flow compensation factors must strictly increase with extrusion length");
}
}
if (!flowComps.empty() && !nearly_equal(flowComps.back(), 1.0)) {
throw Slic3r::InvalidArgument("Final compensation factor for small area infill flow compensation model must be 1.0");
}