Commit 952f4eaa authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Finishing chaikins sequences implementation.

parent 50bb82c7
Pipeline #16079 passed with stages
in 12 minutes and 47 seconds
......@@ -18,6 +18,44 @@ std::vector<std::pair<data_type, data_type>> chaikins(
{
std::vector<std::pair<data_type, data_type>> result(
2 * control_polygon.size() - 2);
auto sequence_step =
[](const std::vector<std::pair<data_type, data_type>>& control_polygon,
std::vector<std::pair<data_type, data_type>>& result) {
//
// resize the sequence set
result.resize(2 * control_polygon.size());
for (size_t pi = 0; pi < control_polygon.size(); ++pi)
{
// use the first and the last
if (pi == control_polygon.size() - 1)
{
const std::pair<data_type, data_type>& p1 = control_polygon[pi];
const std::pair<data_type, data_type>& p2 = control_polygon[0];
std::pair<data_type, data_type> qi =
std::make_pair(p1.first * .75 + p2.first * .25,
p1.second * .75 + p2.second * .25);
std::pair<data_type, data_type> ri =
std::make_pair(p1.first * .25 + p2.first * .75,
p1.second * .25 + p2.second * .75);
result[result.size() - 2] = qi;
result[result.size() - 1] = ri;
}
else
{
const std::pair<data_type, data_type>& p1 = control_polygon[pi];
const std::pair<data_type, data_type>& p2 = control_polygon[pi + 1];
std::pair<data_type, data_type> qi =
std::make_pair(p1.first * .75 + p2.first * .25,
p1.second * .75 + p2.second * .25);
std::pair<data_type, data_type> ri =
std::make_pair(p1.first * .25 + p2.first * .75,
p1.second * .25 + p2.second * .75);
result[2 * pi] = qi;
result[2 * pi + 1] = ri;
}
}
return;
};
for (size_t pi = 0; pi < control_polygon.size(); ++pi)
{
// break if this is the last point
......@@ -28,14 +66,19 @@ std::vector<std::pair<data_type, data_type>> chaikins(
p1.first * .75 + p2.first * .25, p1.second * .75 + p2.second * .25);
std::pair<data_type, data_type> ri = std::make_pair(
p1.first * .25 + p2.first * .75, p1.second * .25 + p2.second * .75);
// char buf[80];
// sprintf(buf, "%.2f,%.2f", qi.first, qi.second);
// radix_line("\t{" << buf << "},");
// sprintf(buf, "%.2f,%.2f", ri.first, ri.second);
// radix_line("\t{" << buf << "},");
result[2 * pi] = qi;
result[2 * pi + 1] = ri;
}
if (sequence > 1)
{
auto& control_set = result;
std::vector<std::pair<data_type, data_type>> sequence_set;
for (size_t si = 0; si < sequence; ++si)
{
sequence_step(control_set, sequence_set);
}
result = sequence_set;
}
return result;
}
} // namespace radix
......@@ -26,36 +26,42 @@ TEST(RadixChaikins, Simple)
chaikins<float>(control_polygon, tranlate);
std::vector<std::pair<float, float>> blessed{
{10.00, 22.50}, {10.00, 27.50}, {10.00, 32.50}, {10.00, 37.50},
{12.50, 40.00}, {17.50, 40.00}, {22.50, 40.00}, {27.50, 40.00},
{32.50, 40.00}, {37.50, 40.00}, {40.00, 37.50}, {40.00, 32.50},
{42.50, 30.00}, {47.50, 30.00}, {52.50, 30.00}, {57.50, 30.00},
{62.50, 30.00}, {67.50, 30.00}, {70.00, 32.50}, {70.00, 37.50},
{70.00, 42.50}, {70.00, 47.50}, {70.00, 52.50}, {70.00, 57.50},
{70.00, 62.50}, {70.00, 67.50}, {70.00, 72.50}, {70.00, 77.50},
{70.00, 82.50}, {70.00, 87.50}, {70.00, 92.50}, {70.00, 97.50},
{70.00, 102.50}, {70.00, 107.50}, {67.50, 110.00}, {62.50, 110.00},
{60.00, 107.50}, {60.00, 102.50}, {57.50, 100.00}, {52.50, 100.00},
{50.00, 97.50}, {50.00, 92.50}, {50.00, 87.50}, {50.00, 82.50},
{47.50, 80.00}, {42.50, 80.00}, {40.00, 77.50}, {40.00, 72.50},
{40.00, 67.50}, {40.00, 62.50}, {37.50, 60.00}, {32.50, 60.00},
{30.00, 57.50}, {30.00, 52.50}, {27.50, 50.00}, {22.50, 50.00},
{20.00, 52.50}, {20.00, 57.50}, {20.00, 62.50}, {20.00, 67.50},
{22.50, 70.00}, {27.50, 70.00}, {30.00, 72.50}, {30.00, 77.50},
{30.00, 82.50}, {30.00, 87.50}, {32.50, 90.00}, {37.50, 90.00},
{40.00, 92.50}, {40.00, 97.50}, {40.00, 102.50}, {40.00, 107.50},
{42.50, 110.00}, {47.50, 110.00}, {50.00, 112.50}, {50.00, 117.50},
{50.00, 122.50}, {50.00, 127.50}, {52.50, 130.00}, {57.50, 130.00},
{62.50, 130.00}, {67.50, 130.00}, {72.50, 130.00}, {77.50, 130.00},
{80.00, 127.50}, {80.00, 122.50}, {80.00, 117.50}, {80.00, 112.50},
{80.00, 107.50}, {80.00, 102.50}, {80.00, 97.50}, {80.00, 92.50},
{80.00, 87.50}, {80.00, 82.50}, {80.00, 77.50}, {80.00, 72.50},
{80.00, 67.50}, {80.00, 62.50}, {80.00, 57.50}, {80.00, 52.50},
{80.00, 47.50}, {80.00, 42.50}, {80.00, 37.50}, {80.00, 32.50},
{80.00, 27.50}, {80.00, 22.50}, {77.50, 20.00}, {72.50, 20.00},
{67.50, 20.00}, {62.50, 20.00}, {57.50, 20.00}, {52.50, 20.00},
{47.50, 20.00}, {42.50, 20.00}, {37.50, 20.00}, {32.50, 20.00},
{27.50, 20.00}, {22.50, 20.00}, {17.50, 20.00}, {12.50, 20.00}};
{10.0f, 22.5f}, {10.0f, 27.5f}, {10.0f, 32.5f}, {10.0f, 37.5f},
{12.5f, 40.0f}, {17.5f, 40.0f}, {22.5f, 40.0f}, {27.5f, 40.0f},
{32.5f, 40.0f}, {37.5f, 40.0f}, {40.0f, 37.5f}, {40.0f, 32.5f},
{42.5f, 30.0f}, {47.5f, 30.0f}, {52.5f, 30.0f}, {57.5f, 30.0f},
{62.5f, 30.0f}, {67.5f, 30.0f}, {70.0f, 32.5f}, {70.0f, 37.5f},
{70.0f, 42.5f}, {70.0f, 47.5f}, {70.0f, 52.5f}, {70.0f, 57.5f},
{70.0f, 62.5f}, {70.0f, 67.5f}, {70.0f, 72.5f}, {70.0f, 77.5f},
{70.0f, 82.5f}, {70.0f, 87.5f}, {70.0f, 92.5f}, {70.0f, 97.5f},
{70.0f, 102.5f}, {70.0f, 107.5f}, {67.5f, 110.0f}, {62.5f, 110.0f},
{60.0f, 107.5f}, {60.0f, 102.5f}, {57.5f, 100.0f}, {52.5f, 100.0f},
{50.0f, 97.5f}, {50.0f, 92.5f}, {50.0f, 87.5f}, {50.0f, 82.5f},
{47.5f, 80.0f}, {42.5f, 80.0f}, {40.0f, 77.5f}, {40.0f, 72.5f},
{40.0f, 67.5f}, {40.0f, 62.5f}, {37.5f, 60.0f}, {32.5f, 60.0f},
{30.0f, 57.5f}, {30.0f, 52.5f}, {27.5f, 50.0f}, {22.5f, 50.0f},
{20.0f, 52.5f}, {20.0f, 57.5f}, {20.0f, 62.5f}, {20.0f, 67.5f},
{22.5f, 70.0f}, {27.5f, 70.0f}, {30.0f, 72.5f}, {30.0f, 77.5f},
{30.0f, 82.5f}, {30.0f, 87.5f}, {32.5f, 90.0f}, {37.5f, 90.0f},
{40.0f, 92.5f}, {40.0f, 97.5f}, {40.0f, 102.5f}, {40.0f, 107.5f},
{42.5f, 110.0f}, {47.5f, 110.0f}, {50.0f, 112.5f}, {50.0f, 117.5f},
{50.0f, 122.5f}, {50.0f, 127.5f}, {52.5f, 130.0f}, {57.5f, 130.0f},
{62.5f, 130.0f}, {67.5f, 130.0f}, {72.5f, 130.0f}, {77.5f, 130.0f},
{80.0f, 127.5f}, {80.0f, 122.5f}, {80.0f, 117.5f}, {80.0f, 112.5f},
{80.0f, 107.5f}, {80.0f, 102.5f}, {80.0f, 97.5f}, {80.0f, 92.5f},
{80.0f, 87.5f}, {80.0f, 82.5f}, {80.0f, 77.5f}, {80.0f, 72.5f},
{80.0f, 67.5f}, {80.0f, 62.5f}, {80.0f, 57.5f}, {80.0f, 52.5f},
{80.0f, 47.5f}, {80.0f, 42.5f}, {80.0f, 37.5f}, {80.0f, 32.5f},
{80.0f, 27.5f}, {80.0f, 22.5f}, {77.5f, 20.0f}, {72.5f, 20.0f},
{67.5f, 20.0f}, {62.5f, 20.0f}, {57.5f, 20.0f}, {52.5f, 20.0f},
{47.5f, 20.0f}, {42.5f, 20.0f}, {37.5f, 20.0f}, {32.5f, 20.0f},
{27.5f, 20.0f}, {22.5f, 20.0f}, {17.5f, 20.0f}, {12.5f, 20.0f}};
// for (const auto& point : results)
// {
// char buf[80];
// sprintf(buf, "%.4ff,%.4ff", point.first, point.second);
// radix_line("{" << buf << "},");
// }
radix_tagged_line("Number of polygon points (" << results.size() << ")");
ASSERT_EQ(blessed.size(), (2 * control_polygon.size()) - 2);
ASSERT_EQ(blessed.size(), results.size());
......@@ -64,3 +70,38 @@ TEST(RadixChaikins, Simple)
EXPECT_EQ(blessed[i], results[i]);
}
}
TEST(RadixChaikins, TwoSequence)
{
std::vector<std::pair<int, int>> control_polygon{
{1, 2}, {2, 2}, {2, 1}, {1, 1}, {1, 2}};
auto tranlate = [](const std::pair<int, int>& point) {
// tranlate index into 10x10m grid
return std::make_pair(10.f * float(point.first),
10.f * float(point.second));
};
std::vector<std::pair<float, float>> results =
chaikins<float>(control_polygon, tranlate, 2);
// for (const auto& point : results)
// {
// char buf[80];
// sprintf(buf, "%.4ff,%.4ff", point.first, point.second);
// radix_line("{" << buf << "},");
// }
std::vector<std::pair<float, float>> blessed{
{13.7500f, 20.0f}, {16.2500f, 20.0f}, {18.1250f, 19.3750f},
{19.3750f, 18.1250f}, {20.0f, 16.2500f}, {20.0f, 13.7500f},
{19.3750f, 11.8750f}, {18.1250f, 10.6250f}, {16.2500f, 10.0f},
{13.7500f, 10.0f}, {11.8750f, 10.6250f}, {10.6250f, 11.8750f},
{10.0f, 13.7500f}, {10.0f, 16.2500f}, {10.6250f, 18.1250f},
{11.8750f, 19.3750f}};
radix_tagged_line("Number of polygon points (" << results.size() << ")");
ASSERT_EQ(blessed.size(), 4 * (control_polygon.size() - 1));
ASSERT_EQ(blessed.size(), results.size());
for (size_t i = 0; i < blessed.size(); ++i)
{
EXPECT_EQ(blessed[i], results[i]);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment