Okay, so your "polygonn" object takes in the number of points and the array of points itself.
When you do
Point<T>(*verts),
you're doing the same thing as Point<T>(verts[0]) so you're essentially only passing the first vertex. In other words, kinda useless.
I think a "has-a" relationship would make much more sense here than an is-a relationship. A polygon
has an array of points that define it, and taking the average of those points could be an additional operation. But, if the end result needs to be that polygon.x() == 5 and polygon.y() == 8, you need to compute the average as you mentioned, and eventually assign it to _pts.
I would change your polygon constructor so it assigns a new value to
_pts, which is computed by taking the average of the x coordinates of
verts, and the average of the y coordinates of
verts.
Let's say you have a function like this:
1 2 3 4 5 6 7
|
Vector<int> average(Vector<int> points[], int size)
{
int x_sum = 0;
int y_sum = 0;
// .... compute sum and then divide by number of points
return Vector<int>(x_sum / size, y_sum / size);
}
| |
To compute the average, sum the x components and then divide by the total number of values, and sum the y components then divide that by the total number of values. Try to write that.