From 398cae3b24fcff06d341e11b4f5671e93ee20b6a Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Wed, 17 May 2023 13:21:06 +0200 Subject: [PATCH] Added toString method to polygons, together with fields "label" and "collided_with" --- polygons.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/polygons.h b/polygons.h index edc3c59..8ccb6ae 100644 --- a/polygons.h +++ b/polygons.h @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -20,11 +21,13 @@ class polygon { std::vector points; double inertia; double mass; + std::string label; std::vector global_points = points; vec2d speed; double angular_speed; + std::unordered_set 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;