Added toString method to polygons, together with fields "label" and

"collided_with"
This commit is contained in:
Karma Riuk 2023-05-17 13:21:06 +02:00
parent 399949876f
commit 398cae3b24

View File

@ -5,6 +5,7 @@
#include <cmath>
#include <gtk/gtk.h>
#include <unordered_set>
#include <utility>
#include <vector>
@ -20,11 +21,13 @@ class polygon {
std::vector<vec2d> points;
double inertia;
double mass;
std::string label;
std::vector<vec2d> global_points = points;
vec2d speed;
double angular_speed;
std::unordered_set<polygon*> collided_with;
void draw(cairo_t* cr) const;
void draw_bounding_rect(cairo_t* cr) const;
@ -92,6 +95,17 @@ class polygon {
return vec2d{x, y} / points.size();
}
friend std::ostream& operator<<(std::ostream& os, polygon& p) {
vec2d c = p.centroid();
os << p.label << ": " << std::endl;
os << " mass: " << p.mass << std::endl;
os << " position: " << c << std::endl;
os << " angle: " << p.angle << std::endl;
os << " speed: " << p.speed << std::endl;
os << " angular speed: " << p.angular_speed << std::endl;
return os;
}
};
extern polygon* polygons;