fix(VarWatch): better speed efficiency fraction representation#70
fix(VarWatch): better speed efficiency fraction representation#70Aurumaker72 wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the speed efficiency fraction display in the VarWatch module by extracting the fraction-formatting logic into a new reusable Formatter.fraction utility function, replacing an inline multi-branch conditional.
Changes:
- Adds a new
Formatter.fraction(value, denominator)function that rounds a[0,1]value to the nearest fraction with the given denominator. - Updates
VarWatch'sspd_efficiencyhandler to callFormatter.fraction(spd_efficiency, 4)instead of the inlined if/elseif chain.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/core/Formatter.lua |
Adds Formatter.fraction, a generic utility to format a [0,1] float as a fraction string |
src/core/VarWatch.lua |
Simplifies the spd_efficiency display by delegating fraction formatting to Formatter.fraction |
| ---@param value number A number in the range 0-1. | ||
| ---@param denominator number The denominator of the fraction. | ||
| ---@return string The value's string representation as a fraction. | ||
| Formatter.fraction = function(value, denominator) |
There was a problem hiding this comment.
The Formatter.fraction function clamps value to the range [0, 1] before computing the numerator. However, Engine.GetSpeedEfficiency() can return values greater than 1 (it computes the ratio of actual distance moved to sliding speed, which has no upper bound). This means any efficiency above 1 (i.e., above 100%) will be silently clamped and displayed as 4/4 regardless of the actual value.
For consistency with Formatter.percent — which handles super-threshold values by rendering ∞% — Formatter.fraction (or its caller in VarWatch) should handle out-of-range values explicitly, for example by returning something like >4/4 or a special symbol when value > 1, rather than silently clamping and misrepresenting the data.
| Formatter.fraction = function(value, denominator) | |
| Formatter.fraction = function(value, denominator) | |
| if value > 1 then | |
| return string.format('>%d/%d', denominator, denominator) | |
| end |
Improves speed efficiency fraction representation.