RaidZeroLib
Coroutine robot framework for VEX V5
Loading...
Searching...
No Matches
DiscretePath.hpp
1#pragma once
2#include <cassert>
3#include <concepts>
4#include <ranges>
5#include <vector>
6
7#include "RaidZeroLib/api/Geometry/Point.hpp"
8
9namespace rz {
10
26 public:
28 using const_reference = const Point&;
29 using container_type = std::vector<Point>;
30 using size_type = std::size_t;
31 using const_iterator = std::vector<Point>::const_iterator;
32 using const_reverse_iterator = std::vector<Point>::const_reverse_iterator;
33
40 explicit DiscretePath(std::initializer_list<Point> waypoints);
41
54 template <std::ranges::input_range Range>
55 requires(!std::same_as<std::remove_cvref_t<Range>, DiscretePath> &&
56 std::convertible_to<std::ranges::range_reference_t<Range>, Point>)
57 explicit DiscretePath(Range&& range) : path(std::ranges::begin(range), std::ranges::end(range)) {
58 assert(!path.empty() && "DiscretePath cannot be empty");
59 }
60
68
75 DiscretePath operator+(const Point& rhs) const;
76
78 const_iterator begin() const noexcept;
79
81 const_iterator end() const noexcept;
82
85
87 const_reverse_iterator rend() const noexcept;
88
94 const_reference operator[](size_type index) const noexcept;
95
97 const_reference front() const noexcept;
98
100 const_reference back() const noexcept;
101
113 Curvature getCurvature(std::size_t index) const noexcept;
114
116 size_type size() const noexcept;
117
118 private:
119 std::vector<Point> path;
120};
121
134 const Point& point);
135} // namespace rz
Immutable sequence of 2D waypoints with unit-safe geometry.
Definition DiscretePath.hpp:25
DiscretePath(Range &&range)
Constructs a path from any C++20 input range of points.
Definition DiscretePath.hpp:57
Curvature getCurvature(std::size_t index) const noexcept
Signed curvature at vertex index using the circumcircle of three consecutive points.
size_type size() const noexcept
Number of waypoints.
const_reverse_iterator rend() const noexcept
Reverse end iterator (one before the first).
const Point & const_reference
Definition DiscretePath.hpp:28
Point value_type
Definition DiscretePath.hpp:27
const_iterator end() const noexcept
Forward end iterator (one past the last).
std::vector< Point > container_type
Definition DiscretePath.hpp:29
std::vector< Point >::const_iterator const_iterator
Definition DiscretePath.hpp:31
std::vector< Point >::const_reverse_iterator const_reverse_iterator
Definition DiscretePath.hpp:32
DiscretePath operator+(const DiscretePath &rhs) const
Concatenates two paths (this followed by rhs).
const_reference back() const noexcept
Last waypoint.
DiscretePath(std::initializer_list< Point > waypoints)
Constructs a path from a brace-initialized list of points.
DiscretePath operator+(const Point &rhs) const
Appends a single waypoint to the end of the path.
std::size_t size_type
Definition DiscretePath.hpp:30
const_reverse_iterator rbegin() const noexcept
Reverse begin iterator (last element).
const_reference front() const noexcept
First waypoint.
const_iterator begin() const noexcept
Forward begin iterator.
Immutable 2D point / vector with unit-safe Cartesian coordinates.
Definition Point.hpp:21
DiscretePath::const_iterator closestPoint(DiscretePath::const_iterator begin, DiscretePath::const_iterator end, const Point &point)
Iterator-based closest-point search by Euclidean distance.
au::QuantityD< au::Inverse< au::Meters > > Curvature
Definition Units.hpp:11
Definition DriverControl.hpp:11