Skip to content

Commit 7e550d6

Browse files
committed
rewritten search interval
1 parent 2f35600 commit 7e550d6

27 files changed

+604
-415
lines changed

src/SplineAkima.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ namespace Splines {
141141
} while ( iend < m_npts );
142142

143143
Utils::check_NaN( m_Yp, msg+" Yp", m_npts, __LINE__, __FILE__ );
144+
m_search.reset();
144145
}
145146

146147
#ifndef DOXYGEN_SHOULD_SKIP_THIS

src/SplineAkima2D.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ namespace Splines {
7272
for ( integer i{0}; i < m_nx; ++i ) Z[i] = z_node(i,j);
7373

7474
#ifdef DEBUG_AKIMA
75-
msg = fmt::format("Akima2Dspline::make_spline Z1 {} in [0,{})", j, m_ny );
75+
msg = fmt::format( "Akima2Dspline::make_spline Z1 {} in [0,{})", j, m_ny );
7676
Utils::check_NaN( Z, msg, m_nx, __LINE__, __FILE__ );
7777
#endif
7878

7979
Akima_build( m_X, Z, Zp, m, m_nx );
8080

8181
#ifdef DEBUG_AKIMA
82-
msg = fmt::format("Akima2Dspline::make_spline Zp1 {} in [0,{})", j, m_ny );
82+
msg = fmt::format( "Akima2Dspline::make_spline Zp1 {} in [0,{})", j, m_ny );
8383
Utils::check_NaN( Zp, msg, m_nx, __LINE__, __FILE__ );
8484
#endif
8585

@@ -90,14 +90,14 @@ namespace Splines {
9090
for ( integer j{0}; j < m_ny; ++j ) Z[j] = z_node(i,j);
9191

9292
#ifdef DEBUG_AKIMA
93-
msg = fmt::format("Akima2Dspline::make_spline Z2 {} in [0,{})", i, m_nx );
93+
msg = fmt::format( "Akima2Dspline::make_spline Z2 {} in [0,{})", i, m_nx );
9494
Utils::check_NaN( Z, msg, m_ny, __LINE__, __FILE__ );
9595
#endif
9696

9797
Akima_build( m_Y, Z, Zp, m, m_ny );
9898

9999
#ifdef DEBUG_AKIMA
100-
msg = fmt::format("Akima2Dspline::make_spline Zp2 {} in [0,{})", i, m_nx );
100+
msg = fmt::format( "Akima2Dspline::make_spline Zp2 {} in [0,{})", i, m_nx );
101101
Utils::check_NaN( Zp, msg, m_ny, __LINE__, __FILE__ );
102102
#endif
103103

@@ -108,14 +108,14 @@ namespace Splines {
108108
for ( integer i{0}; i < m_nx; ++i ) Z[i] = Dy_node(i,j);
109109

110110
#ifdef DEBUG_AKIMA
111-
msg = fmt::format("Akima2Dspline::make_spline Zp3 {} in [0,{})", j, m_ny );
111+
msg = fmt::format( "Akima2Dspline::make_spline Zp3 {} in [0,{})", j, m_ny );
112112
Utils::check_NaN( Z, msg, m_nx, __LINE__, __FILE__ );
113113
#endif
114114

115115
Akima_build( m_X, Z, Zp, m, m_nx );
116116

117117
#ifdef DEBUG_AKIMA
118-
msg = fmt::format("Akima2Dspline::make_spline Zp3 {} in [0,{})", j, m_ny );
118+
msg = fmt::format( "Akima2Dspline::make_spline Zp3 {} in [0,{})", j, m_ny );
119119
Utils::check_NaN( Zp, msg, m_nx, __LINE__, __FILE__ );
120120
#endif
121121

@@ -133,14 +133,14 @@ namespace Splines {
133133
for ( integer j{0}; j < m_ny; ++j ) Z[j] = Dx_node(i,j);
134134

135135
#ifdef DEBUG_AKIMA
136-
msg = fmt::format("Akima2Dspline::make_spline Z4 {} in [0,{})", i, m_nx );
136+
msg = fmt::format( "Akima2Dspline::make_spline Z4 {} in [0,{})", i, m_nx );
137137
Utils::check_NaN( Z, msg, m_ny, __LINE__, __FILE__ );
138138
#endif
139139

140140
Akima_build( m_Y, Z, Zp, m, m_ny );
141141

142142
#ifdef DEBUG_AKIMA
143-
msg = fmt::format("Akima2Dspline::make_spline Zp4 {} in [0,{})", i, m_nx );
143+
msg = fmt::format( "Akima2Dspline::make_spline Zp4 {} in [0,{})", i, m_nx );
144144
Utils::check_NaN( Zp, msg, m_ny, __LINE__, __FILE__ );
145145
#endif
146146

@@ -150,6 +150,9 @@ namespace Splines {
150150
Utils::check_NaN( m_DX, "Akima2Dspline::make_spline DX ", nn, __LINE__, __FILE__ );
151151
Utils::check_NaN( m_DY, "Akima2Dspline::make_spline DY ", nn, __LINE__, __FILE__ );
152152
Utils::check_NaN( m_DXY, "Akima2Dspline::make_spline DXY ", nn, __LINE__, __FILE__ );
153+
154+
m_search_x.reset();
155+
m_search_y.reset();
153156
}
154157

155158
void

src/SplineBessel.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ namespace Splines {
115115
} while ( iend < m_npts );
116116

117117
Utils::check_NaN( m_Yp, msg+" Yp", m_npts, __LINE__, __FILE__ );
118+
m_search.reset();
118119
}
119120

120121
using GC_namespace::GC_type;

src/SplineBiCubic.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ namespace Splines {
5656
make_derivative_y( m_Z, m_DY );
5757
make_derivative_xy( m_DX, m_DY, m_DXY );
5858

59+
m_search_x.reset();
60+
m_search_y.reset();
5961
}
6062

6163
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

src/SplineBiQuintic.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ namespace Splines {
6262

6363
make_derivative_xy( m_DXXY, m_DXYY, m_DXXYY );
6464

65+
m_search_x.reset();
66+
m_search_y.reset();
6567
}
6668

6769
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

src/SplineBilinear.cc

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,25 @@ namespace Splines {
3939

4040
real_type
4141
BilinearSpline::eval( real_type x, real_type y ) const {
42-
integer const i { this->search_x( x ) };
43-
integer const j { this->search_y( y ) };
42+
std::pair<integer,real_type> X(0,x), Y(0,y);
43+
44+
m_search_x.find( X );
45+
m_search_y.find( Y );
46+
47+
integer const i { X.first };
48+
integer const j { Y.first };
4449
real_type const DX { m_X[i+1] - m_X[i] };
4550
real_type const DY { m_Y[j+1] - m_Y[j] };
46-
real_type const u { (x-m_X[i])/DX };
47-
real_type const v { (y-m_Y[j])/DY };
51+
real_type const u { (X.second-m_X[i])/DX };
52+
real_type const v { (Y.second-m_Y[j])/DY };
4853
real_type const u1 { 1-u };
4954
real_type const v1 { 1-v };
50-
real_type const Z00 { m_Z[this->ipos_C(i,j)] };
51-
real_type const Z01 { m_Z[this->ipos_C(i,j+1)] };
52-
real_type const Z10 { m_Z[this->ipos_C(i+1,j)] };
53-
real_type const Z11 { m_Z[this->ipos_C(i+1,j+1)] };
55+
56+
real_type const Z00 { m_Z[ipos_C(i,j)] };
57+
real_type const Z01 { m_Z[ipos_C(i,j+1)] };
58+
real_type const Z10 { m_Z[ipos_C(i+1,j)] };
59+
real_type const Z11 { m_Z[ipos_C(i+1,j+1)] };
60+
5461
return u1 * ( Z00 * v1 + Z01 * v ) +
5562
u * ( Z10 * v1 + Z11 * v );
5663
}
@@ -59,11 +66,18 @@ namespace Splines {
5966

6067
real_type
6168
BilinearSpline::Dx( real_type x, real_type y ) const {
62-
integer const i { this->search_x( x ) };
63-
integer const j { this->search_y( y ) };
69+
std::pair<integer,real_type> X(0,x), Y(0,y);
70+
71+
m_search_x.find( X );
72+
m_search_y.find( Y );
73+
74+
integer const i { X.first };
75+
integer const j { Y.first };
76+
6477
real_type const DX { m_X[i+1] - m_X[i] };
6578
real_type const DY { m_Y[j+1] - m_Y[j] };
66-
real_type const v { (y-m_Y[j])/DY };
79+
real_type const v { (Y.second-m_Y[j])/DY };
80+
6781
real_type const Z00 { m_Z[ipos_C(i,j)] };
6882
real_type const Z01 { m_Z[ipos_C(i,j+1)] };
6983
real_type const Z10 { m_Z[ipos_C(i+1,j)] };
@@ -75,11 +89,18 @@ namespace Splines {
7589

7690
real_type
7791
BilinearSpline::Dy( real_type x, real_type y ) const {
78-
integer const i { this->search_x( x ) };
79-
integer const j { this->search_y( y ) };
92+
std::pair<integer,real_type> X(0,x), Y(0,y);
93+
94+
m_search_x.find( X );
95+
m_search_y.find( Y );
96+
97+
integer const i { X.first };
98+
integer const j { Y.first };
99+
80100
real_type const DX { m_X[i+1] - m_X[i] };
81101
real_type const DY { m_Y[j+1] - m_Y[j] };
82-
real_type const u { (x-m_X[i])/DX };
102+
real_type const u { (X.second-m_X[i])/DX };
103+
83104
real_type const Z00 { m_Z[ipos_C(i,j)] };
84105
real_type const Z01 { m_Z[ipos_C(i,j+1)] };
85106
real_type const Z10 { m_Z[ipos_C(i+1,j)] };
@@ -91,18 +112,27 @@ namespace Splines {
91112

92113
void
93114
BilinearSpline::D( real_type x, real_type y, real_type d[3] ) const {
94-
integer const i { this->search_x( x ) };
95-
integer const j { this->search_y( y ) };
115+
std::pair<integer,real_type> X(0,x), Y(0,y);
116+
117+
m_search_x.find( X );
118+
m_search_y.find( Y );
119+
120+
integer const i { X.first };
121+
integer const j { Y.first };
122+
96123
real_type const DX { m_X[i+1] - m_X[i] };
97124
real_type const DY { m_Y[j+1] - m_Y[j] };
98-
real_type const u { (x-m_X[i])/DX };
99-
real_type const v { (y-m_Y[j])/DY };
125+
126+
real_type const u { (X.second-m_X[i])/DX };
127+
real_type const v { (Y.second-m_Y[j])/DY };
100128
real_type const u1 { 1-u };
101129
real_type const v1 { 1-v };
130+
102131
real_type const Z00 { m_Z[this->ipos_C(i,j)] };
103132
real_type const Z01 { m_Z[this->ipos_C(i,j+1)] };
104133
real_type const Z10 { m_Z[this->ipos_C(i+1,j)] };
105134
real_type const Z11 { m_Z[this->ipos_C(i+1,j+1)] };
135+
106136
d[0] = u1 * ( Z00 * v1 + Z01 * v ) + u * ( Z10 * v1 + Z11 * v );
107137
d[1] = v1 * (Z10-Z00) + v * (Z11-Z01); d[1] /= DX;
108138
d[2] = u1 * (Z01-Z00) + u * (Z11-Z10); d[2] /= DY;

src/SplineConstant.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ namespace Splines {
6060
m_external_alloc = true;
6161
m_X = p_x;
6262
m_Y = p_y;
63-
init_last_interval();
6463
}
6564

6665
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -76,7 +75,6 @@ namespace Splines {
7675
m_X = m_mem_constant( npts );
7776
m_Y = m_mem_constant( npts );
7877
}
79-
init_last_interval();
8078
m_npts = 0;
8179
}
8280

@@ -86,7 +84,7 @@ namespace Splines {
8684
real_type
8785
ConstantSpline::eval( real_type x ) const {
8886
std::pair<integer,real_type> res(0,x);
89-
this->search( res );
87+
m_search.find( res );
9088
return m_Y[res.first];
9189
}
9290

src/SplineCubic.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,15 +466,16 @@ namespace Splines {
466466
do {
467467
// cerca intervallo monotono strettamente crescente
468468
for ( ++iend; iend < m_npts && m_X[iend-1] < m_X[iend]; ++iend ) {}
469-
auto seg_bc0 = CubicSpline_BC::NOT_A_KNOT;
470-
auto seg_bcn = CubicSpline_BC::NOT_A_KNOT;
469+
auto seg_bc0{ CubicSpline_BC::NOT_A_KNOT };
470+
auto seg_bcn{ CubicSpline_BC::NOT_A_KNOT };
471471
if ( ibegin == 0 ) seg_bc0 = m_bc0;
472472
if ( iend == m_npts ) seg_bcn = m_bcn;
473473
CubicSpline_build( m_X+ibegin, m_Y+ibegin, m_Yp+ibegin, iend - ibegin, seg_bc0, seg_bcn );
474474
ibegin = iend;
475475
} while ( iend < m_npts );
476476

477477
Utils::check_NaN( m_Yp, msg+" Yp", m_npts, __LINE__, __FILE__ );
478+
m_search.reset();
478479
}
479480

480481
#ifndef DOXYGEN_SHOULD_SKIP_THIS

src/SplineCubicBase.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ namespace Splines {
6262
m_Yp[i] = yp[i*incyp];
6363
}
6464
m_npts = n;
65+
m_search.reset();
6566
}
6667

6768
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -75,7 +76,7 @@ namespace Splines {
7576
integer N{ static_cast<integer>(x.size()) };
7677
if ( N > static_cast<integer>(y.size()) ) N = static_cast<integer>(y.size());
7778
if ( N > static_cast<integer>(yp.size()) ) N = static_cast<integer>(yp.size());
78-
this->build (
79+
this->build(
7980
x.data(), 1,
8081
y.data(), 1,
8182
yp.data(), 1,
@@ -107,7 +108,6 @@ namespace Splines {
107108
m_Yp = m_mem_cubic( npts );
108109
m_external_alloc = false;
109110
}
110-
init_last_interval();
111111
m_npts = 0;
112112
}
113113

@@ -118,14 +118,14 @@ namespace Splines {
118118
integer const n,
119119
real_type *& p_x,
120120
real_type *& p_y,
121-
real_type *& p_dy
121+
real_type *& p_dy
122122
) {
123123
m_npts_reserved = n;
124124
m_X = p_x;
125125
m_Y = p_y;
126126
m_Yp = p_dy;
127127
m_external_alloc = true;
128-
init_last_interval();
128+
m_npts = 0;
129129
}
130130

131131
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -149,7 +149,7 @@ namespace Splines {
149149
real_type
150150
CubicSplineBase::eval( real_type x ) const {
151151
std::pair<integer,real_type> res(0,x);
152-
this->search( res );
152+
m_search.find( res );
153153
return this->id_eval( res.first, res.second );
154154
}
155155

@@ -173,7 +173,7 @@ namespace Splines {
173173
real_type
174174
CubicSplineBase::D( real_type x ) const {
175175
std::pair<integer,real_type> res(0,x);
176-
this->search( res );
176+
m_search.find( res );
177177
return this->id_D( res.first, res.second );
178178
}
179179

@@ -197,7 +197,7 @@ namespace Splines {
197197
real_type
198198
CubicSplineBase::DD( real_type x ) const {
199199
std::pair<integer,real_type> res(0,x);
200-
this->search( res );
200+
m_search.find( res );
201201
return this->id_DD( res.first, res.second );
202202
}
203203

@@ -221,7 +221,7 @@ namespace Splines {
221221
real_type
222222
CubicSplineBase::DDD( real_type x ) const {
223223
std::pair<integer,real_type> res(0,x);
224-
this->search( res );
224+
m_search.find( res );
225225
return this->id_DDD( res.first, res.second );
226226
}
227227

src/SplineHermite.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ namespace Splines {
175175
base_DDD[3] = t9*(168*t3-24*t1-t14);
176176
base_DDD[4] = t25*(36*t3-9*t1-t22);
177177
base_DDD[5] = t25*(3*t1-24*t3+t22);
178-
179178
}
180179

181180
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -197,7 +196,6 @@ namespace Splines {
197196
base_DDDD[3] = t6*(168*H-t10);
198197
base_DDDD[4] = t19*(36*H-t16);
199198
base_DDDD[5] = t19*(t16-24*H);
200-
201199
}
202200

203201
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

0 commit comments

Comments
 (0)