Open avcarr2 opened 1 year ago
Another probably incorrect implementation of handling binary search on double arrays.
Here, starting index again doesn't correctly determine which index it is closer to. This one is more serious because it has 17 references. https://github.com/smith-chem-wisc/mzLib/blob/b0f82ea7bf47321ad2b81833961bff6d5706fe13/mzLib/MassSpectrometry/MzSpectra/MzSpectrum.cs#L673-L695
https://github.com/smith-chem-wisc/mzLib/blob/b0f82ea7bf47321ad2b81833961bff6d5706fe13/mzLib/MassSpectrometry/MzSpectra/MzSpectrum.cs#L718-L730
The linked method has an error commonly associated with performig binary searches on double arrays. The method as written uses a binary search to find the minimum mz value in the MzSpectrum.XArray and does not test to see if the correct, closest value is the index to the right or the left.
To fix this issue, replace lines currently binary search associated code should be replaced with the following: ` int ind = Array.BinarySearch(XArray, minX); if (ind < 0) { ind = ~ind; }