Skip to content

Commit

Permalink
fix(listen): Fixed bug with unit converter. Closes #239
Browse files Browse the repository at this point in the history
  • Loading branch information
atruskie committed Oct 15, 2015
1 parent 8c3c15d commit 824a3f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/services/unitConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ angular
return functions.input.startOffset + functions.pixelsToSeconds((left || 0.0) + (width || 0.0));
};
functions.toLow = function toLow(top, height) {
return functions.pixelsToHertz(
var low = functions.pixelsToHertz(
functions.invertPixels(top || 0.0) - (height || 0.0)
);

return low >= 0 ? low : 0;
};
functions.toHigh = function toHigh(top) {
return functions.pixelsToHertz(functions.invertPixels(top || 0.0));
Expand Down
7 changes: 6 additions & 1 deletion src/components/services/unitConverters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe("The unitConverter service", function () {
});

it("correctly sets width and height given a stretched image", function () {
inputArgs.imageElement = {src: "boobies", naturalWidth: 1200, naturalHeight: 250 };
inputArgs.imageElement = {src: "test-image", naturalWidth: 1200, naturalHeight: 250 };

converters = unitConverter.getConversions(inputArgs);

Expand Down Expand Up @@ -244,6 +244,11 @@ describe("The unitConverter service", function () {
expect(low).toBe(8010.351563 /*hertz (unrounded = 8010.3515625)*/);
});

it("toLow corrects for heights that are too tall", () => {
var low = converters.toLow(245, 18); // pixels
expect(low).toBe(0 /* hertz */);
});

it("correctly calculates the highFrequency for an audioEvent from the top position of a box", function () {
var high = converters.toHigh(20 /*pixels*/);
expect(high).toBe(10163.671875 /*hertz (unrounded = 10163.671875)*/);
Expand Down

0 comments on commit 824a3f4

Please sign in to comment.