Skip to content

Commit 678453d

Browse files
author
camilo
committed
doc update. Add setData methods to interp1
1 parent 1e9be20 commit 678453d

File tree

7 files changed

+85
-9
lines changed

7 files changed

+85
-9
lines changed

check/qlibs_cpp_test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,17 @@ void test_interp1( void )
405405
cout << interpolation.get( 3.1 ) << endl;
406406
cout << interpolation.get( 0.5 ) << endl;
407407
cout << interpolation.get( 5.0 ) << endl;
408+
409+
410+
real_t xdat[] = { 1.0f, 6.0f, 11.0f, 16.0f, 21.0f, 26.0f, 31.0f, 36.0f };
411+
real_t ydat[] = { 59.6870f, 44.5622f, -0.8642f , 0.8725f, -2.3016f, -50.3095f, -54.5966f, 37.9036f };
412+
interp1 interpolation2( xdat, ydat );
413+
interpolation2.setMethod( INTERP1_HERMITE );
414+
cout << "spline test 2" << endl;
415+
for( int i = 1; i<36;i++) {
416+
417+
cout << i << " " << interpolation2.get( i ) << endl;
418+
}
408419
}
409420

410421
int main()

doc/mainpage.dox

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* - @subpage qtdl_desc "TDL : Tapped Delay Line in O(1)"
4040
* - Type-generic array operations
4141
* - Fast floating-point math library
42-
* - 1D Interpolation class
42+
* - @subpage qinterp1_desc "1D Interpolation class"
4343
*/
4444

4545
/**

doc/qinterp1.dox

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*! @page qinterp1_desc 1D Interpolation class
2+
* The \ref qlibs::interp1 class provides a simple, consistent interface for a set of
3+
* one-dimensional interpolators. The class recieves X-Values and Y-Values and
4+
* the size of this arrays to setup the instance. The user can later pass the
5+
* X point to interpolate, and the interpolator instance return the estimated Y
6+
* at the point X using the specified method.
7+
*
8+
* The current supported methods are:
9+
* - qlibs::INTERP1_NEXT : Return the next neighbor.
10+
* - qlibs::INTERP1_PREVIOUS : Return the previous neighbor.
11+
* - qlibs::INTERP1_NEAREST : Return the nearest neighbor.
12+
* - qlibs::INTERP1_LINEAR : Linear interpolation from nearest neighbors.
13+
* - qlibs::INTERP1_SINE : Sine interpolation.
14+
* - qlibs::INTERP1_CUBIC : Cubic interpolation.
15+
* - qlibs::INTERP1_HERMITE : Piecewise cubic Hermite interpolation.
16+
* - qlibs::INTERP1_SPLINE : Catmull spline interpolation.
17+
* - qlibs::INTERP1_CONSTRAINED_SPLINE : A special kind of spline that doesn't overshoot.
18+
*
19+
* If value if beyond the endpoints, extrapolation is performed using the current
20+
* method.
21+
*
22+
* @section qinterp1_ex1 Example : Code snippet that demonstrates the spline interpolation .
23+
*
24+
* @code{.c}
25+
* real_t xdat[] = { 1.0f, 6.0f, 11.0f, 16.0f, 21.0f, 26.0f, 31.0f, 36.0f };
26+
* real_t ydat[] = { 59.6870f, 44.5622f, -0.8642f , 0.8725f, -2.3016f, -50.3095f, -54.5966f, 37.9036f };
27+
* interp1 interpolator( xdat, ydat );
28+
* interpolator.setMethod( INTERP1_SPLINE );
29+
* auto ye = interpolator.get( 18.5f ); //interpolated value at 18.5
30+
* @endcode
31+
*
32+
*/

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"maintainer": true
1717
}
1818
],
19-
"version": "1.0.9",
19+
"version": "1.1.0",
2020
"license": "MIT",
2121
"frameworks": "arduino",
2222
"platforms": "*"

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=qlibs
2-
version=1.0.9
2+
version=1.1.0
33
license=MIT
44
author=J. Camilo Gomez C. <[email protected]>
55
maintainer=J. Camilo Gomez C. <[email protected]>

src/include/interp1.hpp

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,55 @@ namespace qlibs {
109109
/**
110110
* @brief Constructor for the 1D interpolation instance.
111111
* @param[in] xTable An array of size @a sizeTable with the x points sorted in ascending order.
112-
* @param[in] yTabLe An array of size @a sizeTable with the y points.
112+
* @param[in] yTable An array of size @a sizeTable with the y points.
113113
* @param[in] sizeTable The number of points in @a xTable @a yTable
114114
*/
115115
interp1( const real_t * const xTable,
116-
const real_t * const yTabLe,
117-
const size_t sizeTable ) : xData( xTable ), yData( yTabLe ), dataSize( sizeTable ) {}
116+
const real_t * const yTable,
117+
const size_t sizeTable ) : xData( xTable ), yData( yTable ), dataSize( sizeTable ) {}
118118

119119
/**
120120
* @brief Constructor for the 1D interpolation instance.
121121
* @param[in] xTable An array of size @a sizeTable with the x points sorted in ascending order.
122-
* @param[in] yTabLe An array of size @a sizeTable with the y points.
122+
* @param[in] yTable An array of size @a sizeTable with the y points.
123123
*/
124124
template <size_t sizeTable>
125125
interp1( real_t (&xTable)[ sizeTable ],
126126
real_t (&yTable)[ sizeTable ] ) : interp1( xTable, yTable, sizeTable ) {}
127127

128+
/**
129+
* @brief Set the data table for the 1D interpolation instance.
130+
* @param[in] xTable An array of size @a sizeTable with the x points sorted in ascending order.
131+
* @param[in] yTable An array of size @a sizeTable with the y points.
132+
* @param[in] sizeTable The number of points in @a xTable @a yTable
133+
*/
134+
bool setData( const real_t * const xTable,
135+
const real_t * const yTable,
136+
const size_t sizeTable )
137+
{
138+
bool retValue = false;
139+
140+
if ( ( nullptr != xTable ) && ( nullptr != yTable ) && ( sizeTable >= 4U ) ) {
141+
xData = xTable;
142+
yData = yTable;
143+
dataSize = sizeTable;
144+
retValue = true;
145+
}
146+
return retValue;
147+
}
148+
149+
/**
150+
* @brief Set the data for the 1D interpolation instance.
151+
* @param[in] xTable An array of size @a sizeTable with the x points sorted in ascending order.
152+
* @param[in] yTable An array of size @a sizeTable with the y points.
153+
*/
154+
template <size_t sizeTable>
155+
bool setData( real_t (&xTable)[ sizeTable ],
156+
real_t (&yTable)[ sizeTable ] )
157+
{
158+
return setData( xTable, yTable, sizeTable );
159+
}
160+
128161
/**
129162
* @brief Specify the interpolation method to use.
130163
* @param[in] m The interpolation method.

src/qlibs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ This file is part of the QuarkTS++ OS distribution.
4141
#ifndef QLIBS_CPP_H
4242
#define QLIBS_CPP_H
4343

44-
#define QLIBS_CPP_VERSION "1.0.9"
45-
#define QLIBS_CPP_VERNUM ( 109U )
44+
#define QLIBS_CPP_VERSION "1.1.0"
45+
#define QLIBS_CPP_VERNUM ( 110U )
4646
#define QLIBS_CPP_CAPTION "qLibs++" QLIBS_CPP_VERSION
4747

4848
#include <include/qlibs_types.hpp>

0 commit comments

Comments
 (0)