class Points
{
public:
Points (int _num_points) : num_points (_num_points), points (new double [_num_points * 2]){}
~Points (){delete [] points;}
public:
int get_num_points () const {return num_points;}
void get_coordinate (int _pos, double &_x, double &_y) const
{
if (_pos < num_points)
{
_x = *(points + _pos * 2);
_y = *(points + _pos * 2 + 1);
}
}
void set_coordinate (int _pos, double _x, double _y)
{
if (_pos < num_points)
{
*(points + _pos * 2) = _x;
*(points + _pos * 2 + 1) = _y;
}
}
private:
int num_points;
double *points;
};
class Line
{
public:
void set_coordinates (double _x1, double _y1, double _x2, double _y2)
{
x1 = _x1;
y1 = _y1;
x2 = _x2;
y2 = _y2;
}
void draw (){ . . . .}
private:
double x1, y1, x2, y2;
};
class Polyline
{
public:
Polyline (const Points &_points) : points (_points), lines (new Line [_points.get_num_points () - 1])
{
double x1, y1, x2, y2;
for (int i = 0; i < get_num_lines (); i++)
{
points.get_coordinate (i * 2, x1, y1);
points.get_coordinate (i * 2 + 1, x2, y2);
lines [i].set_coordinates (x1, y1, x2, y2);
}
}
~Polyline (){delete [] lines;}
public:
Points get_points () const {return points;}
int get_num_lines () const {return points.get_num_points () -1;}
Line* get_line (unsigned _ind)
{
Line *ret = NULL;
if (_ind < get_num_lines ()) ret = &lines [_ind];
return ret;
}
void draw () {for (int i = 0; i < get_num_lines (); i++) lines [i].draw ();}
private:
Points points;
Line *lines;
};