Skip to content

Commit 0823e80

Browse files
committed
template version
1 parent 6c9164f commit 0823e80

32 files changed

+528
-1078
lines changed

Diff for: CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
1212
set(is_project_root ON)
1313
endif()
1414

15-
option(NOIZ_BUILD_TESTS "Build noiz tests" ${is_project_root})
15+
#option(NOIZ_BUILD_TESTS "Build noiz tests" FALSE)#${is_project_root})
1616
option(NOIZ_BUILD_EXAMPLES "Build noiz examples" ${is_project_root})
1717

1818
add_library(noiz-compile-options INTERFACE)
@@ -34,7 +34,7 @@ if(NOIZ_BUILD_EXAMPLES)
3434
add_subdirectory(examples)
3535
endif()
3636

37-
if(NOIZ_BUILD_TESTS)
38-
enable_testing()
39-
add_subdirectory(tests)
40-
endif()
37+
#if(NOIZ_BUILD_TESTS)
38+
#enable_testing()
39+
#add_subdirectory(tests)
40+
#endif()

Diff for: examples/common/argument_parsing.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <charconv>
22
#include <format>
33
#include <iostream>
4+
#include <span>
45

56
namespace {
67
template <typename Type>

Diff for: examples/histogram/histogram.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <noiz/noise2.hpp>
1+
#include <noiz/noiseTemplate.hpp>
22
#include <charconv>
33
#include <filesystem>
44
#include <format>
@@ -82,7 +82,7 @@ auto main(int argc, char** argv) -> int {
8282
auto histogram = Histogram{};
8383
for (int i = 0; i < config.count; ++i) {
8484
// build point on line (y = 0)
85-
auto const point = noiz::Vec2f{.x = static_cast<float>(i) * config.step};
85+
const auto point = noiz::ConstructVector(static_cast<float>(i) * config.step, 0.0f);
8686
// add noise at point
8787
histogram.add(noise.at(point));
8888
}

Diff for: examples/point-cloud/pointcloud.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <noiz/noise3.hpp>
1+
#include <noiz/noiseTemplate.hpp>
22
#include <noiz/processing.hpp>
33

44
#include <argument_parsing.hpp>
@@ -31,9 +31,10 @@ struct Config {
3131
if (!args.args.empty()) {
3232
return false;
3333
}
34-
grid_extent.x *= image_size_factor;
35-
grid_extent.y *= image_size_factor;
36-
grid_extent.z *= image_size_factor;
34+
35+
grid_extent.component[0] *= image_size_factor;
36+
grid_extent.component[1] *= image_size_factor;
37+
grid_extent.component[2] *= image_size_factor;
3738
return true;
3839
}
3940
};
@@ -69,7 +70,7 @@ class Point_Cloud {
6970
}
7071
#else //hybrid multi fractal noise
7172
const float noise_value = noise_processor.hybrid_multi_fractal_processing(
72-
noiz::Vec3f{.x = static_cast<float>(x) * step, .y = static_cast<float>(y) * step, .z = static_cast<float>(z) * step}
73+
noiz::ConstructVector(static_cast<float>(x) * step, static_cast<float>(y) * step, static_cast<float>(z) * step)
7374
);
7475
if(noise_value > 2.0f){ //this should render a half of the points with hmf noise
7576

Diff for: examples/texture2d/texture2d.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <noiz/noise2.hpp>
1+
#include <noiz/noiseTemplate.hpp>
22

33
#include <argument_parsing.hpp>
44

@@ -36,8 +36,8 @@ struct Config {
3636
if (!args.args.empty()) {
3737
return false;
3838
}
39-
grid_extent.x = constant_base_resolution * image_size_factor;
40-
grid_extent.y = constant_base_resolution * image_size_factor;
39+
grid_extent.component[0] = constant_base_resolution * image_size_factor;
40+
grid_extent.component[1] = constant_base_resolution * image_size_factor;
4141
return true;
4242
}
4343
};
@@ -55,7 +55,7 @@ class Texture_2D {
5555
for (int y = 0; y < image_size; y++) {
5656
for(int x = 0; x < image_size; x++) {
5757
// add noise at point
58-
float adjusted_noise = noise.at(noiz::Vec2f{.x = static_cast<float>(x) * step, .y = static_cast<float>(y) * step});
58+
float adjusted_noise = noise.at(noiz::ConstructVector(static_cast<float>(x) * step, static_cast<float>(y) * step));
5959
adjusted_noise = (adjusted_noise + 1.f) * 0.5f;
6060
grayscale_color = static_cast<uint8_t>((adjusted_noise) * 255.f);
6161
for(int i = 0; i < 3; i++) {

Diff for: noiz/CMakeLists.txt

+9-27
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,15 @@ add_library(${PROJECT_NAME} INTERFACE)
44
add_library(noiz::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
55

66
target_sources(${PROJECT_NAME} PUBLIC FILE_SET HEADERS BASE_DIRS include FILES
7-
include/noiz/detail/data2.hpp
8-
include/noiz/detail/generator.hpp
9-
include/noiz/detail/grid2.hpp
10-
11-
include/noiz/cell2.hpp
12-
include/noiz/index2.hpp
13-
include/noiz/noise2.hpp
14-
include/noiz/seed.hpp
15-
include/noiz/vec2.hpp
16-
17-
18-
include/noiz/detail/data3.hpp
19-
include/noiz/detail/grid3.hpp
20-
21-
include/noiz/cell3.hpp
22-
include/noiz/index3.hpp
23-
include/noiz/noise3.hpp
24-
include/noiz/vec3.hpp
25-
26-
27-
include/noiz/detail/data4.hpp
28-
include/noiz/detail/grid4.hpp
29-
30-
include/noiz/cell4.hpp
31-
include/noiz/index4.hpp
32-
include/noiz/noise4.hpp
33-
include/noiz/vec4.hpp
7+
include/noiz/detail/dataTemplate.hpp
8+
include/noiz/detail/generator.hpp
9+
include/noiz/detail/gridTemplate.hpp
10+
11+
include/noiz/cellTemplate.hpp
12+
include/noiz/indexTemplate.hpp
13+
include/noiz/noiseTemplate.hpp
14+
include/noiz/seed.hpp
15+
include/noiz/vecTemplate.hpp
3416
)
3517

3618
target_include_directories(${PROJECT_NAME} INTERFACE

Diff for: noiz/include/noiz/cell2.hpp

-26
This file was deleted.

Diff for: noiz/include/noiz/cell3.hpp

-31
This file was deleted.

Diff for: noiz/include/noiz/cell4.hpp

-24
This file was deleted.

Diff for: noiz/include/noiz/cellTemplate.hpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
#include <array>
3+
#include "indexTemplate.hpp"
4+
#include "vecTemplate.hpp"
5+
6+
namespace noiz {
7+
template <std::floating_point Type, std::size_t N>
8+
struct CornerData {
9+
Vec<Type, N> location{};
10+
Vec<Type, N> gradient{};
11+
};
12+
13+
template <typename Type, std::size_t N>
14+
struct TCell {
15+
std::array<Type, (1 << N)> corners{};
16+
};
17+
18+
template <std::floating_point Type>
19+
using Cell2 = TCell<Vec<Type, 2>, 2>;
20+
template <std::floating_point Type>
21+
using Cell3 = TCell<Vec<Type, 3>, 3>;
22+
template <std::floating_point Type>
23+
using Cell4 = TCell<Vec<Type, 4>, 4>;
24+
template <std::floating_point Type, std::size_t N>
25+
using Cell = TCell<Vec<Type, N>, N>;
26+
27+
template <std::floating_point Type, std::size_t N>
28+
using CornerCell = TCell<CornerData<Type, N>, N>;
29+
} // namespace noiz

Diff for: noiz/include/noiz/detail/data2.hpp

-41
This file was deleted.

Diff for: noiz/include/noiz/detail/data3.hpp

-58
This file was deleted.

0 commit comments

Comments
 (0)