// Written and (C) by Francois Fleuret
// Contact <francois.fleuret@idiap.ch> for comments & bug reports
+#include <iostream>
+
#include <cmath>
#include "polygon.h"
+using namespace std;
+
static const scalar_t dl = 20.0;
static const scalar_t repulsion_constant = 0.2;
static const scalar_t dissipation = 0.5;
return new Polygon(_mass, _red, _green, _blue, _relative_x, _relative_y, _nb_vertices);
}
+#ifdef XFIG_SUPPORT
void Polygon::color_xfig(XFigTracer *tracer) {
tracer->add_color(int(255 * _red), int(255 * _green), int(255 * _blue));
}
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) {
}
#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(Canvas *canvas) {
+ canvas->set_drawing_color(_red, _green, _blue);
+ canvas->draw_polygon(1, _nb_vertices, _x, _y);
}
-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);
+void Polygon::draw_contours(Canvas *canvas) {
+ canvas->set_drawing_color(0.0, 0.0, 0.0);
+ canvas->draw_polygon(0, _nb_vertices, _x, _y);
}
-#endif
void Polygon::set_vertex(int k, scalar_t x, scalar_t y) {
_relative_x[k] = x;
_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;