bool isIn(T p[2], const std::vector<T> xs, const std::vector<T> &ys) { int num_intersection = 0; int n = xs.size(); T A[2] = { xs[n - 1], ys[n - 1] }; for (int i = 0; i < n; i++) { T B[2] = { xs[i], ys[i] }; //if the scanline of p intersect with AB bool ret; if (B[1] >= A[1]) ret = isIntersection(p, A, B); else ret = isIntersection(p, B, A); if (ret) num_intersection++; A[0] = B[0]; A[1] = B[1]; } return num_intersection % 2 == 1; }
Rectangle Rectangle::intersect(const Rectangle& other) const { if (isIntersection(other)) { Point lowerRightCorner = getLowerRightCorner(); Point otherLowerRightCorner = other.getLowerRightCorner(); int x1 = std::max(upperLeftCorner.x, other.upperLeftCorner.x); int y1 = std::max(upperLeftCorner.y, other.upperLeftCorner.y); int x2 = std::min(lowerRightCorner.x, otherLowerRightCorner.x); int y2 = std::min(lowerRightCorner.y, otherLowerRightCorner.y); return Rectangle::fromCoordinates(x1, y1, x2, y2); } else { return Rectangle::ZERO; } }
int checkCost(long r, long g, long b){ int x = -1; //HEURISTIC TABLE RGB HTable[25]; HTable[0].red=42;HTable[0].green=59;HTable[0].blue=27.5;// HTable[1].red=60.5;HTable[1].green=40;HTable[1].blue=25;// HTable[4].red=45.5;HTable[4].green=41;HTable[4].blue=12.5;// HTable[5].red=42.5;HTable[5].green=50;HTable[5].blue=48;// HTable[6].red=67.5;HTable[6].green=81;HTable[6].blue=20; HTable[7].red=100;HTable[7].green=50;HTable[7].blue=0; HTable[8].red=33.5;HTable[8].green=50.5;HTable[8].blue=32.5; HTable[9].red=47.5;HTable[9].green=23;HTable[9].blue=19; HTable[10].red=100;HTable[10].green=93;HTable[10].blue=34.5; HTable[11].red=54;HTable[11].green=64;HTable[11].blue=30; HTable[13].red=100;HTable[13].green=0;HTable[13].blue=50; HTable[14].red=54;HTable[14].green=48.5;HTable[14].blue=29; HTable[16].red=68.5;HTable[16].green=87.5;HTable[16].blue=31; HTable[17].red=100;HTable[17].green=35.5;HTable[17].blue=45; HTable[18].red=55;HTable[18].green=58;HTable[18].blue=50; HTable[20].red=50;HTable[20].green=0;HTable[20].blue=100; HTable[23].red=0;HTable[23].green=100;HTable[23].blue=100; HTable[24].red=82.5;HTable[24].green=54;HTable[24].blue=36.5; for (int i=0;i<=24;i++){ if((i!=2) && (i!=3) && (i!=12) && (i!=15) && (i!=19) && (i!=21) && (i!=22)){ int range; if(isIntersection(r,g,b)){ return 100; } if(isStop(r,g,b)){ return 101; } if(i==14){//pengecualian untuk abu2 range = 5; } else { range = 25; } if((r <= HTable[i].red + range) && (r >= HTable[i].red - range) && (g >= HTable[i].green - range) && (g <= HTable[i].green + range) && (b >= HTable[i].blue - range) && (b <= HTable[i].blue + range)){ x = i; break; } } } return x; }
void PPETask::dataPreHandle() { //all edges adjustAntiClockWise(getAllEdges()); if (farmEdge.size() < 3) printLog("farmEdge.size() < 3", true); if (farmEdge.size() == 0) printLog("farmEdge.size() == 0", true); //offsetSprayInflation farmEdge.inflate(sprayingOffset); for (int i = 0; i < (int)nsz_blank.size(); i++) nsz_blank[i].deflate(sprayingOffset); //offsetSprayInflation for (int i = 0; i < (int)nsz_around.size(); i++) nsz_around[i].inflate(sprayingOffset); for (int i = 0; i < (int)nsz_height.size(); i++) nsz_height[i].inflate(sprayingOffset); for (int i = 0; i < (int)obs_around_outside.size(); i++) obs_around_outside[i].inflate(sprayingOffset); //all edges vector<DjiEdge* > tem=getAllEdges(); for (int i = 0; i < (int)tem.size(); i++) { tem[i]->calOuterRect(); } tem = getAllEdges(); for (int i = 0; i < (int)tem.size(); i++) { for (int j = i + 1; j < (int)tem.size(); j++) { if (isIntersection(*tem[i], *tem[j])) printLog("two edge intersected, in dataPreHandle",true); } } }