Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
cone.hpp
Go to the documentation of this file.
1#pragma once
2#include <cmath>
3#include <functional>
4#include <iostream>
5#include <string>
6
9
11
12struct Cone {
15 double certainty = 1.0;
16 static constexpr double equality_tolerance = 0.1;
17 bool is_large = false;
18 rclcpp::Time timestamp = rclcpp::Time(0); //< Last time the cone was updated
19 Cone() = default;
21 rclcpp::Time timestamp = rclcpp::Time(0));
22 Cone(double x, double y, const std::string& color = "unknown", double certainty = 1.0,
23 rclcpp::Time timestamp = rclcpp::Time(0));
24 friend bool operator==(const Cone& c1, const Cone& c2) {
27 }
28};
29
30} // namespace common_lib::structures
31
36namespace std {
37template <>
38struct hash<common_lib::structures::Cone> {
39 std::size_t operator()(const common_lib::structures::Cone& cone) const noexcept {
40 // Quantize position to improve compatibility with equality_tolerance
41 auto quantize = [](double value, double tolerance) { return std::round(value / tolerance); };
42 std::size_t x_hash = std::hash<double>()(
43 quantize(cone.position.x, common_lib::structures::Cone::equality_tolerance));
44 std::size_t y_hash = std::hash<double>()(
45 quantize(cone.position.y, common_lib::structures::Cone::equality_tolerance));
46 return x_hash ^ (y_hash << 1);
47 }
48};
49} // namespace std
Hash function for cones.
Definition cone.hpp:36
friend bool operator==(const Cone &c1, const Cone &c2)
Definition cone.hpp:24
common_lib::competition_logic::Color color
Definition cone.hpp:14
static constexpr double equality_tolerance
Definition cone.hpp:16
double euclidean_distance(const Position &other) const
Definition position.cpp:10
std::size_t operator()(const common_lib::structures::Cone &cone) const noexcept
Definition cone.hpp:39