Question: Help with overloaded >> operator for findParcelName function: I need to fix findParcelName function so that it reads a point object and tells me if
Help with overloaded >> operator for findParcelName function:
I need to fix findParcelName function so that it reads a point object and tells me if that object is inside the polygon or not. To fix this function I need to get a working overloaded >> operator. Please help me with the overloaded >> operator.
TEST CASE:
TEST_CASE("Testing container (GIS) operations") { GIS taxMap; SECTION("Check file availability") { //I PASS TEST REQUIRE(!taxMap.readFile("zzzzz.zzzz")); REQUIRE(taxMap.readFile("simple-polygons.txt")); } SECTION("Check point that isn't inside any of the polygons") {//I FAIL TEST taxMap.readFile("simple-polygons.txt"); CHECK("Not Found" == taxMap.findParcelName(Point(-1, -1))); } SECTION("Check for point inside polygon") {//I FAIL TEST taxMap.readFile("simple-polygons.txt"); CHECK("squareParcel" == taxMap.findParcelName(Point(1, 1))); CHECK("wideRectangleParcel" == taxMap.findParcelName(Point(5, 4))); } } GIS Class Code:
class GIS{ public: GIS(){ } ~GIS(){cout<<"memory release"<> poly) { //ADD OVERLOADED >> OEPRATOR FOR THIS TO WORK if (poly.contains(point)) { // check if the point is inside the polygon file.close(); return poly.GetName(); // return the name of the polygon if found } } file.close(); return "Not Found"; // return "Not Found" if the point is not inside any polygon } simple-polygons.txt:
squareParcel 0 0 0 2 2 2 2 0 wideRectangleParcel 0 2 0 4 6 4 6 2
Polygon class:
class Polygon: public Point { public: Polygon(); Polygon(string n, Point points1[10], int vertexs); Polygon(const Polygon &p1){ name = p1.name; vertexCount = p1.vertexCount; for(int i = 0; i < vertexCount; i++){ points[i] = p1.points[i]; } } ~Polygon(){ cout<<"Memory released"<//ADD OVERLOADED OPERATOR HERE? bool Polygon::contains(Point point){ int i; int j; bool x = false; for (i = 0, j = vertexCount-1; i < vertexCount; j = i++){ if (points[i].getX() == point.getX() && points[i].getY() == point.getY()) { return true; } if (((points[i].getY()>point.getY()) != (points[j].getY()>point.getY())) && (point.getX() < (points[j].getX()-points[i].getX()) * (point.getY()-points[i].getY()) / (points[j].getY()-points[i].getY()) + points[i].getX())) { x = !x; } } return x; } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
