1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
struct Ellipse : Shape {
Ellipse(Point p, int ww, int hh) // center, min, and max distance from center
:w{ ww }, h{ hh } {
add(Point{ p.x - ww, p.y - hh });
}
void draw_lines() const;
Point center() const { return{ point(0).x + w, point(0).y + h }; }
Point focus1() const { return{ center().x + int(sqrt(double(w*w - h*h))), center().y }; }
Point focus2() const { return{ center().x - int(sqrt(double(w*w - h*h))), center().y }; }
void set_major(int ww) { w = ww; }
int major() const { return w; }
void set_minor(int hh) { h = hh; }
int minor() const { return h; }
private:
int w;
int h;
};
struct Arc : Ellipse {
Arc(Point p, int ww, int hh, double saa, double eaa)
: w{ ww }, h{ hh }, sa{ saa }, ea{ eaa } {
add(Point{ p.x - ww, p.y - hh });
}
void draw_lines() const;
private:
int w; // Width
int h; // Heigth
double sa; // Start angle
double ea; // End angle
};
|