Skip to content

Commit

Permalink
refactor: Change dataMinBin to include 0th bin since it can include n…
Browse files Browse the repository at this point in the history
…on-zero values
  • Loading branch information
ShrimpCryptid committed Dec 17, 2024
1 parent 186937c commit 235a471
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/Histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ export default class Histogram {
this.max = hinfo.max;
this.binSize = hinfo.binSize;

// track the first and last nonzero bins with at least 1 sample
// TODO: If `this.min` is not 0, should `this.dataMinBin` be `0` (instead of starting at 1)
// since the first bin doesn't represent zero values?
for (let i = 1; i < this.bins.length; i++) {
// TODO: These should always return 0 and NBINS - 1, respectively. Test if these
// can be removed.
for (let i = 0; i < this.bins.length; i++) {
if (this.bins[i] > 0) {
this.dataMinBin = i;
break;
}
}
for (let i = this.bins.length - 1; i >= 1; i--) {
for (let i = this.bins.length - 1; i >= 0; i--) {
if (this.bins[i] > 0) {
this.dataMaxBin = i;
break;
Expand Down
5 changes: 2 additions & 3 deletions src/test/lut.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ describe("test histogram", () => {
const histogram = new Histogram(conedata);

describe("binary volume data", () => {
it("has a min of 255", () => {
// histogram dataMin is the min nonzero value
expect(histogram.getMin()).to.equal(255);
it("has a min of 0", () => {
expect(histogram.getMin()).to.equal(0);
});
it("has a max of 255", () => {
expect(histogram.getMax()).to.equal(255);
Expand Down

0 comments on commit 235a471

Please sign in to comment.