mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 21:13:35 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
106
generator/generator_tests/triangles_tree_coding_test.cpp
Normal file
106
generator/generator_tests/triangles_tree_coding_test.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "testing/testing.hpp"
|
||||
|
||||
#include "generator/tesselator.hpp"
|
||||
|
||||
#include "coding/geometry_coding.hpp"
|
||||
#include "coding/point_coding.hpp"
|
||||
#include "coding/reader.hpp"
|
||||
#include "coding/writer.hpp"
|
||||
|
||||
#include "geometry/mercator.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
using P = m2::PointD;
|
||||
|
||||
bool IsEqual(P const & p1, P const & p2)
|
||||
{
|
||||
return p1.EqualDxDy(p2, kMwmPointAccuracy);
|
||||
}
|
||||
|
||||
bool FindTriangle(serial::OutPointsT const & test, P arr[])
|
||||
{
|
||||
size_t const count = test.size();
|
||||
for (size_t i = 0; i < count; i += 3)
|
||||
{
|
||||
for (int base = 0; base < 3; ++base)
|
||||
{
|
||||
if (IsEqual(test[i], arr[base])
|
||||
&& IsEqual(test[i + 1], arr[(base + 1) % 3])
|
||||
&& IsEqual(test[i + 2], arr[(base + 2) % 3]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CompareTriangles(serial::OutPointsT const & test, P arrP[], int arrT[][3], size_t count)
|
||||
{
|
||||
TEST_EQUAL(test.size(), 3 * count, (test));
|
||||
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
P trg[] = {arrP[arrT[i][0]], arrP[arrT[i][1]], arrP[arrT[i][2]]};
|
||||
TEST(FindTriangle(test, trg), ("Triangles:", test, " Etalon:", trg[0], trg[1], trg[2]));
|
||||
}
|
||||
}
|
||||
|
||||
void TestTrianglesCoding(P arrP[], size_t countP, int arrT[][3], size_t countT)
|
||||
{
|
||||
tesselator::TrianglesInfo info;
|
||||
info.AssignPoints(arrP, arrP + countP);
|
||||
|
||||
info.Reserve(countT);
|
||||
|
||||
for (size_t i = 0; i < countT; ++i)
|
||||
info.Add(arrT[i][0], arrT[i][1], arrT[i][2]);
|
||||
|
||||
serial::GeometryCodingParams cp;
|
||||
|
||||
serial::TrianglesChainSaver saver(cp);
|
||||
tesselator::PointsInfo points;
|
||||
|
||||
m2::PointU (*D2U)(m2::PointD const &, uint8_t) = &PointDToPointU;
|
||||
info.GetPointsInfo(saver.GetBasePoint(), saver.GetMaxPoint(),
|
||||
std::bind(D2U, std::placeholders::_1, cp.GetCoordBits()), points);
|
||||
|
||||
info.ProcessPortions(points, saver);
|
||||
|
||||
std::vector<char> buffer;
|
||||
MemWriter<std::vector<char>> writer(buffer);
|
||||
saver.Save(writer);
|
||||
|
||||
TEST(!buffer.empty(), ());
|
||||
|
||||
MemReader reader(&buffer[0], buffer.size());
|
||||
ReaderSource<MemReader> src(reader);
|
||||
|
||||
serial::OutPointsT triangles;
|
||||
serial::LoadOuterTriangles(src, cp, triangles);
|
||||
|
||||
CompareTriangles(triangles, arrP, arrT, countT);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
UNIT_TEST(TrianglesCoding_Smoke)
|
||||
{
|
||||
P arrP[] = {P(0, 0), P(0, 1), P(1, 0), P(1, 1), P(0, -1), P(-1, 0)};
|
||||
int arrT[][3] = {{0, 1, 2}, {1, 3, 2}, {4, 0, 2}, {1, 0, 5}, {4, 5, 0}};
|
||||
|
||||
TestTrianglesCoding(arrP, ARRAY_SIZE(arrP), arrT, ARRAY_SIZE(arrT));
|
||||
}
|
||||
|
||||
UNIT_TEST(TrianglesCoding_Rect)
|
||||
{
|
||||
P arrP[] = {
|
||||
P(-16.874999848078005, -44.999999874271452),
|
||||
P(-16.874999848078005, -39.374999869032763),
|
||||
P(-11.249999842839316, -39.374999869032763),
|
||||
P(-11.249999842839316, -44.999999874271452)};
|
||||
|
||||
int arrT[][3] = {{2, 0, 1}, {0, 2, 3}};
|
||||
|
||||
TestTrianglesCoding(arrP, ARRAY_SIZE(arrP), arrT, ARRAY_SIZE(arrT));
|
||||
}
|
||||
Reference in New Issue
Block a user