/****************************************************************************
 * This file is part of the project AqDiagram.
 * AqDiagram (c) by 2025 Martin Preuss, all rights reserved.
 *
 * The license for this file can be found in the file COPYING which you
 * should have received along with this file.
 ****************************************************************************/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "./average.h"



double AQDG_Data_GetAbsMinDiffX(const AQDG_GRAPH_DATAPAIR_LIST *dpList)
{
  if (dpList && AQDG_Graph_DataPair_List_GetCount(dpList)) {
    const AQDG_GRAPH_DATAPAIR *dp;
    double minDist=0.0;
    double lastValue=0.0;
    int cnt=0;

    dp=AQDG_Graph_DataPair_List_First(dpList);
    while(dp) {
      double d;
  
      d=AQDG_Graph_DataPair_GetValueX(dp);
      if (cnt) {
        double dist;

        dist=abs(d-lastValue);
        if (cnt>1) {
          if (dist<minDist)
            minDist=dist;
        }
        else
          minDist=dist;
      }
      lastValue=d;
      cnt++;
      dp=AQDG_Graph_DataPair_List_Next(dp);
    }
    return minDist;
  }
  return 0.0;
}



double AQDG_Data_GetAbsMinDiffY(const AQDG_GRAPH_DATAPAIR_LIST *dpList)
{
  if (dpList && AQDG_Graph_DataPair_List_GetCount(dpList)) {
    const AQDG_GRAPH_DATAPAIR *dp;
    double minDist;
    double lastValue;
    int cnt=0;

    dp=AQDG_Graph_DataPair_List_First(dpList);
    while(dp) {
      double d;
  
      d=AQDG_Graph_DataPair_GetValueY(dp);
      if (cnt) {
        double dist;

        dist=abs(d-lastValue);
        if (cnt>1) {
          if (dist<minDist)
            minDist=dist;
        }
        else
          minDist=dist;
      }
      lastValue=d;
      cnt++;
      dp=AQDG_Graph_DataPair_List_Next(dp);
    }
    return minDist;
  }
  return 0.0;
}



