#include #include #include #include #define FRC_NO_ICU 1 #include "FRC.h" #include "path.h" #include "rnn.h" namespace path { static Eigen::Vector2f cart2pol(Eigen::Vector2f c) { return Eigen::Vector2f( std::sqrt(c.array().square().sum()), std::atan2(c[0], c[1]) ); } static Eigen::Vector2f pol2cart(Eigen::Vector2f p) { return Eigen::Vector2f( p[0] * std::sin(p[1]), p[0] * std::cos(p[1]) ); } float atan2(Eigen::Vector2f c) { return std::atan2(c[0],c[1]); } float rad(Eigen::Vector2f c) { return std::sqrt(c.array().square().sum()); } Eigen::Vector2f norm(Eigen::Vector2f v1, Eigen::Vector2f v2, float d) { return Eigen::Vector2f((v1[0]+v2[0])/d, v1[1]); } constexpr static unsigned char code(char c) { return static_cast(c)-'a'; } spacialRepresentation::spacialRepresentation(const sKeymap& k) : points(Eigen::Matrix::Zero()) { auto s = k.exportKeys(); for (int i = 0; i != static_cast(s.size()); ++i) { if (s[i] != code(' ')) { short c = s[i]; // std::cout<<"s: "< keymapToSpace(const sKeymap& k) { return std::make_unique(k); } std::vector wordToPath(spacialRepresentation * const k, const std::string& word) { // std::clog< out; size_t ci=1; Eigen::Vector2f cpos(k->points.col(word[0]-'a')), cvel(0,0), tpos(k->points.col(word[1]-'a')); const static float maxvel{.4}, accel{.18}, thresh{.25}; // std::clog<<"index: "<closestKeyTo(cpos); curr[closestKey] = 1; curr[26] = rad(cpos - k->points.col(closestKey)); auto caccel = Eigen::Vector2f( std::min(accel, tdelta[0]), tdelta[1] ); curr.array().segment<2>(28) = caccel.array(); cvel = norm(caccel, cvel, (maxvel+accel)/maxvel); curr[27] = cvel[0]; out.push_back(curr); cpos += pol2cart(cvel); if (cpos[0] != cpos[0] || cpos[1] != cpos[1]) { std::cerr< 60 * ci) { // std::clog<<"index: "<= word.size()) break; tpos = k->points.col(word[ci]-'a'); // std::clog<<"index: "< uniform(0.0, cats.sum()); float choose = uniform(r); for (int stop = 0; stop != cats.size(); ++stop) { choose -= cats[stop]; if (choose <= 0) { return stop; } } //Silence a warning return cats.size()-1; } std::string wordFromPath(const std::vector& path, const std::vector& nodes, pcg32_k64& r) { std::string out; auto alphabet = "abcdefghijklmnopqrstuvwxyz"; for (size_t i = 0; i != path.size(); ++i) { if (chooseCategorical(nodes[i], r) == 0) { out.append(1, alphabet[chooseCategorical(path[i].head<26>(), r)]); } } return out; } }