From 036c4c1634b2e056da722b21302608ccfe05a298 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 7 Nov 2022 06:30:02 -0500 Subject: Build tools --- meson.build | 8 +++++++- meson_options.txt | 3 +++ src/chilbert_obj.cpp | 40 -------------------------------------- src/chilbert_svg.cpp | 49 ----------------------------------------------- tools/.clang-tidy | 7 +++++++ tools/chilbert_obj.cpp | 41 +++++++++++++++++++++++++++++++++++++++ tools/chilbert_svg.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/meson.build | 15 +++++++++++++++ 8 files changed, 125 insertions(+), 90 deletions(-) delete mode 100644 src/chilbert_obj.cpp delete mode 100644 src/chilbert_svg.cpp 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 diff --git a/meson.build b/meson.build index 8d3152c..c71fdfc 100644 --- a/meson.build +++ b/meson.build @@ -86,7 +86,7 @@ detail_headers = files( ) # Declare dependency for internal meson dependants -spaix_dep = declare_dependency(include_directories: include_dirs) +chilbert_dep = declare_dependency(include_directories: include_dirs) # Generage pkg-config file for external dependants pkg.generate( @@ -101,6 +101,12 @@ pkg.generate( install_headers(headers, subdir: versioned_name / 'chilbert') install_headers(detail_headers, subdir: versioned_name / 'chilbert' / 'detail') +######### +# Tools # +######### + +subdir('tools') + ###################### # Tests / Benchmarks # ###################### diff --git a/meson_options.txt b/meson_options.txt index e090a29..3210b0d 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -9,3 +9,6 @@ option('strict', type: 'boolean', value: false, yield: true, option('tests', type: 'feature', value: 'auto', yield: true, description: 'Build tests') + +option('tools', type: 'feature', value: 'auto', yield: true, + description: 'Build command line utilities') diff --git a/src/chilbert_obj.cpp b/src/chilbert_obj.cpp deleted file mode 100644 index 76039d0..0000000 --- a/src/chilbert_obj.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2018-2022 David Robillard -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "chilbert/chilbert.hpp" - -#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/src/chilbert_svg.cpp b/src/chilbert_svg.cpp deleted file mode 100644 index a572f68..0000000 --- a/src/chilbert_svg.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// 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; - } - - const uint32_t w = - uint32_t(sqrt(1 << uint32_t(ceil(log2(double(num_points)))))) - 1; - - // Header - printf("\n", - w, - w); - printf("Hilbert Curve\n"); - printf("\n\n"); - - return 0; -} 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