Skip to content

Commit

Permalink
BACK UP
Browse files Browse the repository at this point in the history
LOST SOME DATA TO POWER OUTAGE, SPAMMING BACKUPS
  • Loading branch information
GDBobby committed Sep 28, 2023
1 parent bd40d80 commit 1a5391a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 66 deletions.
14 changes: 3 additions & 11 deletions noiz/include/noizN/cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,14 @@

namespace noiz {
template <std::floating_point Type>
struct Corner3 {
struct Corner {
Vec<Type> location{};
Vec<Type> gradient{};
};

template <typename Type>
template <typename Vec_Type>
struct TCell {
Type left_top_below{};
Type right_top_below{};
Type left_bottom_below{};
Type right_bottom_below{};

Type left_top_above{};
Type right_top_above{};
Type left_bottom_above{};
Type right_bottom_above{};
std::vector<Vec_Type> corners;
};

template <std::floating_point Type>
Expand Down
11 changes: 7 additions & 4 deletions noiz/include/noizN/detail/data.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#pragma once
#include "generator.hpp"
#include "grid3.hpp"
#include "grid.hpp"

namespace noiz::detail {
template <std::floating_point Type>
auto make_populated_grid(Index3 const grid_extent, Seed seed = Generator::make_random_seed()) -> Grid3<Type> {
auto ret = make_grid3<Type>(grid_extent);
auto make_populated_grid(Index3 const grid_extent, Seed seed = Generator::make_random_seed()) -> Grid<Type> {
auto ret = make_grid<Type>(grid_extent);
auto generator = Generator{seed};
for (auto& corner : ret.corners) { generator.next(corner.gradient); }
return ret;
}

template <std::floating_point Type>
constexpr auto compute_offsets(CornerCell3<Type> const& corner, Vec3<Type> const point) -> Cell3<Type> {
constexpr auto compute_offsets(CornerCell<Type> const& corner, Vec<Type> const point) -> Cell<Type> {

Cell<Type> ret;
ret.resize(corner.size());
return Cell3<Type>{
.left_top_below = point - corner.left_top_below.location,
.right_top_below = point - corner.right_top_below.location,
Expand Down
Empty file.
24 changes: 4 additions & 20 deletions noiz/include/noizN/detail/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@ class Generator {
/// \brief Fill the next random unit Vec.
/// \param out The Vec to assign to.
///
template <std::floating_point Type>
void next(Vec2<Type>& out) {
auto distribution = std::uniform_real_distribution<Type>{Type{-1}, Type{1}};
out = Vec2<Type>{.x = distribution(m_engine), .y = distribution(m_engine)}.normalized();
}

template <std::floating_point Type>
void next(Vec3<Type>& out) {
auto distribution = std::uniform_real_distribution<Type>{Type{-1}, Type{1}};
out = Vec3<Type>{.x = distribution(m_engine), .y = distribution(m_engine), .z = distribution(m_engine)}.normalized();
}

template <std::floating_point Type>
void next(Vec<Type>& out) {
auto distribution = std::uniform_real_distribution<Type>{Type{-1}, Type{1}};
Expand All @@ -55,18 +43,14 @@ class Generator {
/// \returns The next random unit Vec.
///
template <std::floating_point Type>
auto next2() -> Vec2<Type> {
auto ret = Vec2<Type>{};
next(ret);
return ret;
}
template <std::floating_point Type>
auto next3() -> Vec3<Type> {
auto ret = Vec3<Type>{};
auto nextN(uint8_t dimension_count) -> Vec<Type> {
auto ret = Vec<Type>{};
ret.components.resize(dimension_count);
next(ret);
return ret;
}


private:
std::default_random_engine m_engine{};
};
Expand Down
43 changes: 21 additions & 22 deletions noiz/include/noizN/detail/grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@

namespace noiz::detail {
template <std::floating_point Type>
[[nodiscard]] constexpr auto to_index(Vec3<Type> const point) -> Index {
return Index{.x = static_cast<int>(point.x), .y = static_cast<int>(point.y), .z = static_cast<int>(point.z)};
[[nodiscard]] constexpr auto to_index(Vec<Type> const point) -> Index {
Index ret;
ret.components.resize(point.components.size());
for(int i = 0; i < ret.components.size(); i++){
ret.components[i] = static_cast<int>(point.components[i]);
}
return ret;
}

template <std::floating_point Type>
[[nodiscard]] constexpr auto to_vec(Index const index) -> Vec3<Type> {
[[nodiscard]] constexpr auto to_vec(Index const index) -> Vec<Type> {
Vec<Type> returnVec;
returnVec.reserve(index.size());
for(int i = 0; i < index.size(); i++){
Expand All @@ -25,6 +30,8 @@ struct Grid {
Index grid_extent{};

[[nodiscard]] auto at(CellIndex const index) const -> CornerCell<Type> {
CornerCell<Type> ret;

return CornerCell<Type>{
corners.at(index.ltb), corners.at(index.rtb), corners.at(index.lbb), corners.at(index.rbb),
corners.at(index.lta), corners.at(index.rta), corners.at(index.lba), corners.at(index.rba)
Expand Down Expand Up @@ -54,34 +61,26 @@ template <std::floating_point Type>
.grid_extent = grid_extent,
};

std::vector<int> component_position;
Index index;
auto const grid_dimensions = grid_extent.components.size();
component_position.resize(grid_dimensions, 0);


bool finished = false;
for(uint8_t dimension_position = 0; dimension_position < dimension_count;){
index.components.resize(grid_dimensions, 0);

}

auto back_dimension_grid_extent = grid_extent.components.back() + 1;
auto& back_component_position = component_position[grid_dimensions - 1];
auto back_dimension_grid_extent = grid_extent.components[grid_dimensions - 1] + 1;
auto& back_component_position = index.components[grid_dimensions - 1];

auto& first_dimension_position = component_position[0];
auto& first_dimension_position = cindex.components[0];
auto first_dimension_grid_extent = (grid_extent.components[0] + 1);

while(back_component_position < back_dimension_grid_extent){
do{
first_dimension_position++;
for(uint8_t i = 0; i < (dimension_count - 1); i++){
component_position[]
if(first_dimension_position == first_dimension_grid_extent){
component_position[1]++;
component_Position[dimension_position] = 0;
dimension_position++;
}
index.components[i + 1] += index.components[i] == (grid_extent.components[i] + 1);
index.components[i] %= grid_extent.components[i] + 1;
}

auto const flat_index = static_cast<std::size_t>(index.flatten(grid_extent));
ret.corners.at(index).location = to_vec<Type>(index);
}
while(back_component_position < back_dimension_grid_extent);


for(int depth = 0; depth <= grid_extent.z; ++depth) {
Expand Down
28 changes: 19 additions & 9 deletions noiz/include/noizN/index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
#include <cstdint>

namespace noiz {
struct Index3 {
int x{};
int y{};
int z{};

[[nodiscard]] constexpr auto modulo(Index3 const extent) const -> Index3 {
assert(extent.x > 0 && extent.y > 0);
return Index3{.x = x % extent.x, .y = y % extent.y, .z = z % extent.z};
struct Index {
std::vector<int> components;

[[nodiscard]] constexpr auto modulo(Index const extent) const -> Index {
for(int i = 0; i < extent.components.size(); i++) {
assert(extent.component[i] > 0);
}
Index ret;
ret.components.resize(extent.components.size());
for(int i = 0; i < ret.components.size(); i++){
ret.components[i] = components[i] % extent.components[i];
}
}

[[nodiscard]] constexpr auto flatten(Index3 const extent) const -> int64_t {
[[nodiscard]] constexpr auto flatten(Index const extent) const -> int64_t {
assert(extent.components.size() == components.size());
int64_t ret = components.back();
const uint8_t dimension_count = components.size();



return z * ((extent.x + 1) * (extent.y + 1)) + y * (extent.x + 1) + x;
}
};
Expand Down

0 comments on commit 1a5391a

Please sign in to comment.