#include "ellipse.h" #include "line.h" #include int ellipse::interval = 20; #ifndef pi #define pi 3.1415926535897 #endif ellipse::ellipse(const coordsys& s, const coordinate& _o, double _w, double _h) :shape(s),o(_o),width(_w),height(_h) { } // number of lines to make up an ellipse void ellipse::set_granularity(int g) { if (g>=8) { interval = g/4; } } void ellipse::draw(canvas& C) { coordinate P1,P2,P3,P4, OLDP1, OLDP2, OLDP3, OLDP4, INP; bool in = false; double rx,ry; double increment = pi/ (2.0*(double)interval); double a = 0; coordsys paper(0,0,C.width(),C.height()); OLDP1 = system.rotate(coordinate(o.x()+width/2,o.y()),o,center_angle); OLDP3 = system.rotate(coordinate(o.x()-width/2,o.y()),o,center_angle); OLDP2 = OLDP1; OLDP4 = OLDP3; for(int i = 0; i <= interval; i++) { rx = (cos(a)*width)/2.0; ry = (sin(a)*height)/2.0; a+=increment; P1 = system.rotate(coordinate(o.x()+rx,o.y()+ry),o,center_angle); P2 = system.rotate(coordinate(o.x()+rx,o.y()-ry),o,center_angle); P3 = system.rotate(coordinate(o.x()-rx,o.y()+ry),o,center_angle); P4 = system.rotate(coordinate(o.x()-rx,o.y()-ry),o,center_angle); if (rotate) { if (i == 0) { OLDP1 = system.rotate(P1,rotation_center,rotation_angle); OLDP2 = system.rotate(P2,rotation_center,rotation_angle); OLDP3 = system.rotate(P3,rotation_center,rotation_angle); OLDP4 = system.rotate(P4,rotation_center,rotation_angle); } P1 = system.rotate(P1,rotation_center,rotation_angle); P2 = system.rotate(P2,rotation_center,rotation_angle); P3 = system.rotate(P3,rotation_center,rotation_angle); P4 = system.rotate(P4,rotation_center,rotation_angle); } P1 = paper.map(system,P1); if (i==0) OLDP1 = paper.map(system,OLDP1); P2 = paper.map(system,P2); if (i==0) OLDP2 = paper.map(system,OLDP2); P3 = paper.map(system,P3); if (i==0) OLDP3 = paper.map(system,OLDP3); P4 = paper.map(system,P4); if (i==0) OLDP4 = paper.map(system,OLDP4); if (!in) { if (inside(P1,C)) { INP = P1; in = true; } else if (inside(P2,C)) { INP = P2; in = true; } else if (inside(P3,C)) { INP = P3; in = true; } else if (inside(P4,C)) { INP = P4; in = true; } } C.draw_line(round(OLDP1.x()),round(OLDP1.y()), round(P1.x()),round(P1.y()),pen_color,id); C.draw_line(round(OLDP2.x()),round(OLDP2.y()), round(P2.x()),round(P2.y()),pen_color,id); C.draw_line(round(OLDP3.x()),round(OLDP3.y()), round(P3.x()),round(P3.y()),pen_color,id); C.draw_line(round(OLDP4.x()),round(OLDP4.y()), round(P4.x()),round(P4.y()),pen_color,id); OLDP1 = P1; OLDP2 = P2; OLDP3 = P3; OLDP4 = P4; } C.draw_line(round(OLDP1.x()),round(OLDP1.y()), round(OLDP3.x()),round(OLDP3.y()),pen_color,id); C.draw_line(round(OLDP2.x()),round(OLDP2.y()), round(OLDP4.x()),round(OLDP4.y()),pen_color,id); coordinate fo(o); if (rotate) { fo = system.rotate(o,rotation_center,rotation_angle); } fo = paper.map(system,fo); if (filled) { if (!in) if(inside(fo,C)) in = true; if (in) { if (!inside(fo,C)) { fo = find_in(INP,fo,C); } C.fill_area(round(fo.x()),round(fo.y()),id,fill_color); } } }