For brevity. Here you go:
Code:
//. . . somewhere in the class grid:
struct span;
typedef std::vector<span> region;
typedef std::pair< point2d, std::vector<point2d> > normal_pair;
typedef std::vector<normal_pair> boundary;
then here are a couple of examples
Code:
grid::size_type num_points(const grid::region & r, unsigned int until)
{
unsigned long int points = 0;
for(unsigned int i = 0; i < r.size() && i < until; ++i)
points += r[i].dy;
return points;
}
grid::size_type num_points(const grid::boundary & b, unsigned int until)
{
unsigned long int points = 0;
for(unsigned int i = 0; i < b.size() && i < until; ++i)
points += b[i].second.size();
return points;
}
grid::size_type first_more_than(const grid::region & reg, unsigned long int quota, grid::size_type begin_index)
{
unsigned long int count = 0;
for(unsigned int i = begin_index; i < reg.size(); ++i)
{
count += reg[i].dy;
if(count > quota)
return i;
}
return reg.size();
}
grid::size_type first_more_than(const grid::boundary & bound, unsigned long int quota, grid::size_type begin_index)
{
unsigned long int count = 0;
for(unsigned int i = begin_index; i < bound.size(); ++i)
{
count += bound[i].second.size();
if(count > quota)
return i;
}
return bound.size();
}
Using custom functors in stl algorithms would do the trick, but is there a way to specify a member?