Add phenotype-derived cellular motion proposal
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m58s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (network) (push) Canceled after 6s
Foundation / checks (client) (push) Canceled after 2m14s
Foundation / checks (checks) (push) Canceled after 2m17s

This commit is contained in:
dingo
2026-10-10 21:08:50 -04:00
parent 0b607bae53
commit a97c5f3204
6 changed files with 314 additions and 5 deletions
+97
View File
@@ -0,0 +1,97 @@
#include "evo/biology/cellular_motion.hpp"
#include <cstdio>
#include <source_location>
#include <stdexcept>
#include <string>
namespace {
using namespace evo::biology;
void check(bool value, std::source_location at = std::source_location::current()) {
if (!value)
throw std::runtime_error("cellular motion line " + std::to_string(at.line()));
}
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
MetabolicBudget budget(std::uint32_t speed_um_per_second = 200,
std::uint64_t movement_pj_per_second = 1'000) {
MetabolicBudget result{};
result.phenotype.movement_speed = speed_um_per_second;
result.movement = {movement_pj_per_second};
result.rate_microseconds = 1'000'000;
return result;
}
void movement_proposals() {
const CellularArea area{400, 300};
const CellularPosition start{100, 100};
const auto east = propose_cellular_motion(area, start, 20, {1000, 0}, budget());
CHECK(east && east->position == CellularPosition{110, 100});
CHECK(east->distance_um == 10 && east->movement_cost.value == 50);
const auto partial = propose_cellular_motion(area, start, 20, {500, 0}, budget());
CHECK(partial && partial->position == CellularPosition{105, 100});
CHECK(partial->distance_um == 5 && partial->movement_cost.value == 25);
const auto diagonal = propose_cellular_motion(area, start, 20, {707, 707}, budget());
CHECK(diagonal && diagonal->position == CellularPosition{107, 107});
CHECK(diagonal->distance_um == 10 && diagonal->movement_cost.value == 50);
const auto west = propose_cellular_motion(area, start, 20, {-1000, 0}, budget());
CHECK(west && west->position == CellularPosition{90, 100});
CHECK(west->movement_cost.value == 50);
const auto stopped = propose_cellular_motion(area, start, 20, {0, 0}, budget());
CHECK(stopped && stopped->position == start && stopped->distance_um == 0 &&
stopped->movement_cost.value == 0);
}
void edges_and_invalid_state() {
const auto east_edge = propose_cellular_motion({400, 300}, {370, 100}, 20, {1000, 0}, budget());
CHECK(east_edge && east_edge->position == CellularPosition{380, 100});
CHECK(east_edge->distance_um == 10 && east_edge->movement_cost.value == 50);
const auto pinned = propose_cellular_motion({400, 300}, {380, 100}, 20, {1000, 0}, budget());
CHECK(pinned && pinned->position == CellularPosition{380, 100});
CHECK(pinned->distance_um == 0 && pinned->movement_cost.value == 0);
const auto south_edge = propose_cellular_motion({400, 300}, {100, 1}, 20, {0, -1000}, budget());
CHECK(south_edge && south_edge->position == CellularPosition{100, 0});
CHECK(south_edge->distance_um == 1 && south_edge->movement_cost.value == 5);
CHECK(!propose_cellular_motion({0, 300}, {0, 0}, 20, {}, budget()));
CHECK(!propose_cellular_motion({cellular_motion_axis_limit_um + 1, 300}, {0, 0}, 20, {},
budget()));
CHECK(!propose_cellular_motion({400, 300}, {0, 0}, 0, {}, budget()));
CHECK(!propose_cellular_motion({400, 300}, {390, 0}, 20, {}, budget()));
CHECK(!propose_cellular_motion({400, 300}, {0, 0}, 401, {}, budget()));
CHECK(!propose_cellular_motion({400, 300}, {100, 100}, 20, {1000, 1000}, budget()));
auto wrong_rate_period = budget();
wrong_rate_period.rate_microseconds = 50'000;
CHECK(!propose_cellular_motion({400, 300}, {100, 100}, 20, {}, wrong_rate_period));
// The per-tick speed rounds down by ADR-0099; no phantom sub-micrometre step.
const auto quantized =
propose_cellular_motion({400, 300}, {100, 100}, 20, {1000, 0}, budget(19));
CHECK(quantized && quantized->position == CellularPosition{100, 100});
CHECK(quantized->movement_cost.value == 0);
}
void contact_geometry() {
CHECK(cellular_footprints_contact({0, 0}, 20, {20, 0}, 20)); // Exact edge touch.
CHECK(cellular_footprints_contact({0, 0}, 20, {19, 19}, 20));
CHECK(!cellular_footprints_contact({0, 0}, 20, {21, 0}, 20));
CHECK(!cellular_footprints_contact({0, 0}, 0, {0, 0}, 20));
CHECK(cellular_footprints_contact({1'000'000, 1'000'000}, 20, {1'000'020, 1'000'020}, 20));
}
} // namespace
int main() {
try {
movement_proposals();
edges_and_invalid_state();
contact_geometry();
std::puts("PASS cellular motion: phenotype speed, energy cost, bounds and contact");
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;
}
}