1- import type { DataXY } from 'cheminfo-types' ;
21import type { Shape1D } from 'ml-peak-shape-generator' ;
32import { OptimizationOptions } from 'ml-spectra-fitting' ;
43
5- import { optimizePeaks } from '..' ;
4+ import { GSDPeakOptimized , optimizePeaks } from '..' ;
65import { GSDPeak } from '../GSDPeak' ;
6+ import { appendShapeAndFWHM } from '../utils/appendShapeAndFWHM' ;
77
88export interface JoinBroadPeaksOptions {
99 /**
@@ -31,7 +31,6 @@ export interface JoinBroadPeaksOptions {
3131 */
3232
3333export function joinBroadPeaks (
34- data : DataXY ,
3534 peakList : GSDPeak [ ] ,
3635 options : JoinBroadPeaksOptions = { } ,
3736) : GSDPeak [ ] {
@@ -45,8 +44,10 @@ export function joinBroadPeaks(
4544 let max = 0 ;
4645 let maxI = 0 ;
4746 let count = 1 ;
48- const broadLines : any [ ] = [ ] ;
49- const peaks : any [ ] = JSON . parse ( JSON . stringify ( peakList ) ) ;
47+ const broadLines : GSDPeakOptimized [ ] = [ ] ;
48+ const peaks = appendShapeAndFWHM ( peakList , { shape } ) ;
49+
50+ if ( peaks . length < 2 ) return peaks ;
5051
5152 let maxDdy = peakList [ 0 ] . ddY ;
5253 for ( let i = 1 ; i < peakList . length ; i ++ ) {
@@ -59,8 +60,8 @@ export function joinBroadPeaks(
5960 }
6061 }
6162
62- // Push a feke peak
63- broadLines . push ( { x : Number . MAX_VALUE , y : 0 , width : 0 } ) ;
63+ //@ts -expect-error Push a feke peak
64+ broadLines . push ( { x : Number . MAX_VALUE , y : 0 } ) ;
6465
6566 let candidates : { x : number [ ] ; y : number [ ] } = {
6667 x : [ broadLines [ 0 ] . x ] ,
@@ -90,10 +91,12 @@ export function joinBroadPeaks(
9091 ] ,
9192 { shape, optimization } ,
9293 ) ;
94+ //@ts -expect-error type is equal as expected
9395 peaks . push ( fitted [ 0 ] ) ;
9496 } else {
95- // Put back the candidates to the signals list
97+ // Put back the candidates to the peak list
9698 indexes . forEach ( ( index ) => {
99+ // @ts -expect-error todo 2
97100 peaks . push ( broadLines [ index ] ) ;
98101 } ) ;
99102 }
0 commit comments