TEST(test1, tests) { std::vector<cg::point_2> v; v.push_back(cg::point_2(0, 0)); v.push_back(cg::point_2(10, 0)); v.push_back(cg::point_2(10, 10)); cg::point_2 p2(3, 3); cg::contour_2 tr(v); EXPECT_EQ(point_inside_polygon(tr, p2), true); }
/************************************************************************* * * * Check to see a polygon is selected or not. * * Identical to "is_selected()" except never modifies the ROI. * * * If a polygon is selected, it will set the 'acttype' variable. * * Return TRUE or FALSE. * * */ Flag Polygon::is_selectable(short x, short y) { #define Vertex_Check(a,b,p,q,v) com_point_in_rect(a, b, p-v, q-v, p+v, q+v) int i, index; // ------ Check to RESIZE a polygon ----- // Note that basex and basey are not used int dist= 0; int d, dx, dy; int isfound = FALSE; if (force_acttype != ROI_MOVE){ for (i=0; i<npnts; i++){ if (Vertex_Check(x, y, pnt[i].x, pnt[i].y, aperture)){ dx = (x - pnt[i].x); dy = (y - pnt[i].y); d = dx * dx + dy * dy; if (isfound == FALSE || d < dist){ isfound = TRUE; dist = d; vertex_selected = i; } acttype = ROI_RESIZE; } } } if (isfound){ return(TRUE); } // ---- Check polygon MOVE or vertex insertion ----- index = LocateSegment(aperture/2, x, y); if ( index != -1) { // Then user wants to split this segment and insert and new vertex // InsertVertex(index, x, y); acttype = ROI_RESIZE; vertex_selected = index+1; return(TRUE); } else if (com_point_in_rect(x, y, x_min, y_min, x_max, y_max) && point_inside_polygon(yedge[y-y_min], x)) { acttype = ROI_MOVE; return(TRUE); } return(FALSE); }
TEST(test4, tests) { std::vector<cg::point_2> v; v.push_back(cg::point_2(6, -1)); v.push_back(cg::point_2(7, 0)); v.push_back(cg::point_2(7, 1)); v.push_back(cg::point_2(5, 2)); v.push_back(cg::point_2(4, 0)); v.push_back(cg::point_2(2, 2)); v.push_back(cg::point_2(1, 0)); v.push_back(cg::point_2(2, -2)); v.push_back(cg::point_2(3, 0)); v.push_back(cg::point_2(4, -2)); v.push_back(cg::point_2(5, 1)); cg::contour_2 tr(v); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(1, 0)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(2, 0)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(3, 0)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(4, 0)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(5, 0)), false); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(6, 0)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(7, 0)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(8, 0)), false); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(0, 0)), false); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(1, 1)), false); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(2, 1)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(3.5, 0)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(4, 1)), false); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(5, -1)), false); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(4, -0.5)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(3.5, 0.001)), true); }
TEST(test2, tests) { std::vector<cg::point_2> v; v.push_back(cg::point_2(2, 3)); v.push_back(cg::point_2(2, 2)); v.push_back(cg::point_2(3, 1)); v.push_back(cg::point_2(5, 1)); v.push_back(cg::point_2(8, 4)); v.push_back(cg::point_2(6, 6)); v.push_back(cg::point_2(4, 6)); v.push_back(cg::point_2(3, 5)); cg::contour_2 tr(v); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(2, 2)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(3, 1)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(3, 2)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(3, 5)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(3, 6)), false); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(5, 1)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(5, 2)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(8, 4)), true); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(8, 3)), false); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(8, 5)), false); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(6, 7)), false); EXPECT_EQ(point_inside_polygon(tr, cg::point_2(2.5, 3.5)), true); }