diff --git a/rj_geometry/include/rj_geometry/stadium_shape.hpp b/rj_geometry/include/rj_geometry/stadium_shape.hpp index dba27e92ebf..0513aeac1d0 100644 --- a/rj_geometry/include/rj_geometry/stadium_shape.hpp +++ b/rj_geometry/include/rj_geometry/stadium_shape.hpp @@ -24,11 +24,28 @@ class StadiumShape : public Shape { init(c1, c2, r); } + StadiumShape(const StadiumShape& other) { + for (const auto& shape : other.subshapes_) { + std::shared_ptr itr_shape = std::shared_ptr(shape->clone()); + subshapes_.push_back(itr_shape); + } + drawshapes_ = other.drawshapes_; + } + [[nodiscard]] Shape* clone() const override; [[nodiscard]] bool contains_point(Point pt) const override; [[nodiscard]] bool near_point(Point pt, float threshold) const override; + using const_iterator = std::vector>::const_iterator; + using iterator = std::vector>::iterator; + + [[nodiscard]] const_iterator begin() const { return subshapes_.begin(); } + [[nodiscard]] const_iterator end() const { return subshapes_.end(); } + + iterator begin() { return subshapes_.begin(); } + iterator end() { return subshapes_.end(); } + [[nodiscard]] const std::vector>& subshapes() const { return subshapes_; } @@ -37,6 +54,42 @@ class StadiumShape : public Shape { return drawshapes_; } + std::shared_ptr operator[](unsigned int index) { + return subshapes_[index]; + } + + std::shared_ptr operator[](unsigned int index) const { + return subshapes_[index]; + } + + template + [[nodiscard]] bool hit(const T& obj) const { + for (const auto& it : *this) { + if (it->hit(obj)) { + return true; + } + } + + return false; + } + + [[nodiscard]] bool hit(Point pt) const override { return hit(pt); } + + [[nodiscard]] bool hit(const Segment& seg) const override { + return hit(seg); + } + + std::string to_string() override { + std::stringstream str; + str << "StadiumShape<"; + for (auto& subshape : subshapes_) { + str << subshape->to_string() << ", "; + } + str << ">"; + + return str.str(); + } + protected: void init(Point c1, Point c2, float r); diff --git a/soccer/src/soccer/debug_drawer.cpp b/soccer/src/soccer/debug_drawer.cpp index 1c34cc09035..f36784c88f0 100644 --- a/soccer/src/soccer/debug_drawer.cpp +++ b/soccer/src/soccer/debug_drawer.cpp @@ -48,12 +48,6 @@ void DebugDrawer::draw_circle(rj_geometry::Point center, float radius, const QCo dbg->set_color(color(qc)); } -// void DebugDrawer::draw_stadium(rj_geometry::StadiumShape& stadium, const QColor& qc, const QString& layer) { -// this->draw_circle(stadium.drawshapes()[0], qc, layer); -// this->draw_polygon(stadium.drawshapes()[1], qc, layer); -// this->draw_circle(stadium.drawshapes()[2], qc, layer); -// } - void DebugDrawer::draw_arc(const rj_geometry::Arc& arc, const QColor& qc, const QString& layer) { Packet::DebugArc* dbg = log_frame_.add_debug_arcs(); dbg->set_layer(find_debug_layer(layer)); diff --git a/soccer/src/soccer/debug_drawer.hpp b/soccer/src/soccer/debug_drawer.hpp index 495d8e9c73a..97a35245147 100644 --- a/soccer/src/soccer/debug_drawer.hpp +++ b/soccer/src/soccer/debug_drawer.hpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -79,10 +78,6 @@ class DebugDrawer { const QColor& qw = Qt::black, const QString& layer = QString()); - // void draw_stadium(rj_geometry::StadiumShape& stadium, - // const QColor& qc = Qt::black, - // const QString& layer = QString()); - /** * Fill the given log frame with the current debug drawing information, * and reset our current debug drawing data for the next cycle. diff --git a/soccer/src/soccer/planning/planner/plan_request.cpp b/soccer/src/soccer/planning/planner/plan_request.cpp index 648576e2568..ec6819fce17 100644 --- a/soccer/src/soccer/planning/planner/plan_request.cpp +++ b/soccer/src/soccer/planning/planner/plan_request.cpp @@ -84,10 +84,9 @@ void fill_obstacles(const PlanRequest& in, rj_geometry::ShapeSet* out_static, rj_geometry::Point bp_point = maybe_bp_point.value(); rj_geometry::StadiumShape stadium = rj_geometry::StadiumShape{in.world_state->ball.position, bp_point, ball_obs.radius()}; - // for some reason adding the shared pointer below to our static obstacles breaks it, so we add the shape set it has instead. - // std::shared_ptr track_obs_ptr = std::make_shared(stadium); + std::shared_ptr track_obs_ptr = std::make_shared(stadium); - out_static->add(stadium.drawshapes()); + out_static->add(track_obs_ptr); if (in.debug_drawer != nullptr) { QColor draw_color = Qt::red;