2 * SPDX-FileCopyrightText: 2021 Jiri Vlasak <jiri.vlasak.2@cvut.cz>
4 * SPDX-License-Identifier: GPL-3.0-only
9 #define CUTE_C2_IMPLEMENTATION
15 RRTExt2::collide(RRTNode const& n)
17 this->c2x_bc_.p.x = n.x();
18 this->c2x_bc_.p.y = n.y();
19 this->c2x_bc_.r.c = cos(n.h());
20 this->c2x_bc_.r.s = sin(n.h());
21 for (auto& o: this->c2_obstacles_) {
22 if (c2PolytoPoly(&this->c2_bc_, &this->c2x_bc_, &o, NULL)) {
30 RRTExt2::collide_steered()
33 for (auto& n: this->_steered) {
34 if (this->collide(n)) {
39 this->_steered.erase(this->_steered.begin() + i, this->_steered.end());
40 return this->_steered.size() == 0;
43 RRTExt2::RRTExt2() : RRTS()
45 this->c2_bc_.count = 4;
46 this->c2_bc_.verts[0].x = this->_bc.lfx();
47 this->c2_bc_.verts[0].y = this->_bc.lfy();
48 this->c2_bc_.verts[1].x = this->_bc.lrx();
49 this->c2_bc_.verts[1].y = this->_bc.lry();
50 this->c2_bc_.verts[2].x = this->_bc.rrx();
51 this->c2_bc_.verts[2].y = this->_bc.rry();
52 this->c2_bc_.verts[3].x = this->_bc.rfx();
53 this->c2_bc_.verts[3].y = this->_bc.rfy();
60 this->c2_bc_.count = 4;
61 this->c2_bc_.verts[0].x = this->_bc.lfx();
62 this->c2_bc_.verts[0].y = this->_bc.lfy();
63 this->c2_bc_.verts[1].x = this->_bc.lrx();
64 this->c2_bc_.verts[1].y = this->_bc.lry();
65 this->c2_bc_.verts[2].x = this->_bc.rrx();
66 this->c2_bc_.verts[2].y = this->_bc.rry();
67 this->c2_bc_.verts[3].x = this->_bc.rfx();
68 this->c2_bc_.verts[3].y = this->_bc.rfy();
72 RRTExt2::json(Json::Value jvi)
75 assert(jvi["obst"] != Json::nullValue);
76 for (auto& o: jvi["obst"]) {
77 assert(o.size() < C2_MAX_POLYGON_VERTS);
79 c2tmp.count = o.size();
82 c2tmp.verts[i].x = c[0].asDouble();
83 c2tmp.verts[i].y = c[1].asDouble();
86 this->c2_obstacles_.push_back(c2tmp);