148 this->cornerOne = hole.cornerOne;
149 this->cornerTwo = hole.cornerTwo;
150 this->foundHole = hole.foundHole;
151 this->phi = hole.phi;
152 this->threshold = hole.threshold;
153 this->x_translation_one = hole.x_translation_one;
154 this->y_translation_one = hole.y_translation_one;
155 this->x_translation_two = hole.x_translation_two;
156 this->y_translation_two = hole.y_translation_two;
157 this->holeSize = hole.holeSize;
159 this->points = std::make_unique<std::vector<Pose2D>>();
160 for (uint16_t i = 0; i < hole.points->size(); i++) {
161 this->points->push_back(hole.points->data()[i]);
163 this->pointHoles = std::make_unique<std::vector<Hole>>();
164 for (uint16_t i = 0; i < hole.pointHoles->size(); i++) {
165 this->pointHoles->push_back(hole.pointHoles->data()[i]);
171 this->points->push_back(position);
173 if (this->points->size() > 2) {
179 Pose2D perpendicularPosition;
184 if (fabs(this->points->at(0).getHeading() - this->points->at(1).getHeading()) < M_PI / 2) {
186 perpendicularPosition = this->points->at(2);
187 parallelOne = this->points->at(0);
188 parallelTwo = this->points->at(1);
191 else if (fabs(this->points->at(1).getHeading() - this->points->at(2).getHeading()) < M_PI / 2) {
193 perpendicularPosition = this->points->at(0);
194 parallelOne = this->points->at(1);
195 parallelTwo = this->points->at(2);
199 else if (fabs(this->points->at(0).getHeading() - this->points->at(2).getHeading()) < M_PI / 2) {
201 perpendicularPosition = this->points->at(1);
202 parallelOne = this->points->at(0);
203 parallelTwo = this->points->at(2);
206 if (parallelOne.
getX() > parallelTwo.
getX()) {
207 const Pose2D temp = parallelOne;
208 parallelOne = parallelTwo;
216 if (fabs(this->points->at(0).getHeading() + this->points->at(1).getHeading()) < 0.1 || fabs(fabs(this->points->at(0).getHeading()) - fabs(this->points->at(1).getHeading())) < 0.1) {
217 parallelOne = this->points->at(0);
219 parallelTwo = this->points->at(1);
220 perpendicularPosition = this->points->at(2);
223 else if (fabs(this->points->at(2).getHeading() + this->points->at(1).getHeading()) < 0.1 || fabs(fabs(this->points->at(2).getHeading()) - fabs(this->points->at(1).getHeading())) < 0.1) {
224 parallelOne = this->points->at(2);
226 parallelTwo = this->points->at(1);
227 perpendicularPosition = this->points->at(0);
230 else if (fabs(this->points->at(0).getHeading() + this->points->at(2).getHeading()) < 0.1 || fabs(fabs(this->points->at(0).getHeading()) - fabs(this->points->at(2).getHeading())) < 0.1) {
231 parallelOne = this->points->at(0);
233 parallelTwo = this->points->at(2);
234 perpendicularPosition = this->points->at(1);
238 this->points->clear();
247 double dx = (parallelTwo.
getX() - parallelOne.
getX());
248 double dy = (parallelTwo.
getY() - parallelOne.
getY());
249 if (fabs(dx) < 0.01) {
251 double xCornerOne = parallelOne.
getX();
252 double yCornerOne = perpendicularPosition.
getY();
253 cornerOne =
Pose2D(xCornerOne, yCornerOne);
254 oppositeCorner =
Pose2D(cornerOne);
259 else if (fabs(dy) < 0.01) {
260 double xCornerOne = perpendicularPosition.
getX();
261 double yCornerOne = parallelOne.
getY();
262 cornerOne =
Pose2D(xCornerOne, yCornerOne);
263 oppositeCorner =
Pose2D(cornerOne);
268 double m1 = (parallelTwo.
getY() - parallelOne.
getY()) / dx;
269 double b1 = - m1 * parallelOne.
getX() + parallelOne.
getY();
270 double m2 = - 1 / m1;
271 double b2 = -m2 * perpendicularPosition.
getX() + perpendicularPosition.
getY();
273 double xIntersection = (1 / m1 + m1) / (b2 - b1);
274 double yIntersection = xIntersection * m1 + b1;
275 cornerOne =
Pose2D(xIntersection, yIntersection);
278 double angleToOther = (cornerOne.
angleTo(parallelOne) + cornerOne.
angleTo(perpendicularPosition)) / 2;
279 oppositeCorner =
Pose2D(cornerOne);
284 this->cornerOne = cornerOne;
285 this->cornerTwo = oppositeCorner;
286 this->foundHole =
true;
290 Pose2D cornerOneNew(position);
293 Pose2D cornerTwoNew(position);
301 Hole hole(cornerOneNew, cornerTwoNew, 4);
302 this->pointHoles->push_back(hole);
397 if (posOne.
getX() < posTwo.
getX()) {
407 if (fabs(positionOne.
getX() - positionTwo.
getX()) < 0.05) {
410 return (((positionOne.
getX() > 0 && positionOne.
getX() < threshold) ||
411 (positionTwo.
getX() > 0 && positionTwo.
getX() < threshold)) &&
412 fmax(positionOne.
getY(), positionTwo.
getY()) > threshold &&
413 fmin(positionOne.
getY(), positionTwo.
getY()) < 0);
416 if (fabs(positionOne.
getY() - positionTwo.
getY()) < 0.05) {
418 return (((positionOne.
getY() > 0 && positionOne.
getY() < threshold) ||
419 (positionTwo.
getY() > 0 && positionTwo.
getY() < threshold)) &&
420 fmax(positionOne.
getX(), positionTwo.
getX()) > threshold &&
421 fmin(positionOne.
getX(), positionTwo.
getX()) < 0);
425 double m = (positionTwo.
getY() - positionOne.
getY()) / (positionTwo.
getX() - positionOne.
getX());
426 double b = positionOne.
getY() - (positionOne.
getX() * m);
430 double y2Check = m * positionOne.
getX() + b;
431 if ((b < threshold && b > 0) || (y2Check < threshold && y2Check > 0)) {
434 double xValueAtYIsZero = (-b / m);
435 double xValueATYIsThreshold = (threshold - b) / m;
436 return (xValueAtYIsZero > 0 && xValueAtYIsZero < threshold) ||
437 (xValueATYIsThreshold > 0 && xValueATYIsThreshold < threshold);
440 for (uint16_t i = 0; i < this->pointHoles->size(); i++) {
441 if (this->pointHoles->at(i).lineIntersectsHole(posOne, posTwo)) {