Shinya Kitaoka 810553
#pragma once
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
/*--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
 Simplex Noise C++ implementation
Toshihiro Shimizu 890ddd
 Based on a public domain code by Stefan Gustavson.
Toshihiro Shimizu 890ddd
 (The original header is below)
Toshihiro Shimizu 890ddd
--------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*-- start of the original header --*/
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
* A speed-improved simplex noise algorithm for 2D, 3D and 4D in Java.
Toshihiro Shimizu 890ddd
*
Toshihiro Shimizu 890ddd
* Based on example code by Stefan Gustavson (stegu@itn.liu.se).
Toshihiro Shimizu 890ddd
* Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
Toshihiro Shimizu 890ddd
* Better rank ordering method by Stefan Gustavson in 2012.
Toshihiro Shimizu 890ddd
*
Toshihiro Shimizu 890ddd
* This could be speeded up even further, but it's useful as it is.
Toshihiro Shimizu 890ddd
*
Toshihiro Shimizu 890ddd
* Version 2012-03-09
Toshihiro Shimizu 890ddd
*
Toshihiro Shimizu 890ddd
* This code was placed in the public domain by its original author,
Toshihiro Shimizu 890ddd
* Stefan Gustavson. You may use it as you see fit, but
Toshihiro Shimizu 890ddd
* attribution is appreciated.
Toshihiro Shimizu 890ddd
*
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
/*-- end of the original header --*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef IWA_SIMPLEXNOISE_H
Toshihiro Shimizu 890ddd
#define IWA_SIMPLEXNOISE_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct Grad {
Shinya Kitaoka 120a6e
  int x, y, z, w;
Shinya Kitaoka 120a6e
  Grad(int x_, int y_, int z_) : x(x_), y(y_), z(z_), w(0) {}
Shinya Kitaoka 120a6e
  Grad(int x_, int y_, int z_, int w_) : x(x_), y(y_), z(z_), w(w_) {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct CellIds {
Shinya Kitaoka 120a6e
  int i, j, k;
Shinya Kitaoka 120a6e
  int i1, j1, k1;
Shinya Kitaoka 120a6e
  int i2, j2, k2;
Shinya Kitaoka 120a6e
  CellIds(int _i = 0, int _j = 0, int _k = 0, int _i1 = 0, int _j1 = 0,
Shinya Kitaoka 120a6e
          int _k1 = 0, int _i2 = 0, int _j2 = 0, int _k2 = 0) {
Shinya Kitaoka 120a6e
    i  = _i;
Shinya Kitaoka 120a6e
    j  = _j;
Shinya Kitaoka 120a6e
    k  = _k;
Shinya Kitaoka 120a6e
    i1 = _i1;
Shinya Kitaoka 120a6e
    j1 = _j1;
Shinya Kitaoka 120a6e
    k1 = _k1;
Shinya Kitaoka 120a6e
    i2 = _i2;
Shinya Kitaoka 120a6e
    j2 = _j2;
Shinya Kitaoka 120a6e
    k2 = _k2;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool operator==(const CellIds &right) const {
Shinya Kitaoka 120a6e
    return i == right.i && j == right.j && k == right.k && i1 == right.i1 &&
Shinya Kitaoka 120a6e
           j1 == right.j1 && k1 == right.k1 && i2 == right.i2 &&
Shinya Kitaoka 120a6e
           j2 == right.j2 && k2 == right.k2;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class SimplexNoise {
Shinya Kitaoka 120a6e
  // This method is a *lot* faster than using (int)Math.floor(x)
Shinya Kitaoka 120a6e
  static int fastfloor(double x) {
Shinya Kitaoka 120a6e
    int xi = (int)x;
Shinya Kitaoka 120a6e
    return x < xi ? xi - 1 : xi;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static double dot(Grad g, double x, double y) { return g.x * x + g.y * y; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static double dot(Grad g, double x, double y, double z) {
Shinya Kitaoka 120a6e
    return g.x * x + g.y * y + g.z * z;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  static double dot(Grad g, double x, double y, double z, double w) {
Shinya Kitaoka 120a6e
    return g.x * x + g.y * y + g.z * z + g.w * w;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  SimplexNoise();
Shinya Kitaoka 120a6e
  // 2D simplex noise
Shinya Kitaoka 120a6e
  static double noise(double xin, double yin);
Shinya Kitaoka 120a6e
  // 3D simplex noise
Shinya Kitaoka 120a6e
  static double noise(double xin, double yin, double zin);
Shinya Kitaoka 120a6e
  // 4D simplex noise
Shinya Kitaoka 120a6e
  static double noise(double x, double y, double z, double w);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*- セルまたぎを防ぐために、現在の所属セルを得る -*/
Shinya Kitaoka 120a6e
  static CellIds getCellIds(double xin, double yin, double zin);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif