|
- #include <iostream>
- #include <algorithm>
- #include <vector>
-
- #include "nds.h"
-
- void test_getMeshId()
- {
- struct Point_Mesh_struct
- {
- double x;
- double y;
- nds::MeshId id;
- };
-
- std::vector<Point_Mesh_struct> pms = {
- {119.964231568282, 30.54379108113477, 20134317},
- {112.51651927239463, 0.001349130375817211, 17825792},
- {121.4470908, 31.323812150000002, 20169495}
- };
-
- for (int i = 0; i < (int)pms.size(); i++) {
- auto pm = pms[i];
- auto meshid = nds::getMeshId(pm.x, pm.y, 13);
- std::cout << "test_getMeshId: " << meshid << ", " << pm.id;
- if (meshid == pm.id)
- {
- std::cout << " PASSED" << std::endl;
- }
- else
- {
- std::cout << " FAILED" << std::endl;
- }
- }
- }
-
- void test_meshid_rect()
- {
- struct Rect_Mesh_Struct
- {
- RectD rct;
- std::vector<nds::MeshId> meshids;
- };
-
- auto mesh_vector_equal = [&](std::vector<nds::MeshId> left, std::vector<nds::MeshId> right) {
- std::sort(left.begin(), left.end());
- std::sort(right.begin(), right.end());
-
- if (left.size() == right.size()) {
- auto first1 = left.begin();
- auto last1 = left.end();
- auto first2 = right.begin();
- for (; first1 != last1; ++first1, ++first2)
- if (*first1 != *first2)
- return false;
-
- return true;
- }
-
- return false;
- };
-
- std::vector<Rect_Mesh_Struct> rms = {
- //
- {{116.286747, 116.28884, 39.997884, 39.99994}, {20596464}},
- {{-4.4869520831561607, -4.3973922381416495, -0.01, 0.01},
- {89457925, 89457936, 89457937, 89457940, 89457941, 134197167, 134197178, 134197179,
- 134197182, 134197183}},
- //
- };
-
- for (int i = 0; i < (int)rms.size(); i++) {
- auto rm = rms[i];
- std::vector<nds::MeshId> meshids = nds::getMeshIdInRect(rm.rct, 13);
- if (!mesh_vector_equal(meshids, rm.meshids))
- {
- std::cout << "test index: " << i << std::endl;
- }
- }
- int test = 0;
- }
-
- int main()
- {
- test_getMeshId();
- test_meshid_rect();
-
- return 0;
- }
|