2023-03-14 21:46:36 +01:00
|
|
|
#include "polygons.h"
|
|
|
|
|
2023-03-14 23:10:31 +01:00
|
|
|
#include "polygon_generator.h"
|
|
|
|
|
2023-03-14 21:46:36 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
polygon* polygons = nullptr;
|
2023-03-14 23:10:31 +01:00
|
|
|
uint n_polygons = 3;
|
2023-03-14 21:46:36 +01:00
|
|
|
|
|
|
|
void polygons_init_state() {
|
|
|
|
polygons = new polygon[n_polygons];
|
|
|
|
|
2023-03-14 23:10:31 +01:00
|
|
|
polygons[0] = poly_generate::triangle(200, 200, 30).set_center({300, 200});
|
|
|
|
polygons[1] = poly_generate::square(200).set_center({100, 400});
|
|
|
|
polygons[2] = poly_generate::rectangle(200, 100).set_center({400, 400});
|
2023-03-14 21:46:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void polygon::draw(cairo_t* cr) const {
|
2023-03-14 23:10:31 +01:00
|
|
|
const vec2d& center = this->center;
|
2023-03-14 21:46:36 +01:00
|
|
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
|
|
|
|
2023-03-14 23:10:31 +01:00
|
|
|
for (auto& point : this->points)
|
2023-03-14 21:46:36 +01:00
|
|
|
cairo_line_to(cr, center.x + point.x, center.y + point.y);
|
2023-03-14 23:10:31 +01:00
|
|
|
cairo_line_to(
|
|
|
|
cr, center.x + this->points[0].x, center.y + this->points[0].y);
|
2023-03-14 21:46:36 +01:00
|
|
|
cairo_stroke(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void polygons_draw(cairo_t* cr) {
|
|
|
|
for (const polygon* p = polygons; p != polygons + n_polygons; ++p)
|
|
|
|
p->draw(cr);
|
|
|
|
}
|