11 #if defined __cplusplus
49 else if( y2 > yMax ) {
55 return( ptwXY1->
status = status );
56 for( i = 0; i <
n; i++ ) {
62 if( points->
y > yMin ) {
68 for( i++; i <
n; i++ )
if( !( ptwXY1->
points[i].
y < yMin ) )
break;
76 else if( j != n - 1 ) {
80 else if( y2 > yMax ) {
83 if( points->
y < yMax ) {
89 for( i++; i <
n; i++ )
if( !( ptwXY1->
points[i].
y > yMax ) )
break;
97 else if( j != n - 1 ) {
121 return( ptwXY1->
status = status );
131 x = ( y -
y1 ) * ( x2 - x1 ) / ( y2 -
y1 ) + x1;
146 double x1,
x2 = 0.,
y1,
y2 = 0., fx = 1.1,
x,
dx, dxp, lfx,
y;
147 int64_t i, notFirstPass = 0;
148 int nfx, nDone, doLinear;
152 if( ( sectionSubdivideMax < 1 ) || ( dxMax < 0. ) || ( fxMax < 1. ) )
return(
nfu_badInput );
155 for( i = ptwXY1->
length - 1; i >= 0; i-- ) {
168 nfx = sectionSubdivideMax; }
170 nfx = ( (
int) ( lfx /
G4Log( fxMax ) ) ) + 1;
171 if( nfx > sectionSubdivideMax ) nfx = sectionSubdivideMax;
173 if( nfx > 0 ) fx =
G4Exp( lfx / nfx );
175 if( dx < ( fx - 1 ) * x1 ) doLinear = 1; }
188 if( dx <= ( fx - 1 ) *
x ) {
193 dxp = ( fx - 1. ) *
x;
196 if( ( x2 -
x ) < 0.05 * std::fabs( dxp ) )
break;
218 if( length < 3 )
return(
ptwXY_clone( ptwXY1, status ) );
222 if( accuracy < ptwXY1->accuracy ) accuracy = ptwXY1->
accuracy;
229 for( i = 2, j = 1; i <
length; i++ ) {
231 if( ( y1 != y2 ) || ( y2 != y3 ) ) {
240 length = thinned->
length = j;
241 if( ( thin = (
char *)
nfu_calloc( 1, (
size_t) length ) ) == NULL )
goto Err;
242 if( ( *status =
ptwXY_thin2( thinned, thin, accuracy, 0, length - 1 ) ) !=
nfu_Okay )
goto Err;
243 for( j = 1; j <
length; j++ )
if( thin[j] != 0 )
break;
244 for( i = j + 1; i <
length; i++ ) {
258 if( thin != NULL )
nfu_free( thin );
267 double y,
s,
dY, dYMax = 0., dYR, dYRMax = 0;
271 if( i1 + 1 >= i2 )
return(
nfu_Okay );
272 for( i = i1 + 1; i < i2; i++ ) {
274 s = 0.5 * ( std::fabs( y ) + std::fabs( thinned->
points[i].
y ) );
275 dY = std::fabs( y - thinned->
points[i].
y );
277 if( s != 0 ) dYR = dY /
s;
278 if( ( dYR > dYRMax ) || ( ( dYR >= 0.9999 * dYRMax ) && ( dY > dYMax ) ) ) {
280 if( dY > dYMax ) dYMax =
dY;
281 if( dYR > dYRMax ) dYRMax = dYR;
284 if( dYRMax < accuracy ) {
285 for( i = i1 + 1; i < i2; i++ ) thin[i] = 1; }
287 if( ( status =
ptwXY_thin2( thinned, thin, accuracy, i1, iMax ) ) !=
nfu_Okay )
return( status );
288 status =
ptwXY_thin2( thinned, thin, accuracy, iMax, i2 );
298 double dx = x2 -
x1, dndx;
301 dx = ( x2 -
x1 ) / sectionSubdivideMax; }
305 if( ( dndx - ndx ) > 1
e-6 ) ndx++;
306 if( ndx > sectionSubdivideMax ) ndx = sectionSubdivideMax;
307 if( ndx > 0 ) dx /= ndx;
325 for( i1 = 0; i1 < ptwXY->
length; i1++ ) {
326 if( ptwXY->
points[i1].
y != 0 )
break;
329 for( i2 = ptwXY->
length - 1; i2 >= 0; i2-- ) {
330 if( ptwXY->
points[i2].
y != 0 )
break;
333 if( i2 < ptwXY->
length ) i2++;
336 for( i = i1; i < i2; i++ ) ptwXY->
points[i - i1] = ptwXY->
points[i];
338 ptwXY->
length = i2 - i1; }
354 double x1 = 0.,
x2 = 0.,
y1 = 0.,
y2 = 0.,
y, biSectionMax, accuracy;
366 if( (
n1 == 1 ) || ( n2 == 1 ) ) {
376 if( fillWithFirst ) {
377 if( i1 < ( ptwXY1->
length - 1 ) ) {
415 if( biSectionMax < ptwXY2->biSectionMax ) biSectionMax = ptwXY2->
biSectionMax;
417 if( accuracy < ptwXY2->accuracy ) accuracy = ptwXY2->
accuracy;
419 if( n == NULL )
return( NULL );
421 for( i = 0; ( i1 <
n1 ) && ( i2 < n2 ); i++ ) {
425 if( fillWithFirst ) {
427 if( i1 < ( ptwXY1->
length - 1 ) ) {
441 if( fillWithFirst && ( (
y1 != 0. ) || (
y2 != 0. ) ) ) {
453 for( ; i1 <
n1; i1++, i++ ) {
455 if( fillWithFirst )
y = ptwXY1->
points[i1].
y;
458 for( ; i2 < n2; i2++, i++ ) {
460 if( fillWithFirst && trim && ( n->
points[i].
x <=
x2 ) ) {
492 for( i1 = 0, p1 = ptwXY->
points; i1 < length; i1++, p1++ ) {
493 p1->
x = xScale * p1->
x + xOffset;
494 p1->
y = yScale * p1->
y + yOffset;
498 int64_t length_2 = length / 2;
501 for( i1 = 0, p1 = ptwXY->
points, p2 = &(ptwXY->
points[length-1]); i1 < length_2; i1++ ) {
511 #if defined __cplusplus