You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.cpp 2.2 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include "nds.h"
  5. void test_getMeshId()
  6. {
  7. struct Point_Mesh_struct
  8. {
  9. double x;
  10. double y;
  11. nds::MeshId id;
  12. };
  13. std::vector<Point_Mesh_struct> pms = {
  14. {119.964231568282, 30.54379108113477, 20134317},
  15. {112.51651927239463, 0.001349130375817211, 17825792},
  16. {121.4470908, 31.323812150000002, 20169495}
  17. };
  18. for (int i = 0; i < (int)pms.size(); i++) {
  19. auto pm = pms[i];
  20. auto meshid = nds::getMeshId(pm.x, pm.y, 13);
  21. std::cout << "test_getMeshId: " << meshid << ", " << pm.id;
  22. if (meshid == pm.id)
  23. {
  24. std::cout << " PASSED" << std::endl;
  25. }
  26. else
  27. {
  28. std::cout << " FAILED" << std::endl;
  29. }
  30. }
  31. }
  32. void test_meshid_rect()
  33. {
  34. struct Rect_Mesh_Struct
  35. {
  36. RectD rct;
  37. std::vector<nds::MeshId> meshids;
  38. };
  39. auto mesh_vector_equal = [&](std::vector<nds::MeshId> left, std::vector<nds::MeshId> right) {
  40. std::sort(left.begin(), left.end());
  41. std::sort(right.begin(), right.end());
  42. if (left.size() == right.size()) {
  43. auto first1 = left.begin();
  44. auto last1 = left.end();
  45. auto first2 = right.begin();
  46. for (; first1 != last1; ++first1, ++first2)
  47. if (*first1 != *first2)
  48. return false;
  49. return true;
  50. }
  51. return false;
  52. };
  53. std::vector<Rect_Mesh_Struct> rms = {
  54. //
  55. {{116.286747, 116.28884, 39.997884, 39.99994}, {20596464}},
  56. {{-4.4869520831561607, -4.3973922381416495, -0.01, 0.01},
  57. {89457925, 89457936, 89457937, 89457940, 89457941, 134197167, 134197178, 134197179,
  58. 134197182, 134197183}},
  59. //
  60. };
  61. for (int i = 0; i < (int)rms.size(); i++) {
  62. auto rm = rms[i];
  63. std::vector<nds::MeshId> meshids = nds::getMeshIdInRect(rm.rct, 13);
  64. if (!mesh_vector_equal(meshids, rm.meshids))
  65. {
  66. std::cout << "test index: " << i << std::endl;
  67. }
  68. }
  69. int test = 0;
  70. }
  71. int main()
  72. {
  73. test_getMeshId();
  74. test_meshid_rect();
  75. return 0;
  76. }