// Request static int inside(lua_State *L) { int n = lua_gettop(L); // Number of arguments if (n != 2) return luaL_error(L, "Got %d arguments expected 2 (self, point)", n); Circle c = Circle_pull(L, 1); Vector2 v = Vector2_pull(L, 2); lua_pushboolean(L, c.inside(v)); return 1; }
bool CueTable::insertPocket(Polygon2& shape, vec2 holePos){ const Circle circle(holePos, 1.0f); auto edges = &shape.getEdges(); int countEdges = 0; for(uint i = 0; i < edges->size(); i++){ Edge2 edge = edges->at(i); if(circle.inside(edge[0]) ^ circle.inside(edge[1])){ countEdges++; } } if(countEdges > 2){ return false; }else if (countEdges == 1){ return false; } for( auto it = edges->begin(); it != edges->end(); ){ Edge2 edge = (*it); if(circle.inside(edge[0]) && circle.inside(edge[1])){ it = edges->erase( it ); }else{ it++; } } for( auto it = edges->begin(); it != edges->end(); ){ Edge2 edge = (*it); vec2 alpha; IntersectionType intType = circleIntersection(edge, circle, alpha.x, alpha.y); vec2 edge0 = edge[0]; vec2 edge1 = edge[1]; vec2 hit0 = lerp(edge0,edge1,alpha[0]); vec2 hit1 = lerp(edge0,edge1,alpha[1]); switch (intType) { case IMPALE: { it = edges->erase( it ); it = edges->insert(it, Edge2(edge0, hit0)); /*vector<Edge2> pocketEdges = generatePocketEdges(circle, Edge2(edge0, hit0), Edge2(hit1, edge1), 10); for( auto& e : pocketEdges ) it = edges->insert( it + 1, e );*/ it = edges->insert(it + 1, Edge2(hit1, edge1)); it--; break; } case POKE: { it->at(1) = hit0; /*vector<Edge2> pocketEdges = generatePocketEdges(circle, *it, *(it+1), 10); for( auto& e : pocketEdges ) it = edges->insert( it + 1, e );*/ break; } case EXITWOUND: { it->at(0) = hit1; break; } case COMPLETELYINSIDE: case FALLSHORT: case PAST: case NONE: break; case INVALID: default: assert(0); } it++; } return true; }