From 036c4c1634b2e056da722b21302608ccfe05a298 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 7 Nov 2022 06:30:02 -0500 Subject: Build tools --- tools/.clang-tidy | 7 +++++++ tools/chilbert_obj.cpp | 41 +++++++++++++++++++++++++++++++++++++++ tools/chilbert_svg.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/meson.build | 15 +++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 tools/.clang-tidy create mode 100644 tools/chilbert_obj.cpp create mode 100644 tools/chilbert_svg.cpp create mode 100644 tools/meson.build (limited to 'tools') 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 +# 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 +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "chilbert/chilbert.hpp" + +#include +#include +#include +#include +#include + +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 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 +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "chilbert/chilbert.hpp" + +#include +#include +#include +#include +#include +#include + +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(sqrt(1U << static_cast(ceil( + log2(static_cast(num_points)))))) - + 1U; + + // Header + printf("\n", + w, + w); + printf("Hilbert Curve\n"); + printf("\n\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 +# 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 -- cgit v1.2.1