Guys,
I know since the Polygon is a Closed Polyline so it should connects all the dots the user gives it. But the problem here is within the definition. It has been said that "no two line segments intersect" but by a simple code I broke that talk. Probably in fact it's up to the user how defines those dots and sometimes it's possible to two line segments intersect. Apparently there is no difference between Polygon and Closed Polyline.
for (int i = 1; i<np-1; ++i) { // check that new segment doesn't interset and old point
Point ignore(0,0);
if (line_segment_intersect( point(np-1), p, point(i-1), point(i), ignore))
error("intersect in polygon");
}
This clearly does check whether the new segment would intersect with any of the existing segments.
However, it does not check against the implicit closing segment p,point(0).
One should add after that loop:
1 2 3 4
Point ignore(0,0);
if (line_segment_intersect( point(np-1), p, p, point(0), ignore))
error("intersect in polygon");
}
Therefore, I do see a clear difference between Polygon and Closed Polyline, but the implementation of the Polygon appears to have a logical error.
Whether the definition/implementation is correct or not, I'm not thinking about it. What I see is that, if we don't be careful (about the coordinates of points) both of the Closed Polyline and the Polygon intersect. And there isn't (apparently) any difference between them in practice! What the Stroustrup will say in this case!
I don't agree with that. Definition of Polygon is reasonable. Implementation of Polygon fails to fulfil the promise of the definition for that special input.
Simple errata for example code is hardly a challenge. Wrong tone of correspondence can be.