Example #1
0
vector<int> PerimeterWindow::boundaryFromPolygon(QPolygon poly, int xo, int yo, int gw){
    // not sure of the best way of doing this, but lets have a go..
    vector<int> points;
    if(poly.size() < 2){
	cerr << "PerimeterWindow::boundaryFromPolygon, points is too small (less than 2) " << poly.size() << endl;
	return(points);
    }
    for(uint i=1; i < poly.size(); i++){   
	// Fill in the points from i-1 to i
	QPoint p1 = poly[i-1];
	QPoint p2 = poly[i];
//	points.push_back((p1.y() + yo) * gw + p1.x() + xo);
	// then work out how to get the other points..
	int dx = p2.x() - p1.x();
	int dy = p2.y() - p1.y();
	int stepNo = abs(dx) > abs(dy) ? abs(dx) : abs(dy);  
        // in the funny world of pixels a diagonal is only as long as the longer side..
	for(int i=0; i < stepNo; i++){
	    int lx = p1.x() + (i * dx)/stepNo;
	    int ly = p1.y() + (i * dy)/stepNo;
	    // then convert and push back..
	    points.push_back((ly + yo) * gw + lx + xo);
	}
    }
    // but at this point we have not added the last point so we need to do that..
    QPoint p = poly.back();
    points.push_back( (p.y() + yo) * gw + p.x() + xo);
    return(points);
}