< Summary

Information
Class: Chronicis.Client.Utilities.PressureToWidth
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Utilities/PressureToWidth.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 25
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Compute(...)100%66100%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Utilities/PressureToWidth.cs

#LineLine coverage
 1namespace Chronicis.Client.Utilities;
 2
 3/// <summary>
 4/// Maps stylus pressure values to stroke widths for the drawing canvas.
 5/// Mirrors the JavaScript pressureToWidth function in drawingCanvas.js.
 6/// </summary>
 7internal static class PressureToWidth
 8{
 9    private const double MinWidth = 1.0;
 10    private const double MaxWidth = 8.0;
 11    private const double DefaultWidth = 2.0;
 12
 13    /// <summary>
 14    /// Computes the stroke width from a pressure value.
 15    /// For pressure in (0.0, 1.0], returns clamp(pressure * 8, 1, 8).
 16    /// For pressure == 0 or absent (null), returns 2px default.
 17    /// </summary>
 18    public static double Compute(double? pressure)
 19    {
 30220        if (pressure is null or 0.0)
 221            return DefaultWidth;
 22
 30023        return Math.Clamp(pressure.Value * 8.0, MinWidth, MaxWidth);
 24    }
 25}