* @function push * @private * @param {Number[]} xs the x positions of points in the curve * @param {Number[]} ys the y positions of points in the curve * @param {Object} v the curve information * * adds a curve to the rows & columns that it intersects wit
(xs, ys, v)
| 228 | * adds a curve to the rows & columns that it intersects with |
| 229 | */ |
| 230 | function push(xs, ys, v) { |
| 231 | const index = strokes.length; // the index of this stroke |
| 232 | strokes.push(v); // add this stroke to the list |
| 233 | |
| 234 | /** |
| 235 | * @function minMax |
| 236 | * @private |
| 237 | * @param {Number[]} rg the list of values to compare |
| 238 | * @param {Number} min the initial minimum value |
| 239 | * @param {Number} max the initial maximum value |
| 240 | * |
| 241 | * find the minimum & maximum value in a list of values |
| 242 | */ |
| 243 | function minMax(rg, min, max) { |
| 244 | for (let i = rg.length; i-- > 0; ) { |
| 245 | const v = rg[i]; |
| 246 | if (min > v) min = v; |
| 247 | if (max < v) max = v; |
| 248 | } |
| 249 | return { min, max }; |
| 250 | } |
| 251 | |
| 252 | // Expand the bounding box of the glyph by the number of cells below |
| 253 | // before rounding. Curves only partially through a cell won't be added |
| 254 | // to adjacent cells, but ones that are close will be. This helps fix |
| 255 | // small visual glitches that occur when curves are close to grid cell |
| 256 | // boundaries. |
| 257 | const cellOffset = 0.5; |
| 258 | |
| 259 | // loop through the rows & columns that the curve intersects |
| 260 | // adding the curve to those slices |
| 261 | const mmX = minMax(xs, 1, 0); |
| 262 | const ixMin = Math.max( |
| 263 | Math.floor(mmX.min * charGridWidth - cellOffset), |
| 264 | 0 |
| 265 | ); |
| 266 | const ixMax = Math.min( |
| 267 | Math.ceil(mmX.max * charGridWidth + cellOffset), |
| 268 | charGridWidth |
| 269 | ); |
| 270 | for (let iCol = ixMin; iCol < ixMax; ++iCol) cols[iCol].push(index); |
| 271 | |
| 272 | const mmY = minMax(ys, 1, 0); |
| 273 | const iyMin = Math.max( |
| 274 | Math.floor(mmY.min * charGridHeight - cellOffset), |
| 275 | 0 |
| 276 | ); |
| 277 | const iyMax = Math.min( |
| 278 | Math.ceil(mmY.max * charGridHeight + cellOffset), |
| 279 | charGridHeight |
| 280 | ); |
| 281 | for (let iRow = iyMin; iRow < iyMax; ++iRow) rows[iRow].push(index); |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * @function clamp |
no outgoing calls
no test coverage detected