ds-heightmap
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -15,10 +15,10 @@ "use strict"; | ||
}; | ||
const { width, height, rough, randomizer } = conf; | ||
if (width < 2) | ||
throw "Invalid config: width must be larger than 1."; | ||
if (height < 2) | ||
throw "Invalid config: height must be larger than 1."; | ||
const { rough, randomizer } = conf; | ||
const width = conf.width < 2 ? DEFAULT_CONFIG.width : conf.width; | ||
const height = conf.height < 2 ? DEFAULT_CONFIG.height : conf.height; | ||
let max = Number.MIN_SAFE_INTEGER; | ||
let min = Number.MAX_SAFE_INTEGER; | ||
const depth = conf.depth === undefined ? DEFAULT_CONFIG.depth : conf.depth; | ||
const depth = conf.depth === undefined || conf.depth <= 0 | ||
? DEFAULT_CONFIG.depth | ||
: conf.depth; | ||
const maxSide = Math.max(width, height); | ||
@@ -44,8 +44,8 @@ let side = 0; | ||
const output = { data, max, min }; | ||
if (data.length !== width) { | ||
data.splice(width); | ||
if (side !== width) { | ||
data.length = width; | ||
} | ||
if (data[0].length !== height) { | ||
if (side !== height) { | ||
for (const col of data) { | ||
col.splice(height); | ||
col.length = height; | ||
} | ||
@@ -86,3 +86,3 @@ } | ||
function randomize(base, range) { | ||
if (typeof randomizer === "function") | ||
if (typeof randomizer === 'function') | ||
return randomizer(base, range); | ||
@@ -89,0 +89,0 @@ const n = base + |
{ | ||
"name": "ds-heightmap", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Use diamond-square algorithm to generate heightmaps.", | ||
@@ -13,2 +13,3 @@ "main": "lib/index.js", | ||
"lib", | ||
"wasm", | ||
"index.esm.mjs" | ||
@@ -18,5 +19,6 @@ ], | ||
"build": "tsc", | ||
"build:wasm": "cd rs && wasm-pack build --release --out-dir ../wasm", | ||
"build:watch": "tsc --watch", | ||
"lint": "tsc --noEmit --noUnusedLocals true --noUnusedParameters true", | ||
"prepublishOnly": "npm run build", | ||
"prepublishOnly": "npm run build && npm run build:wasm", | ||
"test": "npm run lint" | ||
@@ -23,0 +25,0 @@ }, |
@@ -42,2 +42,19 @@ # ds-heightmap | ||
There is also a WebAssembly version of the module: | ||
```javascript | ||
import { Runner } from 'ds-heightmap/wasm'; | ||
const runner = new Runner( | ||
129, // width | ||
129, // height | ||
2000, // depth | ||
1 // rough | ||
); | ||
const data = runner.ds(); | ||
console.log(data.data); | ||
console.log(data.max); | ||
console.log(data.min); | ||
``` | ||
*Note: `randomizer` is not supported in WebAssembly version yet.* | ||
### Render the map | ||
@@ -44,0 +61,0 @@ |
Sorry, the diff of this file is not supported yet
17270
9
104