3#include "TinyRobotics/maps/IMap.h"
4#include "TinyRobotics/maps/PathSegment.h"
5#include "TinyRobotics/utils/AllocatorPSRAM.h"
7namespace tinyrobotics {
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27template <
typename CoordinateT =
Coordinate<
float>>
29 decltype(std::declval<CoordinateT>().x)>::
type> {
33 void addSegment(
const CoordinateT& from,
const CoordinateT& to,
34 bool directed =
false) {
35 auto distance = from.distance(to);
36 PathSegment<CoordinateT> segment{from, to, distance,
38 segments.push_back(segment);
42 segments.push_back(segment);
45 std::vector<PathSegment<CoordinateT>> getSegments(
46 const CoordinateT& from)
const {
47 std::vector<PathSegment<CoordinateT>> result;
48 for (
const auto& seg : segments) {
49 if (seg.from == from) {
50 result.push_back(seg);
53 for (
const auto& seg : segments) {
54 if (seg.to == from && !seg.directed) {
56 std::swap(reverse_seg.from, reverse_seg.to);
57 result.push_back(reverse_seg);
64 std::vector<CoordinateT> getNeighbors(CoordinateT from)
const override {
65 std::vector<CoordinateT> neighbors;
66 for (
const auto& seg : segments) {
67 if (seg.from == from) {
68 neighbors.push_back(seg.to);
70 if (seg.to == from && !seg.directed) {
71 neighbors.push_back(seg.from);
78 bool isValid(
const Coordinate<
float>& coord)
const override {
80 for (
const auto& seg : segments) {
81 if (seg.from == coord || seg.to == coord)
return true;
86 size_t size()
const {
return segments.size(); }
88 PathSegment<CoordinateT>& operator[](size_t index) {
return segments[index]; }
90 size_t writeTo(Print& out) {
return serializer.write(*
this, out); }
92 size_t readFrom(Stream& in) {
return serializer.read(*
this, in); }
94 void clear() { segments.clear(); }
100 PathMapSerializer<PathMap<CoordinateT>, CoordinateT> serializer;
Custom allocator that uses ESP32's PSRAM for memory allocation.
Definition: AllocatorPSRAM.h:21
A generic 3D coordinate class for robotics, navigation, and spatial calculations.
Definition: Coordinate.h:57
Abstract interface for neighbor queries in map-like data structures.
Definition: IMap.h:27
Represents a graph of valid path segments (edges) between coordinates (nodes).
Definition: PathMap.h:29
Represents a path segment (edge) between two coordinates in a graph.
Definition: PathSegment.h:26