#include "rectangle.h" #include "line.h" rectangle::rectangle(const coordsys& s,const coordinate& _o,double w,double h) : shape(s),o(_o),width(w),height(h) { } void rectangle::draw(canvas& C) { coordinate a(o.x()-width/2,o.y()+height/2), b(o.x()+width/2,o.y()+height/2), c(o.x()+width/2,o.y()-height/2), d(o.x()-width/2,o.y()-height/2); a = system.rotate(a,o,center_angle); b = system.rotate(b,o,center_angle); c = system.rotate(c,o,center_angle); d = system.rotate(d,o,center_angle); coordinate oprime(o); if (rotate) { a = system.rotate(a,rotation_center,rotation_angle); b = system.rotate(b,rotation_center,rotation_angle); c = system.rotate(c,rotation_center,rotation_angle); d = system.rotate(d,rotation_center,rotation_angle); oprime = system.rotate(o,rotation_center,rotation_angle); } coordsys paper(0,0,C.width(),C.height()); a = paper.map(system,a); b = paper.map(system,b); c = paper.map(system,c); d = paper.map(system,d); C.draw_line(round(a.x()),round(a.y()), round(b.x()),round(b.y()),pen_color,id); C.draw_line(round(b.x()),round(b.y()), round(c.x()),round(c.y()),pen_color,id); C.draw_line(round(c.x()),round(c.y()), round(d.x()),round(d.y()),pen_color,id); C.draw_line(round(d.x()),round(d.y()), round(a.x()),round(a.y()),pen_color,id); if (filled) { bool in = false; oprime = paper.map(system,oprime); if (!inside(oprime,C)) { coordinate p; if (inside(a,C)) { oprime = find_in(a,oprime,C); in = true; } else if (inside(b,C)) { oprime = find_in(b,oprime,C); in = true; } else if (inside(c,C)) { oprime = find_in(c,oprime,C); in = true; } else if (inside(d,C)) { oprime = find_in(d,oprime,C); in = true; } else if (intersects(a,b,C,p)) { oprime = find_in(p,oprime,C); in = true; } else if (intersects(b,c,C,p)) { oprime = find_in(p,oprime,C); in = true; } else if (intersects(c,d,C,p)) { oprime = find_in(p,oprime,C); in = true; } else if (intersects(d,a,C,p)) { oprime = find_in(p,oprime,C); in = true; } } else { // inside in = true; } if (in) C.fill_area(round(oprime.x()),round(oprime.y()),id,fill_color); } }