In the PPP (http://www.stroustrup.com/programming1.html) book, Stroustrup has said the following subject about the Circle:
"The main peculiarity of circle's implementation is that the point stored is not the center, but the top left corner of the square bounding the circle."
And these are the definitions and implementations from the book:
struct Circle : Shape {
Circle(Point p, int rr) // center and radius
:r(rr) { add(Point(p.x-r,p.y-r)); }
void draw_lines() const {
if(color.visibility())
fl_arc(point(0).x, point(0).y,r+r,r+r,0,360);
}
Point center() const {
return Point(point(0).x+r,point(0).y+r);
}
int radius() const { return r; }
void set_radius(int rr) { r=rr;}
private:
int r;
};
So the point we give the program is the top-left corner (of the square bounding the circle) and is not the center of the circle. Please look at this simple code:
#include <Simple_window.h>
int main()
{
using namespace std;
Simple_window win(Point(100,100), 600, 400, "test2");
Point t(200,200);
Mark m(t,'x');
Circle c(t,100);
win.attach(c);
win.attach(m);
win.wait_for_button();
}
As you see, I first gave the window a point (here the t) and used that point to be used for the circle shape, but if you run that code (I haven't such reputation to upload its image!), you can see, that point I gave it (the t) is not the top-left corner, it's just the center of the circle, on the contrary of his saying! What is the problem please?