diff --git a/c++/perspective/src/common.h b/c++/perspective/src/common.h index d3bea9c..2c5e843 100644 --- a/c++/perspective/src/common.h +++ b/c++/perspective/src/common.h @@ -42,7 +42,6 @@ public: r(r), g(g), b(b), a(a) { } }; - inline int clz(const Int &x) { return x ? __builtin_clz(x) : 32; } inline int clz(const UInt &x) diff --git a/c++/perspective/src/generator.cpp b/c++/perspective/src/generator.cpp index 8fb0116..4457cf5 100644 --- a/c++/perspective/src/generator.cpp +++ b/c++/perspective/src/generator.cpp @@ -27,10 +27,10 @@ Generator::set_seed(ULongInt x) { Real Generator::random(const ULongIntVector2 &coord, int index) const { - ULongInt seed = ULongInt(rand()) ^ (ULongInt(rand()) << 16) ^ (ULongInt(rand()) << 32) ^ (ULongInt(rand()) << 48); - //ULongInt seed = random(coord.x ^ seeds_x()[index]); - //seed = random(seed ^ coord.y ^ seeds_y()[index]); - return Real(seed)/Real(ULLONG_MAX); + ULongInt seed = random(random(coord.x) ^ seeds_x()[index]); + seed = random(seed ^ random(coord.y) ^ seeds_y()[index]); + seed = random(seed ^ random(coord.x) ^ random(coord.y)); + return Real(seed)/Real(ULLONG_MAX)*Real(2) - Real(1); } Vector4 @@ -78,19 +78,19 @@ Generator::generate(const ULongIntVector2 &coord, bool shrink_cache) const { ULongInt level = (level_x < level_y ? level_x : level_y) + 1; if (level < one) { - value /= (one/level); + value /= one/level; if (level_x == level_y) { // square corners value += ( generate(ULongIntVector2(coord.x - level, coord.y - level)) - + generate(ULongIntVector2(coord.x - level, coord.y + level)) - + generate(ULongIntVector2(coord.x + level, coord.y - level)) - + generate(ULongIntVector2(coord.x + level, coord.y + level)) )*0.25; + + generate(ULongIntVector2(coord.x - level, coord.y + level)) + + generate(ULongIntVector2(coord.x + level, coord.y - level)) + + generate(ULongIntVector2(coord.x + level, coord.y + level)) )*0.25; } else { // diamond corners value += ( generate(ULongIntVector2(coord.x - level, coord.y)) - + generate(ULongIntVector2(coord.x + level, coord.y)) - + generate(ULongIntVector2(coord.x, coord.y - level)) - + generate(ULongIntVector2(coord.x, coord.y + level)) )*0.25; + + generate(ULongIntVector2(coord.x + level, coord.y)) + + generate(ULongIntVector2(coord.x, coord.y - level)) + + generate(ULongIntVector2(coord.x, coord.y + level)) )*0.25; } } } diff --git a/c++/perspective/src/generator.h b/c++/perspective/src/generator.h index affe538..e53476a 100644 --- a/c++/perspective/src/generator.h +++ b/c++/perspective/src/generator.h @@ -21,9 +21,26 @@ public: }; static inline ULongInt random(ULongInt x) { + ++x; + x ^= x >> 2; + x ^= x << 3; + x ^= x >> 5; + x ^= x << 7; + x ^= x >> 11; x ^= x << 13; - x ^= x >> 7; - x ^= x << 17; + x ^= x >> 17; + x ^= x << 19; + x ^= x >> 23; + x ^= x << 29; + x ^= x >> 31; + x ^= x << 37; + x ^= x >> 41; + x ^= x << 43; + x ^= x >> 47; + x ^= x << 53; + x ^= x >> 59; + x ^= x << 61; + ++x; return x; } static inline Real random_to_real(ULongInt x)