Stylus state modeler

Up till now we have only used the raw input stream to create a new smoothed stream of positions, leaving behind the pressure attribute. This is what’s done here, to model the state of the stylus for these new position based on the pressure data of the raw input strokes.
Algorithm Stylus state modeler
Input :


initialize d = d = \infty , index = None \text{index} = \text{None} , interp = None \text{interp } = \text{ None}
for i = n n search i = n - n_{\text{search}} to n 1 n - 1 do
- Find q i q_{i} the position that’s closest to q q on the segment [ p [ i ] , p [ i + 1 ] ] \left\lbrack p\lbrack i\rbrack,p\lbrack i + 1\rbrack \right\rbrack and denote r [ 0 , 1 ] r \in \lbrack 0,1\rbrack the value such that q i = ( 1 r ) p [ i ] + r p [ i + 1 ] q_{i} = (1 - r)p\lbrack i\rbrack + rp\lbrack i + 1\rbrack
- if q q i < d \left. \parallel{q - q_{i}} \right.\parallel < d
- d q q i < d index = i interp = r \begin{array}{r} d \leftarrow \left. \parallel{q - q_{i}} \right.\parallel < d \\ \text{index } = i \\ \text{interp } = r \end{array}
- endif
endfor
calculate ν = ( 1 r ) ν [ index ] + r ν [ index + 1 ] \nu = (1 - r)\nu\left\lbrack \text{index} \right\rbrack + r\nu\left\lbrack \text{index } + 1 \right\rbrack
Output : interpolated pressure ν \nu