[apriltags] Use map as internal data model (#4577)

This leaves the file format as a list, but internally will transform the collection of tags into a map on de/serialization. The serialization will probably happen once on startup, but the tag lookup can happen 100s of times a second. This honestly probably doesn't make too much of a performance hit since N is small, but this is a simple O(n) -> O(1) change for lookups.
This commit is contained in:
PJ Reiniger
2022-11-07 13:09:06 -05:00
committed by GitHub
parent b1b4c1e9e7
commit 5be5869b2f
3 changed files with 43 additions and 28 deletions

View File

@@ -6,6 +6,7 @@
#include <optional>
#include <string_view>
#include <unordered_map>
#include <vector>
#include <units/length.h>
@@ -101,7 +102,7 @@ class WPILIB_DLLEXPORT AprilTagFieldLayout {
bool operator!=(const AprilTagFieldLayout& other) const;
private:
std::vector<AprilTag> m_apriltags;
std::unordered_map<int, AprilTag> m_apriltags;
units::meter_t m_fieldLength;
units::meter_t m_fieldWidth;
bool m_mirror = false;