X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=polygon.cc;h=1d2b3dd434dd42d8ea44aa4fea79d354001b0c7e;hb=5609af651ece7980e4170c9bc0e99e35ed5c13cf;hp=75163cbe4ec6f60bb318d7c8098a87192e2082cd;hpb=ba46b057f3e2613a86f2dea7fa8022990482c735;p=universe.git diff --git a/polygon.cc b/polygon.cc index 75163cb..1d2b3dd 100644 --- a/polygon.cc +++ b/polygon.cc @@ -1,17 +1,6 @@ -//////////////////////////////////////////////////////////////////////////////// -// This program is free software; you can redistribute it and/or // -// modify it under the terms of the GNU General Public License // -// version 2 as published by the Free Software Foundation. // -// // -// This program is distributed in the hope that it will be useful, but // -// WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // -// General Public License for more details. // -// // -// Written and (C) by François Fleuret // -// Contact for comments & bug reports // -//////////////////////////////////////////////////////////////////////////////// +// Written and (C) by Francois Fleuret +// Contact for comments & bug reports #include #include "polygon.h" @@ -58,14 +47,16 @@ 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; +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); +} + +#ifdef X11_SUPPORT void Polygon::draw(SimpleWindow *window) { window->color(_red, _green, _blue); int x[_nb_vertices], y[_nb_vertices]; @@ -82,10 +73,39 @@ void Polygon::draw_contours(SimpleWindow *window) { x[n] = int(_x[n]); y[n] = int(_y[n]); } - window->color(0.0, 0.0, 0.0); - for(int n = 0; n < _nb_vertices; n++) + // window->color(0.0, 0.0, 0.0); + 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 + +#ifdef CAIRO_SUPPORT +void Polygon::draw(cairo_t* context_resource) { + cairo_set_line_width(context_resource, 1.0); + cairo_set_source_rgb (context_resource, _red, _green, _blue); + cairo_move_to(context_resource, _x[0], _y[0]); + for(int n = 0; n < _nb_vertices; n++) { + cairo_line_to(context_resource, _x[n], _y[n]); + } + cairo_close_path(context_resource); + cairo_stroke_preserve(context_resource); + cairo_fill(context_resource); +} + +void Polygon::draw_contours(cairo_t* context_resource) { + cairo_set_line_width(context_resource, 1.0); + // cairo_set_source_rgb (context_resource, 0.0, 0.0, 0.0); + cairo_set_source_rgb (context_resource, 1.0, 1.0, 1.0); + cairo_move_to(context_resource, _x[0], _y[0]); + for(int n = 0; n < _nb_vertices; n++) { + cairo_line_to(context_resource, _x[n], _y[n]); + } + cairo_close_path(context_resource); + cairo_stroke(context_resource); +} +#endif void Polygon::set_vertex(int k, scalar_t x, scalar_t y) { _relative_x[k] = x; @@ -157,7 +177,7 @@ void Polygon::triangularize(int &nt, int nb, int *index) { _relative_x[index[(k+1)%nb]] - _relative_x[index[m]], _relative_y[index[(k+1)%nb]] - _relative_y[index[m]]); - if(a1 * a2 > 0 && best_split < 0 || (abs(a1 - a2) < best_split)) { + if((a1 * a2 > 0 && best_split < 0) || (abs(a1 - a2) < best_split)) { best_n = n; best_m = m; best_split = abs(a1 - a2); } @@ -499,4 +519,3 @@ bool Polygon::collide(Polygon *p) { return false; } -