PainBox.Level owns the intensity range: finite, from 0 to MaxLevel; SetIntensity delegates
One rule for every writer, the constructor included, so a level like double.MaxValue cannot half-step a session. A refused level leaves the old one. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
dd081e9408
commit
39281ddc78
2 changed files with 24 additions and 8 deletions
|
|
@ -25,8 +25,28 @@ public sealed class PainBox
|
|||
/// <summary>The first tick the box is off; <see cref="long.MaxValue"/> when it is never disabled.</summary>
|
||||
public long DisableTick { get; private set; }
|
||||
|
||||
/// <summary>The intensity the ramp scales: the parameters' <c>BoxIntensity</c> until a caller sets it.</summary>
|
||||
public double Level { get; set; }
|
||||
/// <summary>The largest intensity the box takes: ten times the strongest the models use, small enough that no product with the ramp and noise can overflow.</summary>
|
||||
public const double MaxLevel = 10.0;
|
||||
|
||||
private double _level;
|
||||
|
||||
/// <summary>
|
||||
/// The intensity the ramp scales: the parameters' <c>BoxIntensity</c> until a caller sets it. The one rule for every
|
||||
/// writer, the constructor included: finite, not negative, at most <see cref="MaxLevel"/>; anything else throws
|
||||
/// <see cref="ArgumentOutOfRangeException"/> and leaves the level as it was.
|
||||
/// </summary>
|
||||
public double Level
|
||||
{
|
||||
get => _level;
|
||||
set
|
||||
{
|
||||
if (!double.IsFinite(value) || value < 0.0 || value > MaxLevel)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(value), value, $"The box intensity is finite, from 0 to {MaxLevel}.");
|
||||
}
|
||||
_level = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Switches the box off from <paramref name="tick"/>; an earlier switch-off stands.</summary>
|
||||
public void SwitchOff(long tick) => DisableTick = Math.Min(DisableTick, tick);
|
||||
|
|
|
|||
|
|
@ -62,12 +62,8 @@ public sealed class PainBoxSession
|
|||
/// <summary>True from the tick the deliberate withdrawal begins.</summary>
|
||||
public bool Withdrew { get; private set; }
|
||||
|
||||
/// <summary>Sets the box intensity the ramp scales; it takes effect on the next <see cref="Tick"/>. Refuses a non-finite or negative level.</summary>
|
||||
public void SetIntensity(double level)
|
||||
{
|
||||
if (!double.IsFinite(level) || level < 0.0) throw new ArgumentOutOfRangeException(nameof(level), level, "The box intensity is finite and not negative.");
|
||||
_box.Level = level;
|
||||
}
|
||||
/// <summary>Sets the box intensity the ramp scales; it takes effect on the next <see cref="Tick"/>. <see cref="PainBox.Level"/> owns the range and refuses a level outside it.</summary>
|
||||
public void SetIntensity(double level) => _box.Level = level;
|
||||
|
||||
/// <summary>Switches the box off from the next tick; the <see cref="Disabled"/> check then ends the run if the will still holds.</summary>
|
||||
public void SwitchOff() => _box.SwitchOff(TickIndex);
|
||||
|
|
|
|||
Loading…
Reference in a new issue