IceCreamYou / THREE.Terrain

A procedural terrain generation engine for use with the Three.js 3D graphics library for the web.
https://icecreamyou.github.io/THREE.Terrain/
MIT License
717 stars 112 forks source link

Possible mismatch in randomness #20

Closed mattes3 closed 5 years ago

mattes3 commented 5 years ago

Hi,

as promised, I've begun to port this library to Typescript. I ran into a problem with scatter.js.

The function ScatterMeshes() has an option called randomness. I cannot find out the correct type for this option.

The doc for this option says:

randomness: If options.spread is a number, then this property is a function that determines where meshes are placed. Specifically, it returns an array of numbers, where each number is the probability that a mesh is NOT placed on the corresponding face. Valid values include Math.random and the return value of a call to THREE.Terrain.ScatterHelper.

So, randomness is supposed to be a function that returns an array of numbers. How can Math.random be a valid value for this option, since Math.random returns only one number, not an array of numbers?

Can you shed some light on this, please?

IceCreamYou commented 5 years ago

The randomness option has the type () => number | () => number[]. The behavior is:

If the third approach is desired, ScatterHelper is useful for producing the relevant array.