#include "triangle.h" #include "line.h" triangle::triangle(const coordsys& s, const coordinate& _a, const coordinate& _b, const coordinate& _c) : shape(s),ap(_a),bp(_b),cp(_c) { } void triangle::draw(canvas& C) { coordinate a(ap),b(bp),c(cp); // calculate center coordinate o((ap.x()+bp.x()+cp.x())/3,(ap.y()+bp.y()+cp.y())/3); a = system.rotate(a,o,center_angle); b = system.rotate(b,o,center_angle); c = system.rotate(c,o,center_angle); 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); o = 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); 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(a.x()),round(a.y()),pen_color,id); if (filled) { o = paper.map(system,o); coordinate p; bool in = false; if (!inside(o,C)) { if (inside(a,C)) { o = find_in(a,o,C); in = true; } else if (inside(b,C)) { o = find_in(b,o,C); in = true; } else if (inside(c,C)) { o = find_in(c,o,C); in = true; } else if (intersects(a,b,C,p)) { o = find_in(p,o,C); in = true; } else if (intersects(a,c,C,p)) { o = find_in(p,o,C); in = true; } else if (intersects(b,c,C,p)) { o = find_in(p,o,C); in = true; } } else { // inside in = true; } if (in) C.fill_area(round(o.x()),round(o.y()),id,fill_color); } }