add data functions to negate data

This commit is contained in:
Martin Preuss
2025-12-29 18:35:40 +01:00
parent ade43e02ff
commit 0fa6a592aa
3 changed files with 144 additions and 0 deletions

View File

@@ -59,6 +59,7 @@
<headers dist="true" install="$(pkgincludedir)/data"> <headers dist="true" install="$(pkgincludedir)/data">
average.h average.h
accumulate.h accumulate.h
negate.h
floatingavg.h floatingavg.h
date.h date.h
diff.h diff.h
@@ -72,6 +73,7 @@
$(local/typefiles) $(local/typefiles)
average.c average.c
accumulate.c accumulate.c
negate.c
floatingavg.c floatingavg.c
date.c date.c
diff.c diff.c

View File

@@ -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 <config.h>
#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);
}
}
}

View File

@@ -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 <aqdiagram/graph/datapair.h>
#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