Skip to content

fix(core): normalize non-pen pressure for freehand#58

Open
enieuwy wants to merge 1 commit into
antfu:mainfrom
enieuwy:fix/normalize-non-pen-pressure
Open

fix(core): normalize non-pen pressure for freehand#58
enieuwy wants to merge 1 commit into
antfu:mainfrom
enieuwy:fix/normalize-non-pen-pressure

Conversation

@enieuwy

@enieuwy enieuwy commented Apr 18, 2026

Copy link
Copy Markdown

Closes #57.

Summary

This normalizes freehand pressure for non-pen pointer input while preserving real pressure for pen input.

Today BaseModel.getMousePosition() forwards raw event.pressure for every pointer type. StylusModel then feeds those points into perfect-freehand with:

  • thinning: 0.9
  • simulatePressure: false

That means non-pen inputs (mouse, touch) can produce different saved freehand geometry at the same nominal brush size, depending on the platform/browser's reported pressure behavior.

Change

Use real pressure only for pens:

pressure: event.pointerType === 'pen' ? event.pressure : 0.5

This is applied in both coordinate paths of BaseModel.getMousePosition().

Why 0.5

0.5 is the conventional active-pressure baseline for hardware without meaningful pressure support, and it matches the desktop mouse baseline that many browsers already use.

Scope

  • preserves Apple Pencil / pen pressure behavior
  • normalizes mouse and touch to the same freehand pressure baseline
  • does not change line/rect/ellipse behavior beyond using the same point pressure normalization when applicable

Verification

  • pnpm install --frozen-lockfile
  • pnpm build
  • locally verified downstream that the resulting freehand SVG geometry for synthetic mouse vs touch input at the same brush size becomes consistent after this patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Freehand strokes differ between mouse and touch at the same brush size

1 participant