diff --git a/src/lib/aqdiagram/data/0BUILD b/src/lib/aqdiagram/data/0BUILD index 232d02a..efad724 100644 --- a/src/lib/aqdiagram/data/0BUILD +++ b/src/lib/aqdiagram/data/0BUILD @@ -59,6 +59,7 @@ average.h accumulate.h + negate.h floatingavg.h date.h diff.h @@ -72,6 +73,7 @@ $(local/typefiles) average.c accumulate.c + negate.c floatingavg.c date.c diff.c diff --git a/src/lib/aqdiagram/data/negate.c b/src/lib/aqdiagram/data/negate.c new file mode 100644 index 0000000..6a7b988 --- /dev/null +++ b/src/lib/aqdiagram/data/negate.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * 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 +#endif + +#include "./negate.h" + + + +AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_NegateY(const AQDG_GRAPH_DATAPAIR_LIST *dpList) +{ + if (dpList && AQDG_Graph_DataPair_List_GetCount(dpList)) { + AQDG_GRAPH_DATAPAIR_LIST *newList; + const AQDG_GRAPH_DATAPAIR *dp; + + newList=AQDG_Graph_DataPair_List_new(); + dp=AQDG_Graph_DataPair_List_First(dpList); + while(dp) { + AQDG_GRAPH_DATAPAIR *newDp; + double v; + + v=AQDG_Graph_DataPair_GetValueY(dp); + newDp=AQDG_Graph_DataPair_dup(dp); + AQDG_Graph_DataPair_SetValueY(newDp, -v); + AQDG_Graph_DataPair_List_Add(newDp, newList); + + dp=AQDG_Graph_DataPair_List_Next(dp); + } + return newList; + } + return NULL; +} + + + +AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_NegateX(const AQDG_GRAPH_DATAPAIR_LIST *dpList) +{ + if (dpList && AQDG_Graph_DataPair_List_GetCount(dpList)) { + AQDG_GRAPH_DATAPAIR_LIST *newList; + const AQDG_GRAPH_DATAPAIR *dp; + + newList=AQDG_Graph_DataPair_List_new(); + dp=AQDG_Graph_DataPair_List_First(dpList); + while(dp) { + AQDG_GRAPH_DATAPAIR *newDp; + double v; + + v=AQDG_Graph_DataPair_GetValueX(dp); + newDp=AQDG_Graph_DataPair_dup(dp); + AQDG_Graph_DataPair_SetValueX(newDp, -v); + AQDG_Graph_DataPair_List_Add(newDp, newList); + + dp=AQDG_Graph_DataPair_List_Next(dp); + } + return newList; + } + return NULL; +} + + + +void AQDG_Data_NegateInPlaceY(AQDG_GRAPH_DATAPAIR_LIST *dpList) +{ + if (dpList && AQDG_Graph_DataPair_List_GetCount(dpList)) { + AQDG_GRAPH_DATAPAIR *dp; + + dp=AQDG_Graph_DataPair_List_First(dpList); + while(dp) { + double v; + + v=AQDG_Graph_DataPair_GetValueY(dp); + AQDG_Graph_DataPair_SetValueY(dp, -v); + + dp=AQDG_Graph_DataPair_List_Next(dp); + } + } +} + + + +void AQDG_Data_NegateInPlaceX(AQDG_GRAPH_DATAPAIR_LIST *dpList) +{ + if (dpList && AQDG_Graph_DataPair_List_GetCount(dpList)) { + AQDG_GRAPH_DATAPAIR *dp; + + dp=AQDG_Graph_DataPair_List_First(dpList); + while(dp) { + double v; + + v=AQDG_Graph_DataPair_GetValueX(dp); + AQDG_Graph_DataPair_SetValueX(dp, -v); + + dp=AQDG_Graph_DataPair_List_Next(dp); + } + } +} + + diff --git a/src/lib/aqdiagram/data/negate.h b/src/lib/aqdiagram/data/negate.h new file mode 100644 index 0000000..4e96178 --- /dev/null +++ b/src/lib/aqdiagram/data/negate.h @@ -0,0 +1,37 @@ +/**************************************************************************** + * 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. + ****************************************************************************/ + +#ifndef AQDG_DATA_NEGATE_H +#define AQDG_DATA_NEGATE_H + +#include + + + +#ifdef __cplusplus +extern "C" { +#endif + + + +AQDG_API AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_NegateY(const AQDG_GRAPH_DATAPAIR_LIST *dpList); +AQDG_API AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_NegateX(const AQDG_GRAPH_DATAPAIR_LIST *dpList); + +AQDG_API void AQDG_Data_NegateInPlaceY(AQDG_GRAPH_DATAPAIR_LIST *dpList); +AQDG_API void AQDG_Data_NegateInPlaceX(AQDG_GRAPH_DATAPAIR_LIST *dpList); + + + +#ifdef __cplusplus +} +#endif + + + +#endif +