MCPcopy
hub / github.com/mewo2/terrain / fillSinks

Function fillSinks

terrain.js:301–332  ·  view source on GitHub ↗
(h, epsilon)

Source from the content-addressed store, hash-verified

299}
300
301function fillSinks(h, epsilon) {
302 epsilon = epsilon || 1e-5;
303 var infinity = 999999;
304 var newh = zero(h.mesh);
305 for (var i = 0; i < h.length; i++) {
306 if (isnearedge(h.mesh, i)) {
307 newh[i] = h[i];
308 } else {
309 newh[i] = infinity;
310 }
311 }
312 while (true) {
313 var changed = false;
314 for (var i = 0; i < h.length; i++) {
315 if (newh[i] == h[i]) continue;
316 var nbs = neighbours(h.mesh, i);
317 for (var j = 0; j < nbs.length; j++) {
318 if (h[i] >= newh[nbs[j]] + epsilon) {
319 newh[i] = h[i];
320 changed = true;
321 break;
322 }
323 var oh = newh[nbs[j]] + epsilon;
324 if ((newh[i] > oh) && (oh > h[i])) {
325 newh[i] = oh;
326 changed = true;
327 }
328 }
329 }
330 if (!changed) return newh;
331 }
332}
333
334function getFlux(h) {
335 var dh = downhill(h);

Callers 2

doErosionFunction · 0.85
generateCoastFunction · 0.85

Calls 3

zeroFunction · 0.85
isnearedgeFunction · 0.85
neighboursFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…