5#include "../utility/module.hpp"
6#include "../geometry/module.hpp"
29 int32_t preferred = 0;
37 using reference = value_type&;
38 using const_reference = value_type
const&;
40 using iterator = std::vector<value_type>::iterator;
41 using const_iterator = std::vector<value_type>::const_iterator;
43 constexpr iterator
begin() noexcept
45 return _entries.begin();
48 constexpr iterator
end() noexcept
50 return _entries.end();
53 constexpr const_iterator
begin() const noexcept
55 return _entries.begin();
58 constexpr const_iterator
end() const noexcept
60 return _entries.end();
63 constexpr const_iterator cbegin() const noexcept
65 return _entries.cbegin();
68 constexpr const_iterator cend() const noexcept
70 return _entries.cend();
73 constexpr reference operator[](
size_t i)
noexcept
78 constexpr const_reference operator[](
size_t i)
const noexcept
83 constexpr void clear(
size_t n)
noexcept
86 _entries.resize(n + 1);
89 constexpr void fixup_properties() noexcept
91 for (
auto& entry : _entries) {
92 inplace_max(entry.maximum, entry.minimum);
93 inplace_clamp(entry.preferred, entry.minimum, entry.maximum);
109template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
110[[nodiscard]]
constexpr int32_t get_margins(It first, ItEnd last)
noexcept
111 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
129template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
130[[nodiscard]]
constexpr int32_t get_size(It first, ItEnd last)
noexcept
131 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
133 hilet margins = get_margins(first, last);
146template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
147[[nodiscard]]
constexpr int32_t get_minimum(It first, ItEnd last)
noexcept
148 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
150 hilet margins = get_margins(first, last);
152 return a + x.minimum;
163template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
164[[nodiscard]]
constexpr int32_t get_preferred(It first, ItEnd last)
noexcept
165 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
167 hilet margins = get_margins(first, last);
169 return a + x.preferred;
180template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
181[[nodiscard]]
constexpr int32_t get_maximum(It first, ItEnd last)
noexcept
182 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
184 hilet margins = get_margins(first, last);
186 return a + x.maximum;
196template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
197[[nodiscard]]
constexpr int8_t get_highest_priority(It first, ItEnd last)
noexcept
198 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
213template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
214[[nodiscard]]
constexpr int8_t get_lower_priority(It first, ItEnd last, int8_t base_priority)
noexcept
215 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
218 if (x.priority < base_priority) {
219 return std::max(a, x.priority);
240template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
241constexpr void set_priority(It first, ItEnd last, int8_t priority)
noexcept
242 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
246 for (
auto it = first; it != last; ++it) {
247 inplace_min(it->priority, priority);
258template<std::b
idirectional_iterator It, std::sized_sentinal_for<It> ItEnd>
259constexpr void set_margins(It first, ItEnd last, int8_t before_margin, int8_t after_margin)
noexcept
260 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
263 inplace_max(first->margin, before_margin);
264 inplace_max((last - 1)->margin, after_margin);
267template<std::forward_iterator It, std::sentinal_for<It> ItEnd, std::invocable<gr
id_axis::value_type&,
int32_t> Op>
268constexpr void add_to_extent(It first, ItEnd last, int32_t todo, int8_t priority, Op
const& op)
noexcept
269 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
276 return x.priority == priority;
279 if (
auto to_add = todo / count) {
280 for (
auto it = first; it != last and todo; ++it) {
281 if (it->priority == priority) {
289 to_add = todo < 0 ? -1 : 1;
290 for (
auto it = first; it != last and todo; ++it) {
291 if (it->priority == priority) {
298template<std::forward_iterator It, std::sentinal_for<It> ItEnd, std::invocable<gr
id_axis::value_type&,
int32_t> Op>
299constexpr void add_to_extent(It first, ItEnd last, int32_t todo, int8_t priority, Op
const& op)
noexcept
300 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
302 return add_to_extent(first, last, todo, get_highest_priority(first, last), op);
311template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
312constexpr void set_minimum(It first, ItEnd last, int32_t minimum)
noexcept
313 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
317 if (first + 1 == last) {
318 inplace_max(first->minimum, minimum);
321 hilet todo = minimum - get_minimum(first, last);
326 add_to_extent(first, last, todo, [](
auto& x,
auto to_add) {
338template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
339constexpr void set_preferred(It first, ItEnd last, int32_t preferred)
noexcept
340 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
344 if (first + 1 == last) {
345 inplace_max(first->preferred, preferred);
348 hilet todo = preferred - get_preferred(first, last);
353 add_to_extent(first, last, todo, [](
auto& x,
auto to_add) {
354 x.preferred += to_add;
365template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
366constexpr void set_maximum(It first, ItEnd last, int32_t maximum)
noexcept
367 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
371 if (first + 1 == last) {
372 inplace_min(first->maximum, maximum);
375 hilet todo = maximum - get_maximum(first, last);
380 add_to_extent(first, last, todo, [](
auto& x,
auto to_add) {
392template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
393constexpr void update_size(It first, ItEnd last, int32_t size)
noexcept
394 requires(std::is_same_v<std::remove_cvref_t<std::iter_value_t<It>>, grid_axis::value_type>)
396 hi_axiom(size >= get_minimum(first, last));
397 hi_axiom(size <= get_maximum(first, last));
400 for (
auto it = first; it != last; ++it) {
401 it->size = it->preferred;
402 inplace_max(highest_priority, it->priority);
405 auto todo = size - get_size(first, last);
408 for (
auto priority = highest_priority; todo < 0;) {
410 return x.priority == priority and x.size > x.minimum;
414 priority = get_lower_priority(first, last, priority);
421 for (
auto it = first; it != last and todo; ++it) {
423 if (
auto room = x.minimum - size; room and it->priority == priority) {
425 it->size += todo_this;
432 for (
auto priority = highest_priority; todo > 0;) {
434 return x.priority == priority and x.size < x.maximum;
438 priority = get_lower_priority(first, last, priority);
445 for (
auto it = first; it != last and todo; ++it) {
447 if (
auto room = x.maximum - size; room and it->priority == priority) {
449 it->size += todo_this;
464template<std::forward_iterator It, std::sentinal_for<It> ItEnd>
465constexpr void update_position(It first, ItEnd last, int32_t position = 0) noexcept
466 requires(
std::is_same_v<
std::remove_cvref_t<
std::iter_value_t<It>>, grid_axis::value_type>)
472 first->position = position;
473 position += first->size;
474 for (
auto it = first + 1; it != last; ++it) {
475 position += it->margin;
476 it->margin = position;
477 position += it->size;
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11