summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-01-03 17:10:57 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-01-03 17:10:57 +0000
commit9da868abbe640297a81c8a5e32cdc7f7776c295e (patch)
treedc11aef362eb4807c6c77b9ad0cbc0b0588aa470
parentEncapsulate Ray (diff)
downloadilt-9da868abbe640297a81c8a5e32cdc7f7776c295e.tar.bz2
ilt-9da868abbe640297a81c8a5e32cdc7f7776c295e.tar.xz
ilt-9da868abbe640297a81c8a5e32cdc7f7776c295e.zip
Add transform_array
Wraps std::transform to transform one array into another.
-rw-r--r--lib/util.cpp1
-rw-r--r--lib/util.h14
-rw-r--r--ui/font.cpp12
3 files changed, 21 insertions, 6 deletions
diff --git a/lib/util.cpp b/lib/util.cpp
new file mode 100644
index 0000000..408a76a
--- /dev/null
+++ b/lib/util.cpp
@@ -0,0 +1 @@
+#include "util.h"
diff --git a/lib/util.h b/lib/util.h
new file mode 100644
index 0000000..290492f
--- /dev/null
+++ b/lib/util.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <algorithm> // IWYU pragma: keep
+#include <array>
+#include <cstddef>
+
+template<typename T, std::size_t N>
+constexpr auto
+transform_array(const std::array<T, N> & in, auto && transform)
+{
+ std::array<decltype(transform(in.front())), N> out {};
+ std::transform(in.begin(), in.end(), out.begin(), transform);
+ return out;
+}
diff --git a/ui/font.cpp b/ui/font.cpp
index 712818d..e5432b8 100644
--- a/ui/font.cpp
+++ b/ui/font.cpp
@@ -12,6 +12,7 @@
#include <stdexcept>
#include <string>
#include <unicode.h>
+#include <util.h>
#include <utility>
// IWYU pragma: no_forward_declare FT_LibraryRec_
@@ -173,12 +174,11 @@ Font::render(const std::string_view chars) const
const auto charPos = pos + glm::vec2 {ch.bearing.x, ch.bearing.y - static_cast<int>(ch.size.y)};
const auto size = glm::vec2 {ch.size};
- Quad q;
- std::transform(C.begin(), C.end(), q.begin(), [&size, &charPos, &ch, this](const auto & c) {
- return (charPos + (size * c.first))
- || ((glm::vec2 {ch.position} + (glm::vec2 {ch.size} * c.second)) / glm::vec2 {this->size});
- });
- out[fontTextures[ch.textureIdx].texture].emplace_back(q);
+ out[fontTextures[ch.textureIdx].texture].emplace_back(
+ transform_array(C, [&size, &charPos, &ch, this](const auto & c) {
+ return (charPos + (size * c.first))
+ || ((glm::vec2 {ch.position} + (glm::vec2 {ch.size} * c.second)) / glm::vec2 {this->size});
+ }));
pos.x += static_cast<float>(ch.advance);
}