Adapter

//
vector<shared_ptr<VectorObject>> vectorObjects{
make_shared<VectorRectangle>(10, 10, 100, 100), make_shared<VectorRectangle>(30, 30, 60, 60)
}
struct LineToPointAdapter{
typedef vector<Point> Points;
LineToPointAdapter(Line& line){ // Line->Point ()
int left=min(line.start.x, line.end.x);
int right=min(line.start.x, line.end.x);
int top=min(line.start.y, line.end.x);
int bottom=max(line.start.y, line.end.y);
int dx=right-left;
int dy=line.end.y-line.start.y;
if(dx==0){
for(int y=top; y<=bottom; ++y){
points.emplace_back(Point{left, y});
}
} else if(dy==0){
for(int x=left; x<=right; ++x){
points.emplace_back(Point{x, top});
}
}
}
virtual Points::iterator begin(){ return points.begin(); }
virtual Points::iterator end(){ return points.end(); }
private:
Points points;
};
//
for(auto& obj: vectorObjects){
for(auto& line: *obj){
LineToPointAdapter lpo{line};
DrawPoints(dc, lpo.begin(), lpo.end());
}
}