diff --git a/3rdparty/include/Arknights-Tile-Pos/TileCalc.hpp b/3rdparty/include/Arknights-Tile-Pos/TileCalc.hpp index 147d5a7828..83e2c3de1f 100644 --- a/3rdparty/include/Arknights-Tile-Pos/TileCalc.hpp +++ b/3rdparty/include/Arknights-Tile-Pos/TileCalc.hpp @@ -1,13 +1,13 @@ #pragma once +#include +#include #include #include #include -#include -#include -#include #include +#include namespace Map { @@ -27,10 +27,9 @@ namespace Map Tile get_item(int y, int x) const { return tiles[y][x]; } std::vector view; std::string stageId; - std::string code; - std::string levelId; - std::string name; - + std::string code; + std::string levelId; + std::string name; private: int height = 0; int width = 0; @@ -40,9 +39,7 @@ namespace Map { public: TileCalc(int width, int height, const std::string& dir); - bool run(const std::string& code_or_name, bool side, std::vector>& out_pos, - std::vector>& out_tiles) const; - + bool run(const std::string& code_or_name, bool side, std::vector>& out_pos, std::vector>& out_tiles) const; private: int width = 0; int height = 0; @@ -54,7 +51,7 @@ namespace Map bool adapter(double& x, double& y) const; }; - inline void InitMat4x4(cv::Mat& m, double (*num)[4]) + inline void InitMat4x4(cv::Mat& m, double(*num)[4]) { for (int i = 0; i < m.rows; i++) for (int j = 0; j < m.cols; j++) @@ -81,8 +78,10 @@ namespace Map std::vector tmp; tmp.reserve(Level::width); for (const json::value& tile : row.as_array()) { - tmp.emplace_back(Tile { tile.at("heightType").as_integer(), tile.at("buildableType").as_integer(), - tile.get("tileKey", std::string()) }); + tmp.emplace_back(Tile{ + tile.at("heightType").as_integer(), + tile.at("buildableType").as_integer(), + tile.get("tileKey", std::string()) }); } tiles.emplace_back(std::move(tmp)); } @@ -93,20 +92,26 @@ namespace Map TileCalc::width = width; TileCalc::height = height; double ratio = static_cast(height) / width; - double matrixP[4][4] { { ratio / tan(20 * degree), 0, 0, 0 }, - { 0, 1 / tan(20 * degree), 0, 0 }, - { 0, 0, -(1000 + 0.3) / (1000 - 0.3), -(1000 * 0.3 * 2) / (1000 - 0.3) }, - { 0, 0, -1, 0 } }; + double matrixP[4][4]{ + { ratio / tan(20 * degree), 0, 0, 0}, + { 0, 1 / tan(20 * degree), 0, 0}, + { 0, 0, -(1000 + 0.3) / (1000 - 0.3), -(1000 * 0.3 * 2) / (1000 - 0.3)}, + { 0, 0, -1, 0 } + }; InitMat4x4(TileCalc::MatrixP, matrixP); - double matrixX[4][4] { { 1, 0, 0, 0 }, - { 0, cos(30 * degree), -sin(30 * degree), 0 }, - { 0, -sin(30 * degree), -cos(30 * degree), 0 }, - { 0, 0, 0, 1 } }; + double matrixX[4][4]{ + { 1, 0, 0, 0}, + { 0, cos(30 * degree), -sin(30 * degree), 0}, + { 0, -sin(30 * degree), -cos(30 * degree), 0}, + { 0, 0, 0, 1} + }; InitMat4x4(TileCalc::MatrixX, matrixX); - double matrixY[4][4] { { cos(10 * degree), 0, sin(10 * degree), 0 }, - { 0, 1, 0, 0 }, - { -sin(10 * degree), 0, cos(10 * degree), 0 }, - { 0, 0, 0, 1 } }; + double matrixY[4][4]{ + { cos(10 * degree), 0, sin(10 * degree), 0}, + { 0, 1, 0, 0}, + { -sin(10 * degree), 0, cos(10 * degree), 0}, + { 0, 0, 0, 1} + }; InitMat4x4(TileCalc::MatrixY, matrixY); std::ifstream ifs(dir, std::ios::in); if (!ifs.is_open()) { @@ -143,27 +148,23 @@ namespace Map return true; } - inline bool TileCalc::run(const std::string& any_id, bool side, std::vector>& out_pos, - std::vector>& out_tiles) const + inline bool TileCalc::run(const std::string& code_or_name, bool side, std::vector>& out_pos, std::vector>& out_tiles) const { - auto make_lower = [](const std::string& str) -> std::string { - std::string result; - std::transform(str.cbegin(), str.cend(), result.begin(), - [](char c) { return static_cast(std::tolower(c)); }); - return result; - }; - - std::string any_id_lower = make_lower(any_id); for (const Map::Level& level : TileCalc::levels) { - if (make_lower(level.code) != any_id_lower && make_lower(level.name) != any_id_lower && - make_lower(level.levelId) != any_id_lower && make_lower(level.stageId) != any_id_lower) { + if (level.code != code_or_name && + level.name != code_or_name && + level.levelId != code_or_name && + level.stageId != code_or_name) { continue; } auto [x, y, z] = level.view[side ? 1 : 0]; double adapter_y = 0, adapter_z = 0; TileCalc::adapter(adapter_y, adapter_z); - double matrix[4][4] { - { 1, 0, 0, -x }, { 0, 1, 0, -y - adapter_y }, { 0, 0, 1, -z - adapter_z }, { 0, 0, 0, 1 } + double matrix[4][4]{ + { 1, 0, 0, -x}, + { 0, 1, 0, -y - adapter_y}, + { 0, 0, 1, -z - adapter_z}, + { 0, 0, 0, 1} }; auto raw = cv::Mat(cv::Size(4, 4), CV_64F); auto Finall_Matrix = cv::Mat(cv::Size(4, 4), CV_64F); @@ -189,8 +190,7 @@ namespace Map cv::Mat view_point = Finall_Matrix * map_point; view_point = view_point / view_point.at(3, 0); view_point = (view_point + 1) / 2; - tmp_pos[j] = cv::Point2d(view_point.at(0, 0) * TileCalc::width, - (1 - view_point.at(1, 0)) * TileCalc::height); + tmp_pos[j] = cv::Point2d(view_point.at(0, 0) * TileCalc::width, (1 - view_point.at(1, 0)) * TileCalc::height); } out_pos.emplace_back(tmp_pos); out_tiles.emplace_back(tmp_tiles); @@ -199,4 +199,4 @@ namespace Map } return false; } -} // namespace Map +}