Thunderbots Project
Loading...
Searching...
No Matches
field.h
1#pragma once
2
3#include "proto/world.pb.h"
4#include "software/geom/circle.h"
5#include "software/geom/point.h"
6#include "software/geom/rectangle.h"
7#include "software/util/make_enum/make_enum.hpp"
8
9typedef enum
10{
11 POS_X, // positive X side according to vision
12 NEG_X // negative X side
13} FieldSide;
14
35class Field
36{
37 public:
44
51
58 static Field createField(TbotsProto::FieldType field_type);
59
60 Field() = delete;
61
80 explicit Field(double field_x_length, double field_y_length, double defense_x_length,
81 double defense_y_length, double goal_x_length, double goal_y_length,
82 double boundary_buffer_size, double center_circle_radius);
83
94 explicit Field(const TbotsProto::Field &field_proto);
95
101 double xLength() const;
102
109 double totalXLength() const;
110
116 double yLength() const;
117
124 double totalYLength() const;
125
132 double goalYLength() const;
133
139 double goalXLength() const;
140
146 double centerCircleRadius() const;
147
153 Circle centerCircle() const;
154
160 Point centerPoint() const;
161
168 Segment halfwayLine() const;
169
177 double defenseAreaYLength() const;
178
185 double defenseAreaXLength() const;
186
192 const Rectangle &friendlyDefenseArea() const;
193
199 const Rectangle &enemyDefenseArea() const;
200
206 Rectangle friendlyHalf() const;
207
214
221
227 Rectangle enemyHalf() const;
228
235
242
249 const Rectangle &fieldLines() const;
250
258 Rectangle fieldBoundary() const;
259
266
272 Point enemyGoalCenter() const;
273
279 const Rectangle &friendlyGoal() const;
280
286 const Rectangle &enemyGoal() const;
287
294
300 Point enemyPenaltyMark() const;
301
307 Point friendlyCornerPos() const;
308
314 Point friendlyCornerNeg() const;
315
321 Point enemyCornerPos() const;
322
328 Point enemyCornerNeg() const;
329
336
343
349 Point enemyGoalpostPos() const;
350
356 Point enemyGoalpostNeg() const;
357
364 double boundaryMargin() const;
365
371 bool pointInFriendlyDefenseArea(const Point &p) const;
372
378 bool pointInEnemyDefenseArea(const Point &p) const;
379
386 bool pointInFriendlyHalf(const Point &p) const;
387
394 bool pointInEnemyHalf(const Point &p) const;
395
406 bool pointInFriendlyCorner(const Point &p, double radius) const;
407
418 bool pointInEnemyCorner(const Point &p, double radius) const;
419
426 bool operator==(const Field &other) const;
427
434 bool operator!=(const Field &other) const;
435
436 private:
437 // The length of the playable field (between the goal lines) in metres
438 double field_x_length_;
439 // The width of the playable field (between the sidelines) in metres
440 double field_y_length_;
441 // The length of the defense area in metres
442 double defense_x_length_;
443 // The width of the defense area in metres
444 double defense_y_length_;
445 // How "deep" the goal is along the x-axis in metres
446 double goal_x_length_;
447 // The width of the goal (between the goalposts) in metres
448 double goal_y_length_;
449 // The width of the boundary (between the edge of the marked field lines and the
450 // physical border around the field) in metres
451 double boundary_buffer_size_;
452 // The radius of the center circle in metres
453 double center_circle_radius_;
454 // The x-coordinate distance from the goal centre to the penalty mark
455 double goal_centre_to_penalty_mark_;
456 // The following are used for caching to improve performance
457 Rectangle enemy_defense_area_;
458 Rectangle friendly_defense_area_;
459 Rectangle field_lines_;
460 Rectangle enemy_goal_;
461 Rectangle friendly_goal_;
462};
463
464namespace std
465{
466 // Implements the std::less function so Field can be used as the key in data
467 // structures, such as std::map. See:
468 // https://stackoverflow.com/questions/42762633/why-is-stdless-better-than and
469 // https://en.cppreference.com/w/cpp/utility/functional/less
470 template <>
471 struct less<Field>
472 {
473 bool operator()(const Field &lhs, const Field &rhs) const
474 {
475 return lhs.friendlyDefenseArea().halfPerimeter() +
477 lhs.fieldLines().halfPerimeter() +
481 rhs.fieldLines().halfPerimeter() +
483 }
484 };
485} // namespace std
Definition circle.h:10
Definition field.h:36
Point friendlyCornerNeg() const
Definition field.cpp:227
Rectangle friendlyHalf() const
Definition field.cpp:128
Point friendlyGoalpostPos() const
Definition field.cpp:242
Rectangle friendlyPositiveYQuadrant() const
Definition field.cpp:133
double yLength() const
Definition field.cpp:83
Rectangle fieldBoundary() const
Definition field.cpp:163
Point friendlyCornerPos() const
Definition field.cpp:222
bool pointInFriendlyHalf(const Point &p) const
Definition field.cpp:277
static Field createField(TbotsProto::FieldType field_type)
Definition field.cpp:23
double boundaryMargin() const
Definition field.cpp:262
const Rectangle & enemyDefenseArea() const
Definition field.cpp:123
double goalYLength() const
Definition field.cpp:98
Point enemyGoalpostNeg() const
Definition field.cpp:257
bool pointInFriendlyDefenseArea(const Point &p) const
Definition field.cpp:267
double centerCircleRadius() const
Definition field.cpp:170
Point friendlyPenaltyMark() const
Definition field.cpp:210
Rectangle enemyPositiveYQuadrant() const
Definition field.cpp:148
Segment halfwayLine() const
Definition field.cpp:185
Point enemyCornerNeg() const
Definition field.cpp:237
const Rectangle & fieldLines() const
Definition field.cpp:158
bool pointInFriendlyCorner(const Point &p, double radius) const
Definition field.cpp:287
double defenseAreaXLength() const
Definition field.cpp:113
Rectangle friendlyNegativeYQuadrant() const
Definition field.cpp:138
bool operator!=(const Field &other) const
Definition field.cpp:313
bool pointInEnemyDefenseArea(const Point &p) const
Definition field.cpp:272
double totalYLength() const
Definition field.cpp:93
Rectangle enemyNegativeYQuadrant() const
Definition field.cpp:153
Point enemyGoalCenter() const
Definition field.cpp:195
bool pointInEnemyCorner(const Point &p, double radius) const
Definition field.cpp:294
const Rectangle & enemyGoal() const
Definition field.cpp:205
Point friendlyGoalpostNeg() const
Definition field.cpp:247
Point enemyPenaltyMark() const
Definition field.cpp:216
double xLength() const
Definition field.cpp:78
double totalXLength() const
Definition field.cpp:88
Rectangle enemyHalf() const
Definition field.cpp:143
bool operator==(const Field &other) const
Definition field.cpp:301
static Field createSSLDivisionBField()
Definition field.cpp:7
double goalXLength() const
Definition field.cpp:103
double defenseAreaYLength() const
Definition field.cpp:108
const Rectangle & friendlyDefenseArea() const
Definition field.cpp:118
Point friendlyGoalCenter() const
Definition field.cpp:190
Circle centerCircle() const
Definition field.cpp:175
bool pointInEnemyHalf(const Point &p) const
Definition field.cpp:282
Point enemyCornerPos() const
Definition field.cpp:232
const Rectangle & friendlyGoal() const
Definition field.cpp:200
Point centerPoint() const
Definition field.cpp:180
Point enemyGoalpostPos() const
Definition field.cpp:252
static Field createSSLDivisionAField()
Definition field.cpp:15
Definition point.h:14
Definition rectangle.h:10
double halfPerimeter() const
Definition rectangle.cpp:22
Definition segment.h:7