Skip to content

Commit

Permalink
Prevent intersectionRatio from being higher than 1 in IntersectionObs…
Browse files Browse the repository at this point in the history
…erverEntry (#41448)

Summary:
Pull Request resolved: #41448

This was possible before due to precision problems with `double` (we were seeing values like 1.000000002). This is an easy way to prevent that problem.

Changelog: [internal]

Reviewed By: rshest

Differential Revision: D51230183

fbshipit-source-id: 757ef181fe369d525831faf8a6d907467efc544c
  • Loading branch information
rubennorte authored and facebook-github-bot committed Nov 14, 2023
1 parent 11aadb7 commit 5948ab7
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ export default class IntersectionObserverEntry {
return 0;
}

return (
const ratio =
(intersectionRect.width * intersectionRect.height) /
(boundingClientRect.width * boundingClientRect.height)
);
(boundingClientRect.width * boundingClientRect.height);

// Prevent rounding errors from making this value greater than 1.
return Math.min(ratio, 1);
}

/**
Expand Down

0 comments on commit 5948ab7

Please sign in to comment.