X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=polygon.cc;h=9e55d80e179396cce8b7fa084c4938f37c15f022;hb=4754eda0991874c388d8a93517d579ed447d81e9;hp=6f980bd36be3d9b4438b62bf31dfe81044417e13;hpb=2e613b166590300fdc80bb324903ded4a0cb0403;p=universe.git diff --git a/polygon.cc b/polygon.cc index 6f980bd..9e55d80 100644 --- a/polygon.cc +++ b/polygon.cc @@ -47,14 +47,18 @@ Polygon *Polygon::clone() { return new Polygon(_mass, _red, _green, _blue, _relative_x, _relative_y, _nb_vertices); } -void Polygon::print_fig(ostream &os) { - os << "2 2 0 1 0 7 50 -1 20 0.000 0 0 -1 0 0 " << _nb_vertices + 1 << endl; - os << " "; - for(int n = 0; n < _nb_vertices; n++) os << " " << int(_x[n]*10) << " " << int(_y[n]*10); - os << " " << int(_x[0]*10) << " " << int(_y[0]*10); - os << endl; +#ifdef XFIG_SUPPORT +void Polygon::color_xfig(XFigTracer *tracer) { + tracer->add_color(int(255 * _red), int(255 * _green), int(255 * _blue)); } +void Polygon::print_xfig(XFigTracer *tracer) { + tracer->draw_polygon(int(255 * _red), int(255 * _green), int(255 * _blue), + _nb_vertices, _x, _y); +} +#endif + +#ifdef X11_SUPPORT void Polygon::draw(SimpleWindow *window) { window->color(_red, _green, _blue); int x[_nb_vertices], y[_nb_vertices]; @@ -72,8 +76,21 @@ void Polygon::draw_contours(SimpleWindow *window) { y[n] = int(_y[n]); } window->color(0.0, 0.0, 0.0); - for(int n = 0; n < _nb_vertices; n++) + // window->color(1.0, 1.0, 1.0); + for(int n = 0; n < _nb_vertices; n++) { window->draw_line(x[n], y[n], x[(n+1)%_nb_vertices], y[(n+1)%_nb_vertices]); + } +} +#endif + +void Polygon::draw(Canvas *canvas) { + canvas->set_drawing_color(_red, _green, _blue); + canvas->draw_polygon(1, _nb_vertices, _x, _y); +} + +void Polygon::draw_contours(Canvas *canvas) { + canvas->set_drawing_color(0.0, 0.0, 0.0); + canvas->draw_polygon(0, _nb_vertices, _x, _y); } void Polygon::set_vertex(int k, scalar_t x, scalar_t y) { @@ -178,7 +195,9 @@ void Polygon::initialize(int nb_polygons) { _nb_polygons = nb_polygons; - a = _relative_x[_nb_vertices - 1] * _relative_y[0] - _relative_x[0] * _relative_y[_nb_vertices - 1]; + a = _relative_x[_nb_vertices - 1] * _relative_y[0] + - _relative_x[0] * _relative_y[_nb_vertices - 1]; + for(int n = 0; n < _nb_vertices - 1; n++) a += _relative_x[n] * _relative_y[n+1] - _relative_x[n+1] * _relative_y[n]; a *= 0.5; @@ -488,4 +507,3 @@ bool Polygon::collide(Polygon *p) { return false; } -