Skip to content

Commit

Permalink
feat: when broadening overlaping peaks the middle is proportional to …
Browse files Browse the repository at this point in the history
…the width
  • Loading branch information
lpatiny committed Mar 9, 2022
1 parent 299933a commit 8bf8838
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
48 changes: 48 additions & 0 deletions src/post/__tests__/broadenPeaks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,54 @@ describe('broadenPeaks', () => {
]);
});

it('factor=20 not same width', () => {
let result = broadenPeaks(
[
{
x: -0.5,
y: 1,
ddY: 0,
width: 0.1,
index: 25,
inflectionPoints: {
from: { index: 23, x: -0.55 },
to: { index: 27, x: -0.45 },
},
},
{
x: 0.5,
y: 1,
ddY: 0,
width: 0.4,
index: 75,
inflectionPoints: {
from: { index: 73, x: 0.3 },
to: { index: 77, x: 0.7 },
},
},
],
{ factor: 20 },
);
expect(result).toBeDeepCloseTo([
{
x: -0.5,
y: 1,
index: 25,
width: 1.2,
from: { x: -1.5 },
to: { x: -0.3 },
},
{
x: 0.5,
y: 1,
index: 75,
width: 4.8,
from: { x: -0.3 },
to: { x: 4.5 },
},
]);
});

it('factor=20 overlap=true', () => {
let result = broadenPeaks(
[
Expand Down
5 changes: 4 additions & 1 deletion src/post/broadenPeaks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export function broadenPeaks(
let peak = peaks[i];
let nextPeak = peaks[i + 1];
if (peak.to.x > nextPeak.from.x) {
peak.to.x = nextPeak.from.x = (peak.to.x + nextPeak.from.x) / 2;
// we do it proportional to the width of the peaks
peak.to.x = nextPeak.from.x =
(peak.width / (nextPeak.width + peak.width)) * (nextPeak.x - peak.x) +
peak.x;
}
}
}
Expand Down

0 comments on commit 8bf8838

Please sign in to comment.