Krita Source Code Documentation
Loading...
Searching...
No Matches
KisZug.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef KISZUG_H
7#define KISZUG_H
8
9#include <QtGlobal>
10#include <type_traits>
11#include "KisMpl.h"
12#include <zug/transducer/map.hpp>
13#include <zug/reducing/last.hpp>
14
27namespace kiszug {
28
29template <typename T>
30constexpr auto map_static_cast = zug::map([](auto&& x) { return static_cast<T>(x); });
31
32template <typename T>
33constexpr auto map_multiply = [] (T coeff) { return zug::map([coeff](auto&& x) { return x * coeff; }); };
34
35template <typename T>
36constexpr auto map_equal = [] (T value) { return zug::map([value](auto&& x) { return x == value; }); };
37
38template <typename T>
39constexpr auto map_not_equal = [] (T value) { return zug::map([value](auto&& x) { return x != value; }); };
40
41template <typename T>
42constexpr auto map_greater = [] (T value) { return zug::map([value](auto&& x) { return x > value; }); };
43template <typename T>
44constexpr auto map_greater_equal = [] (T value) { return zug::map([value](auto&& x) { return x >= value; }); };
45
46template <typename T>
47constexpr auto map_less = [] (T value) { return zug::map([value](auto&& x) { return x < value; }); };
48
49template <typename T>
50constexpr auto map_less_equal = [] (T value) { return zug::map([value](auto&& x) { return x <= value; }); };
51
52template <>
53inline constexpr auto map_equal<qreal> = [] (qreal value) { return zug::map([value](auto&& x) { return qFuzzyCompare(x, value); }); };
54
55template <>
56inline constexpr auto map_not_equal<qreal> = [] (qreal value) { return zug::map([value](auto&& x) { return !qFuzzyCompare(x, value); }); };
57
58template <>
59inline constexpr auto map_greater_equal<qreal> = [] (qreal value) { return zug::map([value](auto&& x) { return x >= value || qFuzzyCompare(x, value); }); };
60
61template <>
62inline constexpr auto map_less_equal<qreal> = [] (qreal value) { return zug::map([value](auto&& x) { return x <= value || qFuzzyCompare(x, value); }); };
63
64constexpr auto map_round = zug::map([](qreal x) -> int { return qRound(x); });
65
66struct empty_t
67{
68};
69
70constexpr auto to_functor = [] (auto f) {
71 return
72 [=] (auto &&x) {
73 return f(zug::last)(empty_t{}, ZUG_FWD(x));
74 };
75};
76
77constexpr auto foreach_tuple =
78 [] (auto mapping) {
79 return zug::map([=] (auto &&t) {
80 return kismpl::apply_to_tuple(to_functor(mapping), ZUG_FWD(t));
81 });
82 };
83
84constexpr auto foreach_arg =
85 [] (auto mapping) {
86 return zug::map([=] (auto&&... t) {
87 return std::make_tuple(zug::compat::invoke(to_functor(mapping), ZUG_FWD(t))...);
88 });
89 };
90
91} // namespace kiszug
92
93#endif // KISZUG_H
float value(const T *src, size_t ch)
static bool qFuzzyCompare(half p1, half p2)
auto apply_to_tuple(F f, Tuple &&t)
Definition KisMpl.h:60
constexpr auto map_not_equal
Definition KisZug.h:39
constexpr auto map_greater_equal< qreal >
Definition KisZug.h:59
constexpr auto foreach_arg
Definition KisZug.h:84
constexpr auto map_less_equal< qreal >
Definition KisZug.h:62
constexpr auto foreach_tuple
Definition KisZug.h:77
constexpr auto map_multiply
Definition KisZug.h:33
constexpr auto map_static_cast
Definition KisZug.h:30
constexpr auto map_not_equal< qreal >
Definition KisZug.h:56
constexpr auto map_equal
Definition KisZug.h:36
constexpr auto map_less
Definition KisZug.h:47
constexpr auto map_less_equal
Definition KisZug.h:50
constexpr auto to_functor
Definition KisZug.h:70
constexpr auto map_equal< qreal >
Definition KisZug.h:53
constexpr auto map_greater
Definition KisZug.h:42
constexpr auto map_greater_equal
Definition KisZug.h:44
constexpr auto map_round
Definition KisZug.h:64