My App
BoardKitCore

Drawing Algorithms

Point simplification, pressure mapping, and stroke smoothing

The @hfu.digital/boardkit-core drawing module provides algorithms for processing raw pointer input into smooth, optimized strokes.

Point Simplification

Reduces the number of points in a stroke while preserving its visual shape. Uses the Ramer-Douglas-Peucker algorithm.

import { simplifyPoints } from '@hfu.digital/boardkit-core';

const simplified = simplifyPoints(rawPoints, tolerance);
ParameterTypeDescription
pointsPoint[]Raw input points
tolerancenumberDistance tolerance for point removal (default: 1.0)

Higher tolerance values produce fewer points (more simplified), while lower values preserve more detail.

Pressure Mapping

Maps raw stylus pressure values to actual stroke width.

import { pressureToWidth } from '@hfu.digital/boardkit-core';

const width = pressureToWidth(pressure, baseWidth);
ParameterTypeDescription
pressurenumberRaw pressure value (0–1)
baseWidthnumberBase stroke width in pixels
minMultipliernumberMinimum width multiplier (default: 0.3)
maxMultipliernumberMaximum width multiplier (default: 1.5)

Pressure values range from 0.0 to 1.0. The function returns baseWidth * multiplier, where the multiplier is linearly interpolated between minMultiplier and maxMultiplier based on pressure.

Stroke Smoothing

Applies Catmull-Rom spline interpolation to smooth jagged strokes.

import { smoothPoints } from '@hfu.digital/boardkit-core';

const smoothed = smoothPoints(points, tension);
ParameterTypeDescription
pointsPoint[]Input points to smooth
tensionnumberSpline tension (0.0 = straight lines, 1.0 = maximum smoothing)

Pipeline

These algorithms are typically chained in the input pipeline:

Raw PointerEvents → Collect points
  → smoothPoints() (reduce jitter)
  → simplifyPoints() (reduce point count)
  → pressureToWidth() (apply pressure sensitivity)
  → Create StrokeElement

On this page