1 |
- {"ast":null,"code":"/**\n * Class for generating 2D Halton sequences.\n * From https://observablehq.com/@jrus/halton\n */\nexport class Halton2DSequence {\n /**\n * Creates a new Halton2DSequence.\n * @param numSamples Number of samples in the sequence.\n * @param baseX The base for the x coordinate (default: 2).\n * @param baseY The base for the y coordinate (default: 3).\n * @param width Factor to scale the x coordinate by (default: 1). The scaling factor is 1/width.\n * @param height Factor to scale the y coordinate by (default: 1). The scaling factor is 1/height.\n */\n constructor(numSamples, baseX = 2, baseY = 3, width = 1, height = 1) {\n this._curIndex = 0;\n this._sequence = [];\n this._numSamples = 0;\n /**\n * The x coordinate of the current sample.\n */\n this.x = 0;\n /**\n * The y coordinate of the current sample.\n */\n this.y = 0;\n this._width = width;\n this._height = height;\n this._baseX = baseX;\n this._baseY = baseY;\n this._generateSequence(numSamples);\n this.next();\n }\n /**\n * Regenerates the sequence with a new number of samples.\n * @param numSamples Number of samples in the sequence.\n */\n regenerate(numSamples) {\n this._generateSequence(numSamples);\n this.next();\n }\n /**\n * Sets the dimensions of the sequence.\n * @param width Factor to scale the x coordinate by. The scaling factor is 1/width.\n * @param height Factor to scale the y coordinate by. The scaling factor is 1/height.\n */\n setDimensions(width, height) {\n this._width = width;\n this._height = height;\n }\n /**\n * Advances to the next sample in the sequence.\n */\n next() {\n this.x = this._sequence[this._curIndex] / this._width;\n this.y = this._sequence[this._curIndex + 1] / this._height;\n this._curIndex += 2;\n if (this._curIndex >= this._numSamples * 2) {\n this._curIndex = 0;\n }\n }\n _generateSequence(numSamples) {\n this._sequence = [];\n this._curIndex = 0;\n this._numSamples = numSamples;\n for (let i = 1; i <= numSamples; ++i) {\n this._sequence.push(this._halton(i, this._baseX) - 0.5, this._halton(i, this._baseY) - 0.5);\n }\n }\n _halton(index, base) {\n let fraction = 1;\n let result = 0;\n while (index > 0) {\n fraction /= base;\n result += fraction * (index % base);\n index = ~~(index / base); // floor division\n }\n return result;\n }\n}","map":{"version":3,"names":["Halton2DSequence","constructor","numSamples","baseX","baseY","width","height","_curIndex","_sequence","_numSamples","x","y","_width","_height","_baseX","_baseY","_generateSequence","next","regenerate","setDimensions","i","push","_halton","index","base","fraction","result"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Maths/halton2DSequence.js"],"sourcesContent":["/**\n * Class for generating 2D Halton sequences.\n * From https://observablehq.com/@jrus/halton\n */\nexport class Halton2DSequence {\n /**\n * Creates a new Halton2DSequence.\n * @param numSamples Number of samples in the sequence.\n * @param baseX The base for the x coordinate (default: 2).\n * @param baseY The base for the y coordinate (default: 3).\n * @param width Factor to scale the x coordinate by (default: 1). The scaling factor is 1/width.\n * @param height Factor to scale the y coordinate by (default: 1). The scaling factor is 1/height.\n */\n constructor(numSamples, baseX = 2, baseY = 3, width = 1, height = 1) {\n this._curIndex = 0;\n this._sequence = [];\n this._numSamples = 0;\n /**\n * The x coordinate of the current sample.\n */\n this.x = 0;\n /**\n * The y coordinate of the current sample.\n */\n this.y = 0;\n this._width = width;\n this._height = height;\n this._baseX = baseX;\n this._baseY = baseY;\n this._generateSequence(numSamples);\n this.next();\n }\n /**\n * Regenerates the sequence with a new number of samples.\n * @param numSamples Number of samples in the sequence.\n */\n regenerate(numSamples) {\n this._generateSequence(numSamples);\n this.next();\n }\n /**\n * Sets the dimensions of the sequence.\n * @param width Factor to scale the x coordinate by. The scaling factor is 1/width.\n * @param height Factor to scale the y coordinate by. The scaling factor is 1/height.\n */\n setDimensions(width, height) {\n this._width = width;\n this._height = height;\n }\n /**\n * Advances to the next sample in the sequence.\n */\n next() {\n this.x = this._sequence[this._curIndex] / this._width;\n this.y = this._sequence[this._curIndex + 1] / this._height;\n this._curIndex += 2;\n if (this._curIndex >= this._numSamples * 2) {\n this._curIndex = 0;\n }\n }\n _generateSequence(numSamples) {\n this._sequence = [];\n this._curIndex = 0;\n this._numSamples = numSamples;\n for (let i = 1; i <= numSamples; ++i) {\n this._sequence.push(this._halton(i, this._baseX) - 0.5, this._halton(i, this._baseY) - 0.5);\n }\n }\n _halton(index, base) {\n let fraction = 1;\n let result = 0;\n while (index > 0) {\n fraction /= base;\n result += fraction * (index % base);\n index = ~~(index / base); // floor division\n }\n return result;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,OAAO,MAAMA,gBAAgB,CAAC;EAC1B;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;EACIC,WAAWA,CAACC,UAAU,EAAEC,KAAK,GAAG,CAAC,EAAEC,KAAK,GAAG,CAAC,EAAEC,KAAK,GAAG,CAAC,EAAEC,MAAM,GAAG,CAAC,EAAE;IACjE,IAAI,CAACC,SAAS,GAAG,CAAC;IAClB,IAAI,CAACC,SAAS,GAAG,EAAE;IACnB,IAAI,CAACC,WAAW,GAAG,CAAC;IACpB;AACR;AACA;IACQ,IAAI,CAACC,CAAC,GAAG,CAAC;IACV;AACR;AACA;IACQ,IAAI,CAACC,CAAC,GAAG,CAAC;IACV,IAAI,CAACC,MAAM,GAAGP,KAAK;IACnB,IAAI,CAACQ,OAAO,GAAGP,MAAM;IACrB,IAAI,CAACQ,MAAM,GAAGX,KAAK;IACnB,IAAI,CAACY,MAAM,GAAGX,KAAK;IACnB,IAAI,CAACY,iBAAiB,CAACd,UAAU,CAAC;IAClC,IAAI,CAACe,IAAI,CAAC,CAAC;EACf;EACA;AACJ;AACA;AACA;EACIC,UAAUA,CAAChB,UAAU,EAAE;IACnB,IAAI,CAACc,iBAAiB,CAACd,UAAU,CAAC;IAClC,IAAI,CAACe,IAAI,CAAC,CAAC;EACf;EACA;AACJ;AACA;AACA;AACA;EACIE,aAAaA,CAACd,KAAK,EAAEC,MAAM,EAAE;IACzB,IAAI,CAACM,MAAM,GAAGP,KAAK;IACnB,IAAI,CAACQ,OAAO,GAAGP,MAAM;EACzB;EACA;AACJ;AACA;EACIW,IAAIA,CAAA,EAAG;IACH,IAAI,CAACP,CAAC,GAAG,IAAI,CAACF,SAAS,CAAC,IAAI,CAACD,SAAS,CAAC,GAAG,IAAI,CAACK,MAAM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