tess 0.4.0
Performance-first tile and path simulation substrate
Loading...
Searching...
No Matches
path_view.h
1#pragma once
2
3#include <tess/core/shape.h>
4
5#include <cstddef>
6#include <span>
7#include <vector>
8
9namespace tess {
10
21class PathView {
22 public:
24 constexpr PathView() noexcept = default;
25
27 constexpr PathView(std::span<const Coord3> nodes) noexcept : nodes_(nodes) {}
28
30 PathView(const std::vector<Coord3>& nodes) noexcept : nodes_(nodes) {}
31
33 PathView(std::vector<Coord3>&&) = delete;
34
38 PathView(const std::vector<Coord3>&&) = delete;
39
41 [[nodiscard]] constexpr auto size() const noexcept -> std::size_t {
42 return nodes_.size();
43 }
44
45 [[nodiscard]] constexpr auto empty() const noexcept -> bool {
46 return nodes_.empty();
47 }
48
49 [[nodiscard]] constexpr auto operator[](std::size_t index) const noexcept
50 -> const Coord3& {
51 return nodes_[index];
52 }
53
54 [[nodiscard]] constexpr auto front() const noexcept -> const Coord3& {
55 return nodes_.front();
56 }
57
58 [[nodiscard]] constexpr auto back() const noexcept -> const Coord3& {
59 return nodes_.back();
60 }
61
62 [[nodiscard]] constexpr auto begin() const noexcept { return nodes_.begin(); }
63
65 [[nodiscard]] constexpr auto end() const noexcept { return nodes_.end(); }
66
70 [[nodiscard]] constexpr auto data() const noexcept -> const Coord3* {
71 return nodes_.data();
72 }
73
75 [[nodiscard]] constexpr auto span() const noexcept
76 -> std::span<const Coord3> {
77 return nodes_;
78 }
79
86 [[nodiscard]] constexpr auto suffix(std::size_t offset) const noexcept
87 -> PathView {
88 const auto clamped = offset < nodes_.size() ? offset : nodes_.size();
89 return PathView{nodes_.subspan(clamped)};
90 }
91
92 private:
93 std::span<const Coord3> nodes_{};
94};
95
96} // namespace tess
constexpr auto span() const noexcept -> std::span< const Coord3 >
Definition path_view.h:75
PathView(const std::vector< Coord3 > &&)=delete
constexpr auto back() const noexcept -> const Coord3 &
Definition path_view.h:58
constexpr PathView() noexcept=default
constexpr auto empty() const noexcept -> bool
Definition path_view.h:45
constexpr auto front() const noexcept -> const Coord3 &
Definition path_view.h:54
constexpr auto size() const noexcept -> std::size_t
Definition path_view.h:41
constexpr auto data() const noexcept -> const Coord3 *
Definition path_view.h:70
constexpr auto operator[](std::size_t index) const noexcept -> const Coord3 &
Definition path_view.h:49
PathView(const std::vector< Coord3 > &nodes) noexcept
Definition path_view.h:30
constexpr auto begin() const noexcept
Definition path_view.h:62
PathView(std::vector< Coord3 > &&)=delete
constexpr auto end() const noexcept
Definition path_view.h:65
constexpr auto suffix(std::size_t offset) const noexcept -> PathView
Definition path_view.h:86
Definition shape.h:30