Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/xy/__tests__/xyReduce.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ test('xyCheck optimization', () => {
expect(result.y).toStrictEqual([0, 5, 10]);
});

test('xyCheck non-linear x', () => {
const xs = [];
const ys = [];
for (let i = 0; i < 11; i++) {
xs.push(i * 1.2 ** i);
ys.push(i);
}
const result = xyReduce({ x: xs, y: ys }, { nbPoints: 5 });
expect(result.y).toStrictEqual([0, 1, 8, 9, 10]);
});

test('xyCheck extreme non-linear x', () => {
const xs = [];
const ys = [];
for (let i = 0; i < 11; i++) {
xs.push(i * 2 ** i);
ys.push(i);
}
//console.log(xs, ys);
const result = xyReduce({ x: xs, y: ys }, { nbPoints: 5 });
expect(result.y).toStrictEqual([0, 1, 10]);
});

test('Part rounded far 2 with optimization', () => {
const result = xyReduce({ x, y }, { nbPoints: 5, optimize: true });

Expand Down
6 changes: 4 additions & 2 deletions src/xy/xyReduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface XYReduceOptions {
* */
nbPoints?: number;
/**
* If optimize we may have less than nbPoints at the end
* If optimize we may have less than nbPoints at the end. It should not have visible effects
* @default false
* */
optimize?: boolean;
Expand All @@ -42,7 +42,9 @@ export interface XYReduceOptions {

/**
* Reduce the number of points while keeping visually the same noise. Practical to
* display many spectra as SVG. If you want a similar looking spectrum you should still however generate 4x the nbPoints that is being displayed.
* display many spectra as SVG. If you want a similar looking spectrum you should still however
* generate at least 4x the nbPoints that is being displayed.
*
* SHOULD NOT BE USED FOR DATA PROCESSING !!!
* You should rather use ml-xy-equally-spaced to make further processing
*
Expand Down