diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index 40ed372..b21d4f9 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -6702,3 +6702,9 @@ but the final whole-tree format target found 25 recently edited cellular-stage files that were not formatted to the CI-pinned clang-format 19.1.5 style. They are now formatted with that exact version; the repository-wide check passes locally and CI is pending on the formatting-only follow-up. + +CI run 243 found `-Werror,-Wsign-conversion` in the existing cellular-motion +axis clamp, where mixed signed and unsigned conditional expressions selected +their common unsigned type. The clamp now applies signed deltas in explicit +branches and converts only their nonnegative magnitudes. Full run243 checks are +still in progress; the client job failed at this diagnostic before tests ran. diff --git a/src/biology/cellular_motion.cpp b/src/biology/cellular_motion.cpp index d3db037..35249e5 100644 --- a/src/biology/cellular_motion.cpp +++ b/src/biology/cellular_motion.cpp @@ -91,20 +91,22 @@ propose_cellular_motion(CellularArea area, CellularPosition position, std::uint3 cellular_intent_component_limit; const auto max_x = area.width_um - extent_um; const auto max_y = area.height_um - extent_um; - const auto next_x = - static_cast(dx < 0 ? (static_cast(-dx) > position.x_um - ? 0 - : static_cast(position.x_um) + dx) - : (dx > static_cast(max_x - position.x_um) - ? max_x - : static_cast(position.x_um) + dx)); - const auto next_y = - static_cast(dy < 0 ? (static_cast(-dy) > position.y_um - ? 0 - : static_cast(position.y_um) + dy) - : (dy > static_cast(max_y - position.y_um) - ? max_y - : static_cast(position.y_um) + dy)); + const auto clamp_axis = [](std::uint64_t coordinate, std::int64_t delta, + std::uint64_t maximum) noexcept { + if (delta < 0) { + const auto distance = static_cast(-delta); + if (distance > coordinate) + return std::uint64_t{0}; + return coordinate - distance; + } + + const auto distance = static_cast(delta); + if (distance > maximum - coordinate) + return maximum; + return coordinate + distance; + }; + const auto next_x = clamp_axis(position.x_um, dx, max_x); + const auto next_y = clamp_axis(position.y_um, dy, max_y); const auto moved_x = next_x >= position.x_um ? next_x - position.x_um : position.x_um - next_x; const auto moved_y = next_y >= position.y_um ? next_y - position.y_um : position.y_um - next_y; const auto distance = integer_sqrt_ceil(moved_x * moved_x + moved_y * moved_y);