mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Enhance fuzzy equality function for improved precision handling
- Updated the fuzzyEq function to utilize both absolute and relative epsilon for better precision when comparing numbers. This change improves the handling of small and large values, ensuring more accurate equality checks in the reconciliation process.
This commit is contained in:
parent
3c33054afd
commit
d21331cb65
1 changed files with 6 additions and 1 deletions
|
|
@ -43,7 +43,12 @@ local function findDuplicateNames(children: { Instance } | { string }, virtualIn
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fuzzyEq(a: number, b: number, epsilon: number): boolean
|
local function fuzzyEq(a: number, b: number, epsilon: number): boolean
|
||||||
return math.abs(a - b) < epsilon
|
local diff = math.abs(a - b)
|
||||||
|
-- Use both absolute and relative epsilon for better precision handling
|
||||||
|
-- Absolute: for small numbers near zero
|
||||||
|
-- Relative: for larger numbers where absolute epsilon is too tight
|
||||||
|
local maxVal = math.max(math.abs(a), math.abs(b), 1)
|
||||||
|
return diff < epsilon or diff < maxVal * epsilon
|
||||||
end
|
end
|
||||||
|
|
||||||
local function trueEquals(a, b): boolean
|
local function trueEquals(a, b): boolean
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue