From 5ca778dba2fa6fa89fbea0fe76a3d1fbba6bc143 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 2 Nov 2026 21:22:23 +0100 Subject: Restructure --- .nix/derivation.nix | 21 ------ SConstruct | 69 -------------------- app/.nix/derivation.nix | 24 +++++++ app/SConstruct | 69 ++++++++++++++++++++ app/c++/SConscript | 37 +++++++++++ app/c++/ico.hpp | 170 ++++++++++++++++++++++++++++++++++++++++++++++++ app/c++/ico_bar.hpp | 37 +++++++++++ app/c++/ico_ct.hpp | 19 ++++++ c++/SConscript | 37 ----------- c++/ico.hpp | 170 ------------------------------------------------ default.nix | 9 +-- 11 files changed, 361 insertions(+), 301 deletions(-) delete mode 100644 .nix/derivation.nix delete mode 100644 SConstruct create mode 100644 app/.nix/derivation.nix create mode 100644 app/SConstruct create mode 100644 app/c++/SConscript create mode 100644 app/c++/ico.hpp create mode 100644 app/c++/ico_bar.hpp create mode 100644 app/c++/ico_ct.hpp delete mode 100644 c++/SConscript delete mode 100644 c++/ico.hpp diff --git a/.nix/derivation.nix b/.nix/derivation.nix deleted file mode 100644 index fd41fc1..0000000 --- a/.nix/derivation.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ stdenv -, scons -, forstio -}: -stdenv.mkDerivation { - pname = "icosahedrical_destruction"; - version = "0.0.0"; - - src = ./..; - - nativeBuildInputs = [ - scons - forstio.core - ]; - - doCheck = true; - checkPhase = '' - scons test - ./bin/tests - ''; -} diff --git a/SConstruct b/SConstruct deleted file mode 100644 index 26151d4..0000000 --- a/SConstruct +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python3 - -import sys -import os -import os.path -import glob -import re - - -if sys.version_info < (3,): - def isbasestring(s): - return isinstance(s,basestring) -else: - def isbasestring(s): - return isinstance(s, (str,bytes)) - -def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""): - - if isbasestring(filetype): - dir_path = self.Dir('.').abspath - filetype = sorted(glob.glob(dir_path+"/"+filetype)) - - for path in filetype: - target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path ) - if shared: - target_name+='.os' - sources.append( self.SharedObject( target=target_name, source=path ) ) - else: - target_name+='.o' - sources.append( self.StaticObject( target=target_name, source=path ) ) - pass - -def isAbsolutePath(key, dirname, env): - assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,) - -env_vars = Variables( - args=ARGUMENTS -) - -env_vars.Add('prefix', - help='Installation target location of build results and headers', - default='/usr/local/', - validator=isAbsolutePath -) - -env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], - CXX=['c++'], - CPPDEFINES=[], - CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'], - LIBS=[]) -env.__class__.add_source_files = add_kel_source_files -env.Tool('compilation_db'); -env.cdb = env.CompilationDatabase('compile_commands.json'); - -env.objects = []; -env.sources = []; -env.headers = []; -env.targets = []; - -Export('env') -SConscript('c++/SConscript') -SConscript('tests/SConscript') - -# Aliasing -env.Alias('cdb', env.cdb); -env.Alias('all', [env.targets]); -env.Default('all'); - -env.Alias('install', '$prefix') diff --git a/app/.nix/derivation.nix b/app/.nix/derivation.nix new file mode 100644 index 0000000..b90200e --- /dev/null +++ b/app/.nix/derivation.nix @@ -0,0 +1,24 @@ +{ stdenv +, scons +, forstio +}: +stdenv.mkDerivation { + pname = "icosahedrical_destruction"; + version = "0.0.0"; + + src = ./..; + + nativeBuildInputs = [ + scons + forstio.core + ]; + + buildInputs = [ + ]; + + doCheck = true; + checkPhase = '' + scons test + ./bin/tests + ''; +} diff --git a/app/SConstruct b/app/SConstruct new file mode 100644 index 0000000..26151d4 --- /dev/null +++ b/app/SConstruct @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 + +import sys +import os +import os.path +import glob +import re + + +if sys.version_info < (3,): + def isbasestring(s): + return isinstance(s,basestring) +else: + def isbasestring(s): + return isinstance(s, (str,bytes)) + +def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""): + + if isbasestring(filetype): + dir_path = self.Dir('.').abspath + filetype = sorted(glob.glob(dir_path+"/"+filetype)) + + for path in filetype: + target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path ) + if shared: + target_name+='.os' + sources.append( self.SharedObject( target=target_name, source=path ) ) + else: + target_name+='.o' + sources.append( self.StaticObject( target=target_name, source=path ) ) + pass + +def isAbsolutePath(key, dirname, env): + assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,) + +env_vars = Variables( + args=ARGUMENTS +) + +env_vars.Add('prefix', + help='Installation target location of build results and headers', + default='/usr/local/', + validator=isAbsolutePath +) + +env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], + CXX=['c++'], + CPPDEFINES=[], + CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'], + LIBS=[]) +env.__class__.add_source_files = add_kel_source_files +env.Tool('compilation_db'); +env.cdb = env.CompilationDatabase('compile_commands.json'); + +env.objects = []; +env.sources = []; +env.headers = []; +env.targets = []; + +Export('env') +SConscript('c++/SConscript') +SConscript('tests/SConscript') + +# Aliasing +env.Alias('cdb', env.cdb); +env.Alias('all', [env.targets]); +env.Default('all'); + +env.Alias('install', '$prefix') diff --git a/app/c++/SConscript b/app/c++/SConscript new file mode 100644 index 0000000..beb41e5 --- /dev/null +++ b/app/c++/SConscript @@ -0,0 +1,37 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +core_env = env.Clone(); + +core_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +core_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += core_env.sources; +env.headers += core_env.headers; + +## Shared lib +objects_shared = [] +core_env.add_source_files(objects_shared, core_env.sources, shared=True); +env.library_shared = core_env.SharedLibrary('#build/icosahedrical_destruction', [objects_shared]); + +# Set Alias +env.Alias('library', [env.library_shared]); + +env.targets += ['library']; + +# Install +env.Install('$prefix/lib/', [env.library_shared]); +env.Install('$prefix/include/sims/icosahedrical_destruction', [core_env.headers]); + +# Test +# Export('core_env'); +# SConscript('tests/SConscript'); diff --git a/app/c++/ico.hpp b/app/c++/ico.hpp new file mode 100644 index 0000000..5dc00a0 --- /dev/null +++ b/app/c++/ico.hpp @@ -0,0 +1,170 @@ +#pragma once + +#include +#include +#include + +namespace kel { +namespace impl { +struct ico_surface_helper { + /** + * On each triangle we assume a ccw order and we start on the top-left part of the + * triangle. The orientation of the triangle is determined by the horizontal line + * (on the 2D foldout of the icosahedron) which is the down direction. + */ + static constexpr std::array, 20u> neighbour_map {{ + {1,4,5},//0 + {2,0,6},//1 + {3,1,7},//2 + {4,2,8},//3 + {0,3,9},//4 + {14,10,0},//5 + {10,11,1},//6 + {11,12,2},//7 + {12,13,3},//8 + {13,14,4},//9 + {6,5,15},//10 + {7,6,16},//11 + {8,7,17},//12 + {9,8,18},//13 + {5,9,19},//14 + {19,16,10},//15 + {15,17,11},//16 + {16,18,12},//17 + {17,19,13},//18 + {18,15,14} //19 + }}; +}; + +template +class ico_addr { +private: + std::array vals_; +public: + uint8_t& at(uint64_t i){ + return vals_[i]; + } + + const uint8_t& at(uint64_t i) const { + return vals_[i]; + } + + constexpr uint64_t size() const { + return SubD; + } + + bool is_equal(const ico_addr& rhs) const { + bool eq = true; + + for(uint64_t i = 0u; i < size(); ++i){ + eq &= (at(i) == rhs.at(i)); + } + + return eq; + } + + bool has_zero() const { + uint64_t z_ctr = 0u; + for(uint64_t i = 1u; i < size(); ++i){ + z_ctr += (at(i) == 0u ? 1u : 0u); + } + return (z_ctr > 0u); + } + + std::array count_groups() const { + std::array grps{0,0,0,0}; + + for(uint64_t i = 1u; i < size(); ++i){ + auto& addr_i = vals_[i]; + assert(addr_i < 4); + + ++grps[addr_i]; + } + + return grps; + } + + uint64_t count_non_zero_groups() const { + auto ctr = count_groups(); + + uint64_t grp_ctr = 0u; + for(uint64_t i = 1u; i < ctr.size(); ++i){ + grp_ctr += (ctr[i] > 0u ? 1u : 0u); + } + return grp_ctr; + } + + bool has_all_non_zero_groups() const { + auto ctr = count_non_zero_groups(); + return (ctr == 3u); + } + + ico_addr go_to(uint8_t dir_i){ + ico_addr cpy_addr; + cpy_addr.vals_ = vals_; + + if(at(size() - 1u) == 0u){ + cpy_addr.at(size() - 1u) = dir_i + 1u; + } + if(at(size() - 1u) == (dir_i + 1u)){ + cpy_addr.at(size() - 1u) = 0u; + } + + return cpy_addr; + } + + bool borders_root() const { + return not (has_all_non_zero_groups() or has_zero()); + } +}; + +template +class ico_triangle { +private: + std::array,4u> subdivs_; +public: + + ico_triangle& at(uint8_t i){ + return subdivs_[i]; + } + + template + ico_triangle at(const ico_addr& addr, uint64_t next_i){ + auto& addr_i = addr[next_i]; + + auto& sub_triangle = subdivs_[addr_i]; + if constexpr ( D == 1u){ + return sub_triangle; + } + return sub_triangle.at(addr,next_i+1u); + } +}; + +template +class ico_triangle final { +private: + T val_; +public: +}; + +namespace impl { +} + +template +class icosahedron final { +private: + std::array,20u> surfaces_; +public: + + template + ico_triangle at(const ico_addr& addr){ + static_assert(AddrD <= (SubD+1u), "Addr length to large."); + static_assert(AddrD > 0u, "Addr length to small."); + + auto& root_addr = addr[0u]; + auto& root_triangle = surfaces_[root_addr]; + return root_triangle.at(addr, 1u); + } +}; +} +} diff --git a/app/c++/ico_bar.hpp b/app/c++/ico_bar.hpp new file mode 100644 index 0000000..780e28e --- /dev/null +++ b/app/c++/ico_bar.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include "ico.hpp" + +namespace kel { + +template +class ico_coordinate { +private: + static constexpr uint64_t sub_divs_ = impl::power_two::value; + + uint64_t t_; + uint64_t x_; + uint64_t y_; +public: + ico_coordinate(uint64_t t__, uint64_t x__, uint64_t y__): + t_{t__}, + x_{x__}, + y_{y__} + {} + + bool is_on_border() const { + auto comb = x_+y_; + + bool farside_b = (comb == sub_divs_); + bool right_b = (y_ == 0u); + bool left_b = (x_ == 0u); + + return farside_b or right_b or left_b; + } + + ico_coordinate move_x_pos() const { + uint64_t x_mov = x_ + 1u; + + } +}; +} diff --git a/app/c++/ico_ct.hpp b/app/c++/ico_ct.hpp new file mode 100644 index 0000000..2209f66 --- /dev/null +++ b/app/c++/ico_ct.hpp @@ -0,0 +1,19 @@ +#pragma once + +namespace kel { +namespace ct { +template +struct Point {}; + +template +struct Direction { + static_assert(FracU <= FracD, "Can't exceed 1"); + static_assert(FracD > 0u, "Can't divide by 0"); +}; + +namespace impl { + +} + +} +} diff --git a/c++/SConscript b/c++/SConscript deleted file mode 100644 index beb41e5..0000000 --- a/c++/SConscript +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/false - -import os -import os.path -import glob - - -Import('env') - -dir_path = Dir('.').abspath - -# Environment for base library -core_env = env.Clone(); - -core_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) -core_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) - -env.sources += core_env.sources; -env.headers += core_env.headers; - -## Shared lib -objects_shared = [] -core_env.add_source_files(objects_shared, core_env.sources, shared=True); -env.library_shared = core_env.SharedLibrary('#build/icosahedrical_destruction', [objects_shared]); - -# Set Alias -env.Alias('library', [env.library_shared]); - -env.targets += ['library']; - -# Install -env.Install('$prefix/lib/', [env.library_shared]); -env.Install('$prefix/include/sims/icosahedrical_destruction', [core_env.headers]); - -# Test -# Export('core_env'); -# SConscript('tests/SConscript'); diff --git a/c++/ico.hpp b/c++/ico.hpp deleted file mode 100644 index 257f12d..0000000 --- a/c++/ico.hpp +++ /dev/null @@ -1,170 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace kel { -namespace impl { -struct ico_surface_helper { - /** - * On each triangle we assume a ccw order and we start on the top-left part of the - * triangle. The orientation of the triangle is determined by the horizontal line - * (on the 2D foldout of the icosahedron) which is the down direction. - */ - static constexpr std::array, 20u> neighbour_map {{ - {1,4,5},//0 - {2,0,6},//1 - {3,1,7},//2 - {4,2,8},//3 - {0,3,9},//4 - {14,10,0},//5 - {10,11,1},//6 - {11,12,2},//7 - {12,13,3},//8 - {13,14,4},//9 - {6,5,15},//10 - {7,6,16},//11 - {8,7,17},//12 - {9,8,18},//13 - {5,9,19},//14 - {19,16,10},//15 - {15,17,11},//16 - {16,18,12},//17 - {17,19,13},//18 - {18,15,14} //19 - }}; -}; -} - -template -class ico_addr { -private: - std::array vals_; -public: - uint8_t& at(uint64_t i){ - return vals_[i]; - } - - const uint8_t& at(uint64_t i) const { - return vals_[i]; - } - - constexpr uint64_t size() const { - return SubD; - } - - bool is_equal(const ico_addr& rhs) const { - bool eq = true; - - for(uint64_t i = 0u; i < size(); ++i){ - eq &= (at(i) == rhs.at(i)); - } - - return eq; - } - - bool has_zero() const { - uint64_t z_ctr = 0u; - for(uint64_t i = 1u; i < size(); ++i){ - z_ctr += (at(i) == 0u ? 1u : 0u); - } - return (z_ctr > 0u); - } - - std::array count_groups() const { - std::array grps{0,0,0,0}; - - for(uint64_t i = 1u; i < size(); ++i){ - auto& addr_i = vals_[i]; - assert(addr_i < 4); - - ++grps[addr_i]; - } - - return grps; - } - - uint64_t count_non_zero_groups() const { - auto ctr = count_groups(); - - uint64_t grp_ctr = 0u; - for(uint64_t i = 1u; i < ctr.size(); ++i){ - grp_ctr += (ctr[i] > 0u ? 1u : 0u); - } - return grp_ctr; - } - - bool has_all_non_zero_groups() const { - auto ctr = count_non_zero_groups(); - return (ctr == 3u); - } - - ico_addr go_to(uint8_t dir_i){ - ico_addr cpy_addr; - cpy_addr.vals_ = vals_; - - if(at(size() - 1u) == 0u){ - cpy_addr.at(size() - 1u) = dir_i + 1u; - } - if(at(size() - 1u) == (dir_i + 1u)){ - cpy_addr.at(size() - 1u) = 0u; - } - - return cpy_addr; - } - - bool borders_root() const { - return not (has_all_non_zero_groups() or has_zero()); - } -}; - -template -class ico_triangle { -private: - std::array,4u> subdivs_; -public: - - ico_triangle& at(uint8_t i){ - return subdivs_[i]; - } - - template - ico_triangle at(const ico_addr& addr, uint64_t next_i){ - auto& addr_i = addr[next_i]; - - auto& sub_triangle = subdivs_[addr_i]; - if constexpr ( D == 1u){ - return sub_triangle; - } - return sub_triangle.at(addr,next_i+1u); - } -}; - -template -class ico_triangle final { -private: - T val_; -public: -}; - -namespace impl { -} - -template -class icosahedron final { -private: - std::array,20u> surfaces_; -public: - - template - ico_triangle at(const ico_addr& addr){ - static_assert(AddrD <= (SubD+1u), "Addr length to large."); - static_assert(AddrD > 0u, "Addr length to small."); - - auto& root_addr = addr[0u]; - auto& root_triangle = surfaces_[root_addr]; - return root_triangle.at(addr, 1u); - } -}; -} diff --git a/default.nix b/default.nix index f7c4be7..356cc51 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,7 @@ { pkgs ? import {} -, stdenv ? pkgs.llvmPackages_16.stdenv -, clang-tools ? pkgs.clang-tools_16 +, llvmPackages ? pkgs.llvmPackages_22 +, stdenv ? llvmPackages.stdenv +, clang-tools ? llvmPackages.clang-tools , forstio ? (import ((builtins.fetchGit { url = "git@git.keldu.de:forstio/forstio"; ref = "dev"; @@ -10,6 +11,6 @@ }).forstio }: -pkgs.callPackage ./.nix/derivation.nix { - inherit forstio; +pkgs.callPackage ./app/.nix/derivation.nix { + inherit stdenv forstio; } -- cgit v1.3.1