34 lines
1.2 KiB
Dart
34 lines
1.2 KiB
Dart
|
|
// lib/editor/engine/pen_physics.dart
|
|||
|
|
//
|
|||
|
|
// Simple physical tip model: modulate stroke width by tip velocity so fountain
|
|||
|
|
// ink feels slightly thinner when moving fast (starvation), while ballpoint
|
|||
|
|
// stays nearly velocity-invariant.
|
|||
|
|
//
|
|||
|
|
// TODO(pen-physics-wire): wired at capture in PenCanvas._toNormalized via
|
|||
|
|
// tip velocity × pressure. PDF editor path still uses brush gamma only.
|
|||
|
|
|
|||
|
|
import 'brush.dart';
|
|||
|
|
|
|||
|
|
/// Modulate width fraction by tip velocity (page-normalized units per second).
|
|||
|
|
///
|
|||
|
|
/// Fountain: faster → slightly thinner (ink starvation feel).
|
|||
|
|
/// Ballpoint: nearly ignore velocity.
|
|||
|
|
/// Pencil: mild thinning at speed.
|
|||
|
|
/// Highlighter: ignore velocity (flat marker).
|
|||
|
|
double tipVelocityWidthScale(BrushKind kind, double speedNormPerSec) {
|
|||
|
|
final speed =
|
|||
|
|
speedNormPerSec.isNaN || speedNormPerSec < 0 ? 0.0 : speedNormPerSec;
|
|||
|
|
// Reference: ~2 page-widths/sec ≈ fast handwriting; clamp influence to [0,1].
|
|||
|
|
final t = (speed / 2.0).clamp(0.0, 1.0);
|
|||
|
|
switch (kind) {
|
|||
|
|
case BrushKind.fountainPen:
|
|||
|
|
return 1.0 - 0.15 * t;
|
|||
|
|
case BrushKind.ballpoint:
|
|||
|
|
return 1.0 - 0.02 * t;
|
|||
|
|
case BrushKind.pencil:
|
|||
|
|
return 1.0 - 0.08 * t;
|
|||
|
|
case BrushKind.highlighter:
|
|||
|
|
return 1.0;
|
|||
|
|
}
|
|||
|
|
}
|