namespace Febe.Browser.Gestures;
/// A point in CSS pixels relative to the page viewport (the coordinate space of Input.*).
public readonly record struct PagePoint(double X, double Y)
{
public double DistanceTo(PagePoint other) => Math.Sqrt(((X - other.X) * (X - other.X)) + ((Y - other.Y) * (Y - other.Y)));
}
/// A rectangle in CSS pixels relative to the page viewport.
public readonly record struct PageRect(double X, double Y, double Width, double Height)
{
public PagePoint Center => new(X + (Width / 2), Y + (Height / 2));
public double Right => X + Width;
public double Bottom => Y + Height;
public bool Contains(PagePoint p) => p.X >= X && p.X <= Right && p.Y >= Y && p.Y <= Bottom;
}
/// An interval «from a to b» with an optional median (spec §7.2), in the unit of its use.
public readonly record struct Interval(double Min, double Max, double? Median = null);
///
/// Gesture timings for the «naturale» pace (spec §7.7). Every wait is multiplied by the session mood and by the
/// pace factor. Milliseconds unless stated otherwise.
///
public sealed record GestureSettings
{
public static GestureSettings Natural { get; } = new();
/// Pointer travel time.
public Interval MoveDurationMs { get; init; } = new(250, 900);
/// Interval between pointer events: about 60 per second.
public double PointerEventIntervalMs { get; init; } = 1000.0 / 60.0;
/// Largest sideways bend of the path, as a fraction of the distance (a slightly curved path).
public Interval PathBendFraction { get; init; } = new(0.02, 0.12);
/// Part of the target, around its centre, where the pointer lands (0.6 = central 60% in each direction).
public double CentralFraction { get; init; } = 0.6;
/// Hover on the target before pressing.
public Interval HoverMs { get; init; } = new(80, 300);
/// Time between press and release.
public Interval PressMs { get; init; } = new(50, 140);
/// Wheel events in a burst.
public (int Min, int Max) WheelEventsPerBurst { get; init; } = (3, 8);
/// Pixels per wheel event.
public Interval WheelDeltaPx { get; init; } = new(80, 140);
/// Interval between the wheel events of a burst.
public Interval WheelIntervalMs { get; init; } = new(12, 40);
/// Pause between bursts.
public Interval BetweenBurstsMs { get; init; } = new(400, 4000, 1100);
/// Bursts between two reading pauses.
public (int Min, int Max) BurstsBeforeReading { get; init; } = (6, 10);
/// Reading pause.
public Interval ReadingPauseMs { get; init; } = new(3000, 20000, 6000);
/// Probability of a small scroll back after a burst.
public double ScrollBackProbability { get; init; } = 0.1;
/// Pixels per wheel event of a scroll back.
public Interval ScrollBackDeltaPx { get; init; } = new(40, 100);
/// Wait after a page load before the first gesture.
public Interval AfterLoadMs { get; init; } = new(1000, 6000, 2200);
/// Probability of a distraction after an action.
public double DistractionProbability { get; init; } = 0.08;
/// Length of a distraction.
public Interval DistractionMs { get; init; } = new(15000, 90000);
/// Gap between two keys while typing (issue #37), before mood and pace.
public Interval KeyGapMs { get; init; } = new(60, 250, 110);
/// How long a key is held down.
public Interval KeyHoldMs { get; init; } = new(40, 120);
/// Probability of a short hesitation before a key, as a person who thinks of the next letter.
public double TypingHesitationProbability { get; init; } = 0.03;
/// Length of such a hesitation, before mood and pace.
public Interval TypingHesitationMs { get; init; } = new(300, 900);
}