File indexing completed on 2025-01-18 09:59:33
0001
0002
0003
0004
0005
0006 #ifndef ptwXY_h_included
0007 #define ptwXY_h_included
0008
0009 #include <stdio.h>
0010 #include <stdint.h>
0011
0012 #include <nf_utilities.h>
0013 #include <ptwX.h>
0014
0015 #if defined __cplusplus
0016 extern "C" {
0017 namespace GIDI {
0018 #endif
0019
0020 #define ptwXY_minimumSize 10
0021 #define ptwXY_minimumOverflowSize 4
0022 #define ptwXY_maxBiSectionMax 20
0023 #define ptwXY_minAccuracy 1e-14
0024 #define ptwXY_sectionSubdivideMax 1 << 16
0025 #define ClosestAllowXFactor 10
0026
0027 typedef enum ptwXY_dataFrom_e { ptwXY_dataFrom_Unknown, ptwXY_dataFrom_Points, ptwXY_dataFrom_Overflow } ptwXY_dataFrom;
0028 typedef enum ptwXY_group_normType_e { ptwXY_group_normType_none, ptwXY_group_normType_dx, ptwXY_group_normType_norm } ptwXY_group_normType;
0029
0030
0031 #define ptwXY_union_fill 1
0032 #define ptwXY_union_trim 2
0033 #define ptwXY_union_mergeClosePoints 4
0034 typedef enum ptwXY_sigma_e { ptwXY_sigma_none, ptwXY_sigma_plusMinus, ptwXY_sigma_Minus, ptwXY_sigma_plus } ptwXY_sigma;
0035 typedef enum ptwXY_interpolation_e { ptwXY_interpolationLinLin, ptwXY_interpolationLinLog, ptwXY_interpolationLogLin, ptwXY_interpolationLogLog,
0036 ptwXY_interpolationFlat, ptwXY_interpolationOther } ptwXY_interpolation;
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 typedef enum ptwXY_lessEqualGreaterX_e { ptwXY_lessEqualGreaterX_empty, ptwXY_lessEqualGreaterX_lessThan, ptwXY_lessEqualGreaterX_equal,
0058 ptwXY_lessEqualGreaterX_between, ptwXY_lessEqualGreaterX_greater } ptwXY_lessEqualGreaterX;
0059
0060 typedef
0061 struct ptwXYPoint_s {
0062 double x, y;
0063 } ptwXYPoint;
0064
0065 typedef nfu_status (*ptwXY_createFromFunction_callback)( double x, double *y, void *argList );
0066 typedef nfu_status (*ptwXY_applyFunction_callback)( ptwXYPoint *point, void *argList );
0067 typedef nfu_status (*ptwXY_getValue_callback)( void *argList, double x, double *y, double x1, double y1, double x2, double y2 );
0068
0069 typedef struct {
0070 char const *interpolationString;
0071 ptwXY_getValue_callback getValueFunc;
0072 void *argList;
0073 } ptwXY_interpolationOtherInfo;
0074
0075 typedef
0076 struct ptwXYOverflowPoint_s {
0077 struct ptwXYOverflowPoint_s *prior;
0078 struct ptwXYOverflowPoint_s *next;
0079 int64_t index;
0080 ptwXYPoint point;
0081 } ptwXYOverflowPoint;
0082
0083 typedef
0084 struct ptwXYPoints_s {
0085 nfu_status status;
0086 ptwXY_sigma typeX, typeY;
0087 ptwXY_interpolation interpolation;
0088 ptwXY_interpolationOtherInfo interpolationOtherInfo;
0089 int userFlag;
0090 double biSectionMax;
0091 double accuracy;
0092 double minFractional_dx;
0093 int64_t length;
0094 int64_t allocatedSize;
0095 int64_t overflowLength;
0096 int64_t overflowAllocatedSize;
0097 int64_t mallocFailedSize;
0098 ptwXYOverflowPoint overflowHeader;
0099 ptwXYPoint *points;
0100 ptwXYOverflowPoint *overflowPoints;
0101 } ptwXYPoints;
0102
0103
0104
0105
0106 ptwXYPoints *ptwXY_new( ptwXY_interpolation interpolation, ptwXY_interpolationOtherInfo const *interpolationOtherInfo, double biSectionMax,
0107 double accuracy, int64_t primarySize, int64_t secondarySize, nfu_status *status, int userFlag );
0108 nfu_status ptwXY_setup( ptwXYPoints *ptwXY, ptwXY_interpolation interpolation, ptwXY_interpolationOtherInfo const *interpolationOtherInfo,
0109 double biSectionMax, double accuracy, int64_t primarySize, int64_t secondarySize, int userFlag );
0110 ptwXYPoints *ptwXY_create( ptwXY_interpolation interpolation, ptwXY_interpolationOtherInfo const *interpolationOtherInfo,
0111 double biSectionMax, double accuracy, int64_t primarySize, int64_t secondarySize, int64_t length, double const *xy,
0112 nfu_status *status, int userFlag );
0113 ptwXYPoints *ptwXY_createFrom_Xs_Ys( ptwXY_interpolation interpolation, ptwXY_interpolationOtherInfo const *interpolationOtherInfo,
0114 double biSectionMax, double accuracy, int64_t primarySize, int64_t secondarySize, int64_t length, double const *Xs,
0115 double const *Ys, nfu_status *status, int userFlag );
0116
0117 nfu_status ptwXY_copy( ptwXYPoints *dest, ptwXYPoints *src );
0118 ptwXYPoints *ptwXY_clone( ptwXYPoints *ptwXY, nfu_status *status );
0119 ptwXYPoints *ptwXY_cloneToInterpolation( ptwXYPoints *ptwXY, ptwXY_interpolation interpolationTo, nfu_status *status );
0120 ptwXYPoints *ptwXY_slice( ptwXYPoints *ptwXY, int64_t index1, int64_t index2, int64_t secondarySize, nfu_status *status );
0121 ptwXYPoints *ptwXY_xSlice( ptwXYPoints *ptwXY, double xMin, double xMax, int64_t secondarySize, int fill, nfu_status *status );
0122 ptwXYPoints *ptwXY_xMinSlice( ptwXYPoints *ptwXY, double xMin, int64_t secondarySize, int fill, nfu_status *status );
0123 ptwXYPoints *ptwXY_xMaxSlice( ptwXYPoints *ptwXY, double xMax, int64_t secondarySize, int fill, nfu_status *status );
0124
0125 ptwXY_interpolation ptwXY_getInterpolation( ptwXYPoints *ptwXY );
0126 char const *ptwXY_getInterpolationString( ptwXYPoints *ptwXY );
0127 nfu_status ptwXY_getStatus( ptwXYPoints *ptwXY );
0128 int ptwXY_getUserFlag( ptwXYPoints *ptwXY );
0129 void ptwXY_setUserFlag( ptwXYPoints *ptwXY, int userFlag );
0130 double ptwXY_getAccuracy( ptwXYPoints *ptwXY );
0131 double ptwXY_setAccuracy( ptwXYPoints *ptwXY, double accuracy );
0132 double ptwXY_getBiSectionMax( ptwXYPoints *ptwXY );
0133 double ptwXY_setBiSectionMax( ptwXYPoints *ptwXY, double biSectionMax );
0134
0135 nfu_status ptwXY_reallocatePoints( ptwXYPoints *ptwXY, int64_t size, int forceSmallerResize );
0136 nfu_status ptwXY_reallocateOverflowPoints( ptwXYPoints *ptwXY, int64_t size );
0137 nfu_status ptwXY_coalescePoints( ptwXYPoints *ptwXY, int64_t size, ptwXYPoint *newPoint, int forceSmallerResize );
0138 nfu_status ptwXY_simpleCoalescePoints( ptwXYPoints *ptwXY );
0139
0140 nfu_status ptwXY_clear( ptwXYPoints *ptwXY );
0141 nfu_status ptwXY_release( ptwXYPoints *ptwXY );
0142 ptwXYPoints *ptwXY_free( ptwXYPoints *ptwXY );
0143
0144 int64_t ptwXY_length( ptwXYPoints *ptwXY );
0145 int64_t ptwXY_getNonOverflowLength( ptwXYPoints const *ptwXY );
0146
0147 nfu_status ptwXY_setXYData( ptwXYPoints *ptwXY, int64_t length, double const *xy );
0148 nfu_status ptwXY_setXYDataFromXsAndYs( ptwXYPoints *ptwXY, int64_t length, double const *x, double const *y );
0149 nfu_status ptwXY_deletePoints( ptwXYPoints *ptwXY, int64_t i1, int64_t i2 );
0150 ptwXYPoint *ptwXY_getPointAtIndex( ptwXYPoints *ptwXY, int64_t index );
0151 ptwXYPoint *ptwXY_getPointAtIndex_Unsafely( ptwXYPoints *ptwXY, int64_t index );
0152 nfu_status ptwXY_getXYPairAtIndex( ptwXYPoints *ptwXY, int64_t index, double *x, double *y );
0153 ptwXY_lessEqualGreaterX ptwXY_getPointsAroundX( ptwXYPoints *ptwXY, double x, ptwXYOverflowPoint *lessThanEqualXPoint, ptwXYOverflowPoint *greaterThanXPoint );
0154 ptwXY_lessEqualGreaterX ptwXY_getPointsAroundX_closeIsEqual( ptwXYPoints *ptwXY, double x, ptwXYOverflowPoint *lessThanEqualXPoint,
0155 ptwXYOverflowPoint *greaterThanXPoint, double eps, int *closeIsEqual, ptwXYPoint **closePoint );
0156 nfu_status ptwXY_getValueAtX( ptwXYPoints *ptwXY, double x, double *y );
0157 nfu_status ptwXY_setValueAtX( ptwXYPoints *ptwXY, double x, double y );
0158 nfu_status ptwXY_setValueAtX_overrideIfClose( ptwXYPoints *ptwXY, double x, double y, double eps, int override );
0159 nfu_status ptwXY_mergeFromXsAndYs( ptwXYPoints *ptwXY, int length, double *xs, double *ys );
0160 nfu_status ptwXY_mergeFromXYs( ptwXYPoints *ptwXY, int length, double *xys );
0161 nfu_status ptwXY_appendXY( ptwXYPoints *ptwXY, double x, double y );
0162 nfu_status ptwXY_setXYPairAtIndex( ptwXYPoints *ptwXY, int64_t index, double x, double y );
0163
0164 nfu_status ptwXY_getSlopeAtX( ptwXYPoints *ptwXY, double x, const char side, double *slope );
0165
0166 double ptwXY_getXMinAndFrom( ptwXYPoints *ptwXY, ptwXY_dataFrom *dataFrom );
0167 double ptwXY_getXMin( ptwXYPoints *ptwXY );
0168 double ptwXY_getXMaxAndFrom( ptwXYPoints *ptwXY, ptwXY_dataFrom *dataFrom );
0169 double ptwXY_getXMax( ptwXYPoints *ptwXY );
0170 double ptwXY_getYMin( ptwXYPoints *ptwXY );
0171 double ptwXY_getYMax( ptwXYPoints *ptwXY );
0172
0173
0174
0175
0176 nfu_status ptwXY_clip( ptwXYPoints *ptwXY1, double yMin, double yMax );
0177 nfu_status ptwXY_thicken( ptwXYPoints *ptwXY1, int sectionSubdivideMax, double dxMax, double fxMax );
0178 ptwXYPoints *ptwXY_thin( ptwXYPoints *ptwXY1, double accuracy, nfu_status *status );
0179 nfu_status ptwXY_trim( ptwXYPoints *ptwXY );
0180
0181 ptwXYPoints *ptwXY_union( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, nfu_status *status, int unionOptions );
0182
0183 nfu_status ptwXY_scaleOffsetXAndY( ptwXYPoints *ptwXY, double xScale, double xOffset, double yScale, double yOffset );
0184
0185
0186
0187
0188 nfu_status ptwXY_abs( ptwXYPoints *ptwXY );
0189 nfu_status ptwXY_neg( ptwXYPoints *ptwXY );
0190
0191
0192
0193
0194 nfu_status ptwXY_slopeOffset( ptwXYPoints *ptwXY, double slope, double offset );
0195 nfu_status ptwXY_add_double( ptwXYPoints *ptwXY, double value );
0196 nfu_status ptwXY_sub_doubleFrom( ptwXYPoints *ptwXY, double value );
0197 nfu_status ptwXY_sub_fromDouble( ptwXYPoints *ptwXY, double value );
0198 nfu_status ptwXY_mul_double( ptwXYPoints *ptwXY, double value );
0199 nfu_status ptwXY_div_doubleFrom( ptwXYPoints *ptwXY, double value );
0200 nfu_status ptwXY_div_fromDouble( ptwXYPoints *ptwXY, double value );
0201 nfu_status ptwXY_mod( ptwXYPoints *ptwXY, double m, int pythonMod );
0202
0203 ptwXYPoints *ptwXY_binary_ptwXY( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, double v1, double v2, double v1v2, nfu_status *status );
0204 ptwXYPoints *ptwXY_add_ptwXY( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, nfu_status *status );
0205 ptwXYPoints *ptwXY_sub_ptwXY( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, nfu_status *status );
0206 ptwXYPoints *ptwXY_mul_ptwXY( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, nfu_status *status );
0207 ptwXYPoints *ptwXY_mul2_ptwXY( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, nfu_status *status );
0208 ptwXYPoints *ptwXY_div_ptwXY( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, nfu_status *status, int safeDivide );
0209
0210
0211
0212
0213 nfu_status ptwXY_pow( ptwXYPoints *ptwXY, double p );
0214 nfu_status ptwXY_exp( ptwXYPoints *ptwXY, double a );
0215 ptwXYPoints *ptwXY_convolution( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, nfu_status *status, int mode );
0216
0217
0218
0219
0220 nfu_status ptwXY_interpolatePoint( ptwXY_interpolation interpolation, double x, double *y, double x1, double y1, double x2, double y2 );
0221 ptwXYPoints *ptwXY_flatInterpolationToLinear( ptwXYPoints *ptwXY, double lowerEps, double upperEps, nfu_status *status );
0222 ptwXYPoints *ptwXY_toOtherInterpolation( ptwXYPoints *ptwXY, ptwXY_interpolation interpolation, double accuracy, nfu_status *status );
0223 ptwXYPoints *ptwXY_unitbaseInterpolate( double w, double w1, ptwXYPoints *ptwXY1, double w2, ptwXYPoints *ptwXY2, nfu_status *status );
0224 ptwXYPoints *ptwXY_toUnitbase( ptwXYPoints *ptwXY, nfu_status *status );
0225 ptwXYPoints *ptwXY_fromUnitbase( ptwXYPoints *ptwXY, double xMin, double xMax, nfu_status *status );
0226
0227
0228
0229
0230 ptwXPoints *ptwXY_getXArray( ptwXYPoints *ptwXY, nfu_status *status );
0231 nfu_status ptwXY_dullEdges( ptwXYPoints *ptwXY, double lowerEps, double upperEps, int positiveXOnly );
0232 nfu_status ptwXY_mergeClosePoints( ptwXYPoints *ptwXY, double epsilon );
0233 ptwXYPoints *ptwXY_intersectionWith_ptwX( ptwXYPoints *ptwXY, ptwXPoints *ptwX, nfu_status *status );
0234 nfu_status ptwXY_areDomainsMutual( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2 );
0235 nfu_status ptwXY_tweakDomainsToMutualify( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, int epsilonFactor, double epsilon );
0236 nfu_status ptwXY_mutualifyDomains( ptwXYPoints *ptwXY1, double lowerEps1, double upperEps1, int positiveXOnly1,
0237 ptwXYPoints *ptwXY2, double lowerEps2, double upperEps2, int positiveXOnly2 );
0238 nfu_status ptwXY_copyToC_XY( ptwXYPoints *ptwXY, int64_t index1, int64_t index2, int64_t allocatedSize, int64_t *numberOfPoints, double *xy );
0239 nfu_status ptwXY_valueTo_ptwXAndY( ptwXYPoints *ptwXY, double **xs, double **ys );
0240 ptwXYPoints *ptwXY_valueTo_ptwXY( double x1, double x2, double y, nfu_status *status );
0241 ptwXYPoints *ptwXY_createGaussianCenteredSigma1( double accuracy, nfu_status *status );
0242 ptwXYPoints *ptwXY_createGaussian( double accuracy, double xCenter, double sigma, double amplitude, double xMin, double xMax,
0243 double dullEps, nfu_status *status );
0244
0245
0246
0247
0248 void ptwXY_update_biSectionMax( ptwXYPoints *ptwXY1, double oldLength );
0249 ptwXYPoints *ptwXY_createFromFunction( int n, double *xs, ptwXY_createFromFunction_callback func, void *argList, double accuracy, int checkForRoots,
0250 int biSectionMax, nfu_status *status );
0251 ptwXYPoints *ptwXY_createFromFunction2( ptwXPoints *xs, ptwXY_createFromFunction_callback func, void *argList, double accuracy, int checkForRoots,
0252 int biSectionMax, nfu_status *status );
0253 nfu_status ptwXY_applyFunction( ptwXYPoints *ptwXY1, ptwXY_applyFunction_callback func, void *argList, int checkForRoots );
0254 ptwXYPoints *ptwXY_fromString( char const *str, ptwXY_interpolation interpolation, ptwXY_interpolationOtherInfo const *interpolationOtherInfo,
0255 double biSectionMax, double accuracy, char **endCharacter, nfu_status *status );
0256
0257 void ptwXY_showInteralStructure( ptwXYPoints *ptwXY, FILE *f, int printPointersAsNull );
0258 void ptwXY_simpleWrite( ptwXYPoints *ptwXY, FILE *f, char *format );
0259 void ptwXY_simplePrint( ptwXYPoints *ptwXY, char *format );
0260
0261
0262
0263
0264 nfu_status ptwXY_f_integrate( ptwXY_interpolation interpolation, double x1, double y1, double x2, double y2, double *value );
0265 double ptwXY_integrate( ptwXYPoints *ptwXY, double xMin, double xMax, nfu_status *status );
0266 double ptwXY_integrateDomain( ptwXYPoints *ptwXY, nfu_status *status );
0267 nfu_status ptwXY_normalize( ptwXYPoints *ptwXY1 );
0268 double ptwXY_integrateDomainWithWeight_x( ptwXYPoints *ptwXY, nfu_status *status );
0269 double ptwXY_integrateWithWeight_x( ptwXYPoints *ptwXY, double xMin, double xMax, nfu_status *status );
0270 double ptwXY_integrateDomainWithWeight_sqrt_x( ptwXYPoints *ptwXY, nfu_status *status );
0271 double ptwXY_integrateWithWeight_sqrt_x( ptwXYPoints *ptwXY, double xMin, double xMax, nfu_status *status );
0272 ptwXPoints *ptwXY_groupOneFunction( ptwXYPoints *ptwXY, ptwXPoints *groupBoundaries, ptwXY_group_normType normType, ptwXPoints *ptwX_norm, nfu_status *status );
0273 ptwXPoints *ptwXY_groupTwoFunctions( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, ptwXPoints *groupBoundaries, ptwXY_group_normType normType,
0274 ptwXPoints *ptwX_norm, nfu_status *status );
0275 ptwXPoints *ptwXY_groupThreeFunctions( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, ptwXYPoints *ptwXY3, ptwXPoints *groupBoundaries,
0276 ptwXY_group_normType normType, ptwXPoints *ptwX_norm, nfu_status *status );
0277 ptwXPoints *ptwXY_runningIntegral( ptwXYPoints *ptwXY, nfu_status *status );
0278 double ptwXY_integrateWithFunction( ptwXYPoints *ptwXY, ptwXY_createFromFunction_callback func, void *argList,
0279 double xMin, double xMax, int degree, int recursionLimit, double tolerance, nfu_status *status );
0280
0281 #if defined __cplusplus
0282 }
0283 }
0284 #endif
0285
0286 #endif