Skip to content

Commit

Permalink
contourDensity was crashing on NaN weight (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Dec 7, 2022
1 parent 7dc809c commit 517b36c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/density.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function() {
var xi = (x(d, ++i, data) + o) * pow2k,
yi = (y(d, i, data) + o) * pow2k,
wi = +weight(d, i, data);
if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
if (wi && xi >= 0 && xi < n && yi >= 0 && yi < m) {
var x0 = Math.floor(xi),
y0 = Math.floor(yi),
xt = xi - x0 - 0.5,
Expand Down
6 changes: 6 additions & 0 deletions test/density-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ it("contourDensity.thresholds(values[])(data) returns contours for the given val
assert.deepStrictEqual(values1, values2);
});

it("contourDensity.weight(…) accepts NaN weights", () => {
const points = [[1, 0, 1], [0, 1, -2], [1, 1, NaN]];
const c = contourDensity().weight(d => d[2])(points);
assert.strictEqual(c.length, 24);
});

it("contourDensity.thresholds(values[])(data) returns contours for the given values at a different cellSize", () => {
const points = [[1, 0], [0, 1], [1, 1]];
const c = contourDensity().cellSize(16);
Expand Down

0 comments on commit 517b36c

Please sign in to comment.