pub fn find_peaks_over_threshold(data: &Vec<f64>, threshold: f64) -> Vec<GraphPeak> {
    let mut peaks: Vec<GraphPeak> = Vec::new();
    let mut current_peak = GraphPeak::new();

    for x in 0..data.len() {
        let y = data[x];

        if y < threshold {
            // Have we found a peak? If so, add it and start looking for the next one.
            if current_peak.right_trough.x > 0 {

                // Still descending
                if y <= current_peak.right_trough.y {
                    current_peak.right_trough.x = x;
                    current_peak.right_trough.y = y;
                }

                // Rising
                else {
                    compute_area(data, &mut current_peak);
                    peaks.push(current_peak);
                    current_peak.clear();
                }
            }

            // Are we looking for a left trough?
            else if current_peak.left_trough.x == 0 {
                current_peak.left_trough.x = x;
                current_peak.left_trough.y = y;
            }

            // If we have a left trough and an existing peak, assume this is the right trough - for now.
            else if current_peak.peak.x > current_peak.left_trough.x && current_peak.left_trough.x > 0 {
                current_peak.right_trough.x = x;
                current_peak.right_trough.y = y;
            }
            else {
                current_peak.left_trough.x = x;
                current_peak.left_trough.y = y;
            }
        }
        else if current_peak.left_trough.x > 0 { // Left trough is set.
            // Are we looking for a peak or is this bigger than the current peak?
            if current_peak.peak.x == 0 || y >= current_peak.peak.y {
                current_peak.peak.x = x;
                current_peak.peak.y = y;
                current_peak.right_trough.x = 0;
                current_peak.right_trough.y = 0.0;
            }
        }
        else if current_peak.right_trough.x > 0 { // Right trough is set.
            compute_area(data, &mut current_peak);
            peaks.push(current_peak);
            current_peak.clear();
        }
        else { // Nothing is set, but the value is above the threshold.
            current_peak.left_trough.x = x;
            current_peak.left_trough.y = y;
        }
    }

    peaks
}
// Returns a list of peaks in the given array of numeric values. Only peaks that go above the given threshold will be counted.
Returns a list of peaks in the given array of numeric values. Only peaks that go above the given threshold will be counted.
Returns a list of peaks in the given array of numeric values . Only peaks that go above the given threshold will be counted .
pub fn find_peaks_over_threshold(data: &Vec<f64>, threshold: f64) -> Vec<GraphPeak> {
    let mut peaks: Vec<GraphPeak> = Vec::new();
    let mut current_peak = GraphPeak::new();
    for x in 0..data.len() {
        let y = data[x];
        if y < threshold {
            // Have we found a peak? If so, add it and start looking for the next one.
            if current_peak.right_trough.x > 0 {
                // Still descending
                if y <= current_peak.right_trough.y {
                    current_peak.right_trough.x = x;
                    current_peak.right_trough.y = y;
                }
                // Rising
                else {
                    compute_area(data, &mut current_peak);
                    peaks.push(current_peak);
                    current_peak.clear();
                }
            }
            // Are we looking for a left trough?
            else if current_peak.left_trough.x == 0 {
                current_peak.left_trough.x = x;
                current_peak.left_trough.y = y;
            }
            // If we have a left trough and an existing peak, assume this is the right trough - for now.
            else if current_peak.peak.x > current_peak.left_trough.x && current_peak.left_trough.x > 0 {
                current_peak.right_trough.x = x;
                current_peak.right_trough.y = y;
            }
            else {
                current_peak.left_trough.x = x;
                current_peak.left_trough.y = y;
            }
        }
        else if current_peak.left_trough.x > 0 { // Left trough is set.
            // Are we looking for a peak or is this bigger than the current peak?
            if current_peak.peak.x == 0 || y >= current_peak.peak.y {
                current_peak.peak.x = x;
                current_peak.peak.y = y;
                current_peak.right_trough.x = 0;
                current_peak.right_trough.y = 0.0;
            }
        }
        else if current_peak.right_trough.x > 0 { // Right trough is set.
            compute_area(data, &mut current_peak);
            peaks.push(current_peak);
            current_peak.clear();
        }
        else { // Nothing is set, but the value is above the threshold.
            current_peak.left_trough.x = x;
            current_peak.left_trough.y = y;
        }
    }
    peaks
}
pub fn find_peaks_over_threshold ( data : & Vec < f64 > , threshold : f64 ) -> Vec < GraphPeak > { let mut peaks : Vec < GraphPeak > = Vec :: new ( ) ; let mut current_peak = GraphPeak :: new ( ) ; for x in 0 .. data . len ( ) { let y = data [ x ] ; if y < threshold { // Have we found a peak? If so, add it and start looking for the next one. if current_peak . right_trough . x > 0 { // Still descending if y <= current_peak . right_trough . y { current_peak . right_trough . x = x ; current_peak . right_trough . y = y ; } // Rising else { compute_area ( data , & mut current_peak ) ; peaks . push ( current_peak ) ; current_peak . clear ( ) ; } } // Are we looking for a left trough? else if current_peak . left_trough . x == 0 { current_peak . left_trough . x = x ; current_peak . left_trough . y = y ; } // If we have a left trough and an existing peak, assume this is the right trough - for now. else if current_peak . peak . x > current_peak . left_trough . x && current_peak . left_trough . x > 0 { current_peak . right_trough . x = x ; current_peak . right_trough . y = y ; } else { current_peak . left_trough . x = x ; current_peak . left_trough . y = y ; } } else if current_peak . left_trough . x > 0 { // Left trough is set. // Are we looking for a peak or is this bigger than the current peak? if current_peak . peak . x == 0 || y >= current_peak . peak . y { current_peak . peak . x = x ; current_peak . peak . y = y ; current_peak . right_trough . x = 0 ; current_peak . right_trough . y = 0.0 ; } } else if current_peak . right_trough . x > 0 { // Right trough is set. compute_area ( data , & mut current_peak ) ; peaks . push ( current_peak ) ; current_peak . clear ( ) ; } else { // Nothing is set, but the value is above the threshold. current_peak . left_trough . x = x ; current_peak . left_trough . y = y ; } } peaks }
Returns a list of peaks in the given array of numeric values.
Returns a list of peaks in the given array of numeric values .
data
&Vec<f64>
threshold
f64