aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-11-07 06:30:02 -0500
committerDavid Robillard <d@drobilla.net>2022-11-07 06:56:07 -0500
commit036c4c1634b2e056da722b21302608ccfe05a298 (patch)
tree75e4a59b169f8012ec542c1fe806224bd5dc08ac /tools
parentc002ebc4245e805d7a2a0ddaf2fd9f6ff58d22a4 (diff)
downloadchilbert-036c4c1634b2e056da722b21302608ccfe05a298.tar.gz
chilbert-036c4c1634b2e056da722b21302608ccfe05a298.tar.bz2
chilbert-036c4c1634b2e056da722b21302608ccfe05a298.zip
Build tools
Diffstat (limited to 'tools')
-rw-r--r--tools/.clang-tidy7
-rw-r--r--tools/chilbert_obj.cpp41
-rw-r--r--tools/chilbert_svg.cpp52
-rw-r--r--tools/meson.build15
4 files changed, 115 insertions, 0 deletions
diff --git a/tools/.clang-tidy b/tools/.clang-tidy
new file mode 100644
index 0000000..2bcf741
--- /dev/null
+++ b/tools/.clang-tidy
@@ -0,0 +1,7 @@
+# Copyright 2020-2022 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR GPL-2.0-or-later
+
+Checks: >
+ -*-vararg,
+ -cert-err33-c,
+InheritParentConfig: true
diff --git a/tools/chilbert_obj.cpp b/tools/chilbert_obj.cpp
new file mode 100644
index 0000000..b80fa91
--- /dev/null
+++ b/tools/chilbert_obj.cpp
@@ -0,0 +1,41 @@
+// Copyright 2018-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "chilbert/chilbert.hpp"
+
+#include <array>
+#include <climits>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+
+int
+main(int argc, char** argv)
+{
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s NUM_POINTS\n", argv[0]);
+ return 1;
+ }
+
+ const unsigned long num_points = std::strtoul(argv[1], nullptr, 10);
+ if (num_points == 0 || num_points == ULONG_MAX) {
+ fprintf(stderr, "Usage: %s NUM_POINTS\n", argv[0]);
+ return 1;
+ }
+
+ // Vertices
+ for (uint64_t i = 0; i < num_points; ++i) {
+ std::array<uint32_t, 3> point{};
+ chilbert::index_to_coords(point, 16, 3, i);
+ printf("v %u %u %u\n", point[0], point[1], point[2]);
+ }
+
+ // One polyline through all vertices
+ printf("\nl");
+ for (unsigned i = 0; i < num_points - 1; ++i) {
+ printf(" %u", i + 1);
+ }
+ printf("\n");
+
+ return 0;
+}
diff --git a/tools/chilbert_svg.cpp b/tools/chilbert_svg.cpp
new file mode 100644
index 0000000..140b99a
--- /dev/null
+++ b/tools/chilbert_svg.cpp
@@ -0,0 +1,52 @@
+// Copyright 2018-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "chilbert/chilbert.hpp"
+
+#include <array>
+#include <climits>
+#include <cmath>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+
+int
+main(int argc, char** argv)
+{
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s NUM_POINTS\n", argv[0]);
+ return 1;
+ }
+
+ const unsigned long num_points = std::strtoul(argv[1], nullptr, 10);
+ if (num_points == 0 || num_points == ULONG_MAX) {
+ fprintf(stderr, "Usage: %s NUM_POINTS\n", argv[0]);
+ return 1;
+ }
+
+ const uint32_t w =
+ static_cast<uint32_t>(sqrt(1U << static_cast<uint32_t>(ceil(
+ log2(static_cast<double>(num_points)))))) -
+ 1U;
+
+ // Header
+ printf("<svg xmlns='http://www.w3.org/2000/svg'"
+ " version='1.2' baseProfile='tiny' viewBox='0 0 %u %u'>\n",
+ w,
+ w);
+ printf("<desc>Hilbert Curve</desc>\n");
+ printf("<polyline vector-effect='non-scaling-stroke' fill='none' "
+ "stroke='black' stroke-width='1' points='");
+
+ // One polyline through all vertices
+ for (uint64_t i = 0; i <= num_points; ++i) {
+ std::array<uint32_t, 2> point{};
+ chilbert::index_to_coords(point, 32, 2, i);
+ printf("%u,%u ", point[0], point[1]);
+ }
+
+ // Close off document
+ printf("' />\n</svg>\n");
+
+ return 0;
+}
diff --git a/tools/meson.build b/tools/meson.build
new file mode 100644
index 0000000..1a12aba
--- /dev/null
+++ b/tools/meson.build
@@ -0,0 +1,15 @@
+# Copyright 2019-2022 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR GPL-2.0-or-later
+
+tools = [
+ 'chilbert_obj',
+ 'chilbert_svg',
+]
+
+foreach tool : tools
+ executable(
+ tool,
+ files('@0@.cpp'.format(tool)),
+ dependencies: [chilbert_dep],
+ )
+endforeach