bool_algebra_extra.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #ifndef SIMPLE_GEOM_BOOL_ALGEBRA_EXTRA_HPP
  2. #define SIMPLE_GEOM_BOOL_ALGEBRA_EXTRA_HPP
  3. #include "bool_algebra.hpp"
  4. #include "algorithm.hpp"
  5. namespace simple::geom
  6. {
  7. // TODO: disable the element wise * and + for this (or bool vector in general) to not make inclusion of this header silently change behavior
  8. template <
  9. typename C, typename C2,
  10. size_t D, size_t D2,
  11. typename O, typename O2
  12. >
  13. [[nodiscard]]
  14. constexpr auto operator*
  15. (
  16. disjunction<C,D,O> one, // A1xA2x...An
  17. disjunction<C2,D2,O2> other // B1xB2x...Bm
  18. )
  19. noexcept
  20. {
  21. // A1xA2x...Anx1
  22. const auto row = vector(one.range);
  23. // 1xB1xB2x...Bm
  24. const auto column = deeply_transformed(other.range,
  25. [](auto x) { return vector(x); });
  26. // A1xA2x...AnxB1xB2...xBm
  27. return to_disjunction(row(column));
  28. }
  29. class conjunctive_bool
  30. {
  31. bool raw;
  32. public:
  33. constexpr conjunctive_bool() : raw(conjunct::identity) {}
  34. constexpr explicit conjunctive_bool(bool raw) : raw(raw) {}
  35. constexpr explicit operator bool() const noexcept { return raw; }
  36. constexpr conjunctive_bool& operator+=(conjunctive_bool other) noexcept
  37. {
  38. raw = conjunct{}(raw, other.raw);
  39. return *this;
  40. }
  41. constexpr conjunctive_bool operator*(conjunctive_bool other) const noexcept
  42. {
  43. other.raw = disjunct{}(other.raw, raw);
  44. return other;
  45. }
  46. };
  47. // same as disjunction +, but additionally converting to conjunction_bool and back to customize identity and ops used by vector application (matrix multiplication)
  48. template <
  49. typename C, typename C2,
  50. size_t D, size_t D2,
  51. typename O, typename O2
  52. >
  53. [[nodiscard]]
  54. constexpr auto operator+
  55. (
  56. conjunction<C,D,O> one,
  57. conjunction<C2,D2,O2> other
  58. )
  59. noexcept
  60. {
  61. const auto row = vector(deeply_transformed(one.range,
  62. [](auto x) { return conjunctive_bool(x); }));
  63. const auto column = deeply_transformed(other.range,
  64. [](auto x) { return vector(conjunctive_bool(x)); });
  65. return to_conjunction(deeply_transformed(row(column),
  66. [](auto x) { return bool(x); }));
  67. }
  68. // TODO: figure these out
  69. // ideally want elementwise when possible
  70. // but there are lot of strange cases
  71. template <
  72. typename C, typename C2,
  73. size_t D, size_t D2,
  74. typename O, typename O2
  75. >
  76. constexpr auto operator+
  77. (
  78. disjunction<C,D,O>,
  79. disjunction<C2,D2,O2>
  80. )
  81. = delete;
  82. template <
  83. typename C, typename C2,
  84. size_t D, size_t D2,
  85. typename O, typename O2
  86. >
  87. constexpr auto operator+
  88. (
  89. disjunction<C,D,O>,
  90. conjunction<C2,D2,O2>
  91. )
  92. = delete;
  93. template <
  94. typename C, typename C2,
  95. size_t D, size_t D2,
  96. typename O, typename O2
  97. >
  98. constexpr auto operator+
  99. (
  100. conjunction<C,D,O>,
  101. disjunction<C2,D2,O2>
  102. )
  103. = delete;
  104. template <
  105. typename C, typename C2,
  106. size_t D, size_t D2,
  107. typename O, typename O2
  108. >
  109. constexpr auto operator*
  110. (
  111. conjunction<C,D,O>,
  112. conjunction<C2,D2,O2>
  113. )
  114. = delete;
  115. template <
  116. typename C, typename C2,
  117. size_t D, size_t D2,
  118. typename O, typename O2
  119. >
  120. constexpr auto operator*
  121. (
  122. conjunction<C,D,O> one,
  123. disjunction<C2,D2,O2>
  124. )
  125. = delete;
  126. template <
  127. typename C, typename C2,
  128. size_t D, size_t D2,
  129. typename O, typename O2
  130. >
  131. constexpr auto operator*
  132. (
  133. disjunction<C,D,O> one,
  134. conjunction<C2,D2,O2>
  135. )
  136. = delete;
  137. } // namespace simple::geom
  138. #endif /* end of include guard */