summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.nix/derivation.nix8
-rw-r--r--SConstruct68
-rw-r--r--c++/SConscript37
-rw-r--r--c++/ico.hpp70
-rw-r--r--default.nix3
5 files changed, 186 insertions, 0 deletions
diff --git a/.nix/derivation.nix b/.nix/derivation.nix
new file mode 100644
index 0000000..b318a46
--- /dev/null
+++ b/.nix/derivation.nix
@@ -0,0 +1,8 @@
+{ stdenv
+}:
+stdenv.mkDerivation {
+ pname = "icosahedrical_destruction";
+ version = "0.0.0";
+
+ src = ./..;
+}
diff --git a/SConstruct b/SConstruct
new file mode 100644
index 0000000..c07c9b4
--- /dev/null
+++ b/SConstruct
@@ -0,0 +1,68 @@
+#!/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')
+
+# Aliasing
+env.Alias('cdb', env.cdb);
+env.Alias('all', [env.targets]);
+env.Default('all');
+
+env.Alias('install', '$prefix')
diff --git a/c++/SConscript b/c++/SConscript
new file mode 100644
index 0000000..beb41e5
--- /dev/null
+++ b/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/c++/ico.hpp b/c++/ico.hpp
new file mode 100644
index 0000000..0ac1a91
--- /dev/null
+++ b/c++/ico.hpp
@@ -0,0 +1,70 @@
+#pragma once
+
+#include <array>
+#include <cstdint>
+
+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<std::array<uint8_t,3u>, 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<uint64_t SubD>
+class ico_addr {
+private:
+ std::array<uint8_t, SubD+1u> vals_;
+public:
+ template<uint64_t Div = 1u>
+ ico_addr<Div> slice() const {
+ return {};
+ }
+};
+
+template<typename T, uint64_t D>
+class ico_triangle {
+private:
+ std::array<ico_triangle<T,D-1u>> subdivs_;
+public:
+};
+
+template<typename T>
+class ico_triangle<T,0u> final {
+private:
+ T val_;
+public:
+};
+
+template<typename T, uint64_t SubD>
+class icosahedron final {
+private:
+ std::array<ico_triangle<T,SubD>,20u> surfaces_;
+public:
+};
+}
diff --git a/default.nix b/default.nix
new file mode 100644
index 0000000..99e112c
--- /dev/null
+++ b/default.nix
@@ -0,0 +1,3 @@
+{ pkgs ? import <nixpkgs> {}
+}:
+pkgs.callPackage ./.nix/derivation.nix {}