bool on_double_click(const point_2f & p) { chain.clear(); chain = {point_2(0, 0), point_2(20, 20), point_2(40, 40)}; current_vertex_.reset(); return true; }
triangle_contains_point_viewer(): t_(point_2(0, 0), point_2(100, 100), point_2(200, 0)), rbutton_pressed_(false) { }
TEST(Triangulation, one_line) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(0, 0)) (point_2(10, 0)) (point_2(20, 0)) (point_2(10, -10)); cg::cell<double> cell; for (int i = 0; i < pts.size(); i++) { auto ans = cell.get_triangulation(); for (const cg::triangle_2 & tr : ans) { std::cout << tr[0] << tr[1] << tr[2] << std::endl; } cell.add_point(pts[i]); } std::cout << "Ans" << std::endl; auto ans = cell.get_triangulation(); for (const cg::triangle_2 & tr : ans) { std::cout << tr[0] << tr[1] << tr[2] << std::endl; } EXPECT_TRUE(true == true); }
TEST(convex_hull, simple_andrew4) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(1, 0)) (point_2(0, 1)); EXPECT_TRUE(is_convex_hull(pts.begin(), cg::andrew_hull(pts.begin(), pts.end()), pts.end())); }
TEST(orientation, counterclockwise2) { using cg::point_2; std::vector<point_2> a = boost::assign::list_of(point_2(1, 0)) (point_2(3, 0)) (point_2(0, 2)); EXPECT_TRUE(cg::counterclockwise(cg::contour_2(a))); }
TEST(quick_hull, simple2) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(0, 0)) (point_2(5, 0)) (point_2(5, 5)) (point_2(4, 3)); EXPECT_TRUE(is_convex_hull(pts.begin(), cg::quick_hull(pts.begin(), pts.end()), pts.end())); }
TEST(convex_hull, simple_quick_hull0) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(-1, 0)) (point_2(1, 0)) (point_2(0, 1)) (point_2(0, -1)); EXPECT_FALSE(is_convex_hull(pts.begin(), cg::quick_hull(pts.begin(), pts.end()), pts.end())); }
TEST(quick_hull, same_points) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(1, 1)) (point_2(1, 1)) (point_2(1, 1)) (point_2(1, 1)) (point_2(1, 1)); EXPECT_TRUE(is_convex_hull(pts.begin(), cg::quick_hull(pts.begin(), pts.end()), pts.end())); }
TEST(quick_hull, line) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(0, 0)) (point_2(1, 1)) (point_2(3, 3)) (point_2(-1, -1)) (point_2(4, 4)); EXPECT_TRUE(is_convex_hull(pts.begin(), cg::quick_hull(pts.begin(), pts.end()), pts.end())); }
TEST(contains, triangle_point) { using cg::point_2; cg::triangle_2 t(point_2(0, 0), point_2(1, 1), point_2(2, 0)); for (size_t l = 0; l != 3; ++l) EXPECT_TRUE(cg::contains(t, t[l])); EXPECT_TRUE(cg::contains(t, point_2(1, 0.5))); EXPECT_TRUE(cg::contains(t, point_2(1, 0))); EXPECT_TRUE(cg::contains(t, point_2(0.5, 0.5))); EXPECT_TRUE(cg::contains(t, point_2(1.5, 0.5))); EXPECT_FALSE(cg::contains(t, point_2(0, 1))); EXPECT_FALSE(cg::contains(t, point_2(2, 1))); EXPECT_FALSE(cg::contains(t, point_2(1, -1))); }
TEST(jarvis_hull, same_line) { using cg::point_2; std::vector<point_2> pts; int sz = 10; for (int i = 0; i < sz; i++) { pts.push_back(point_2(i, 0)); pts.push_back(point_2(sz, i)); pts.push_back(point_2(0, i + 1)); pts.push_back(point_2(i + 1, sz)); } for (int it = 0; it < 10; ++it) { EXPECT_TRUE(is_convex_hull(pts.begin(), cg::jarvis_hull(pts.begin(), pts.end()), pts.end())); std::random_shuffle(pts.begin(), pts.end()); } }
TEST(dynamic_convex_hull, without_deleting3) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(-15.2939, -91.2349)) (point_2(73.6514, -84.1031)) (point_2(46.0487, -42.9297)) (point_2(21.95, 48.3017)) (point_2(-6.31702, -43.6781)); cg::dynamic_hull dh; for (point_2 p : pts) { dh.add_point(p); } EXPECT_TRUE(is_convex_hull(pts.begin(), pts.end(), dh.get_hull().first, dh.get_hull().second)); }
TEST(dynamic_convex_hull, without_deleting4) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(92.5535, 63.9831)) (point_2(48.2666, -2.07253)) (point_2(-87.6796, 74.2083)) (point_2(-41.6394, 42.1274)) (point_2(4.02735, 3.24309)); cg::dynamic_hull dh; for (point_2 p : pts) { dh.add_point(p); } EXPECT_TRUE(is_convex_hull(pts.begin(), pts.end(), dh.get_hull().first, dh.get_hull().second)); }
TEST(dynamic_convex_hull, without_deleting5) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(-55, -55)) (point_2(53, 65)) (point_2(67, -27)) (point_2(-10, -46)) (point_2(12, -30)); cg::dynamic_hull dh; for (point_2 p : pts) { dh.add_point(p); } EXPECT_TRUE(is_convex_hull(pts.begin(), pts.end(), dh.get_hull().first, dh.get_hull().second)); }
triangle_intersects_triangle_viewer() : s_(point_2(-100, -100), point_2(50, 50), point_2(0, 50)), t_(point_2(-50, -50), point_2(50, -50), point_2(-50, 50)), rbutton_pressed_(false), int_({}) { int_ = cg::intersection(s_, t_); }
bool on_press(const point_2f & p) { for (size_t i = 0; i < chain.size(); ++i) { if (fabs(chain[i].x - p.x) < 15 && fabs(chain[i].y - p.y) < 15) { current_vertex_ = i; return true; } } if(!current_vertex_) chain.push_back(point_2(p.x, p.y)); return true; }
TEST(contains, segment_point) { using cg::point_2; cg::segment_2 s(point_2(0, 0), point_2(2, 2)); for (size_t l = 0; l != 2; ++l) EXPECT_TRUE(cg::contains(s, s[l])); EXPECT_TRUE(cg::contains(s, point_2(1, 1))); EXPECT_FALSE(cg::contains(s, point_2(-1, -1))); EXPECT_FALSE(cg::contains(s, point_2(4, 4))); EXPECT_FALSE(cg::contains(s, point_2(1, 0))); EXPECT_FALSE(cg::contains(s, point_2(0, 1))); }
TEST(jarvis_hull, simple) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(0, 0)) (point_2(1, 0)) (point_2(0, 1)) (point_2(2, 0)) (point_2(0, 2)) (point_2(3, 0)); EXPECT_TRUE(is_convex_hull(pts.begin(), cg::jarvis_hull(pts.begin(), pts.end()), pts.end())); }
TEST(dynamic_convex_hull, with_deleting2) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(81, 80)) (point_2(-80, -41)) (point_2(71, 90)) (point_2(-64, 17)); std::vector<point_2> not_removed = boost::assign::list_of(point_2(81, 80)) (point_2(71, 90)) (point_2(-64, 17)); cg::dynamic_hull dh; for (point_2 p : pts) { dh.add_point(p); } dh.remove_point(point_2(-80, -41)); EXPECT_TRUE(is_convex_hull(not_removed.begin(), not_removed.end(), dh.get_hull().first, dh.get_hull().second)); }
TEST(dynamic_convex_hull, without_deleting1) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(0, 0)) (point_2(1, 0)) (point_2(0, 1)) (point_2(2, 0)) (point_2(0, 2)) (point_2(3, 0)); cg::dynamic_hull dh; for (point_2 p : pts) { dh.add_point(p); } EXPECT_TRUE(is_convex_hull(pts.begin(), pts.end(), dh.get_hull().first, dh.get_hull().second)); }
TEST(dynamic_convex_hull, without_deleting6) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(17, -19)) (point_2(61, 94)) (point_2(-29, 38)) (point_2(-9, -42)) (point_2(-85, 40)) (point_2(-24, -7)) (point_2(-78, 95)); cg::dynamic_hull dh; for (point_2 p : pts) { dh.add_point(p); } auto st_h = dh.get_hull().first; auto en_h = dh.get_hull().second; bool res = is_convex_hull(pts.begin(), pts.end(), st_h, en_h); EXPECT_TRUE(is_convex_hull(pts.begin(), pts.end(), dh.get_hull().first, dh.get_hull().second)); }
TEST(dynamic_convex_hull, with_deleting1) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(0, 0)) (point_2(3, 0)) (point_2(4, 2)) (point_2(2, 2)) (point_2(2, 4)) (point_2(-1, 2)) (point_2(1, 1)) (point_2(0, 1)); std::vector<point_2> not_removed = boost::assign::list_of(point_2(0, 0)) (point_2(3, 0)) (point_2(2, 2)) (point_2(1, 1)) (point_2(0, 1)); cg::dynamic_hull dh; for (point_2 p : pts) { dh.add_point(p); } dh.remove_point(point_2(4, 2)); dh.remove_point(point_2(-1, 2)); dh.remove_point(point_2(2, 4)); EXPECT_TRUE(is_convex_hull(not_removed.begin(), not_removed.end(), dh.get_hull().first, dh.get_hull().second)); }
TEST(minkowski, square) { using cg::point_2; std::vector<point_2> a = boost::assign::list_of(point_2(0, 0)) (point_2(4, 0)) (point_2(4, 4)) (point_2(0, 4)); std::vector<point_2> b = boost::assign::list_of(point_2(-2, -2)) (point_2(2, -2)) (point_2(2, 2)) (point_2(-2, 2)); std::vector<point_2> c = boost::assign::list_of(point_2(-2, -2)) (point_2(6, -2)) (point_2(6, 6)) (point_2(-2, 6)); auto ans = cg::contour_2(c); auto res = cg::minkowski_sum(cg::contour_2(a), cg::contour_2(b)); EXPECT_TRUE( std::equal(ans.begin(), ans.end(), res.begin()) ); }
#include <gtest/gtest.h> #include <boost/assign/list_of.hpp> #include <cg/operations/convex.h> #include <cg/convex_hull/graham.h> #include <misc/random_utils.h> #include "random_utils.h" using namespace util; TEST(convex, 1) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(0, 0)); EXPECT_TRUE(cg::convex(cg::contour_2(pts))); } TEST(convex, 2) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(0, 0)) (point_2(1, 0)); EXPECT_TRUE(cg::convex(cg::contour_2(pts))); } TEST(convex, 3)
contour_contains_point_viewer() : chain(std::vector<point_2>({point_2(0, 0), point_2(20, 20), point_2(40, 40)})) , eps(0.5) , rbutton_pressed_(false) {}
rectangle_intersects_segment_viewer() : s_(point_2(-100, -100), point_2(100, 100)), r_(cg::range_d(-50, 50), cg::range_d(-50, 50)), rbutton_pressed_(false) {}
contour_contains_point_viewer() : contour(std::vector<point_2>({point_2(0, 0), point_2(100, 100), point_2(200, 0)})) {}
localization_point_viewer() { dcel_by_lines = new DCEL(point_2(-400, -400), point_2(400, 400)); }
segments_intersect_viewer() : s_ { cg::segment_2(point_2(-100, -100), point_2(100, 100)), cg::segment_2(point_2(100, -100), point_2(-100, 100)) }, rbutton_pressed_(false) {}
TEST(quick_hull, simple3) { using cg::point_2; std::vector<point_2> pts = boost::assign::list_of(point_2(95.0938, -19.7291)) (point_2(-24.0541, -28.2266)) (point_2(-51.1062, 19.8668)) (point_2(74.1097, -66.2974)) (point_2(94.036, 97.6347)) (point_2(-67.9643, -30.467)) (point_2(79.7704, -61.9609)) (point_2(-1.94966, 50.4662)) (point_2(45.4063, -35.1337)) (point_2(-23.3787, 91.2357)) (point_2(-88.4949, 81.116)) (point_2(6.02942, -54.5359)); EXPECT_TRUE(is_convex_hull(pts.begin(), cg::quick_hull(pts.begin(), pts.end()), pts.end())); }