Skip to content

Commit

Permalink
fix: Round point coordinates before validating proximity
Browse files Browse the repository at this point in the history
  • Loading branch information
Undistraction committed Jul 27, 2024
1 parent 184d131 commit 9412509
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/utils/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const roundToN = (n, value) => Number(value.toFixed(n))
// -----------------------------------------------------------------------------

export const roundTo10 = (value) => roundToN(10, value)
export const roundTo5 = (value) => roundToN(5, value)

export const binomial = (n, k) => {
if (n === 0) {
Expand Down
11 changes: 10 additions & 1 deletion src/utils/validation.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { mapObj } from './functional'
import { roundTo5 } from './math'
import { isArray, isInt, isNil, isPlainObj } from './types'

// -----------------------------------------------------------------------------
// Utils
// -----------------------------------------------------------------------------

const getPointsAreSame = (point1, point2) => {
return point1.x === point2.x && point2.y === point2.y
// Round the points to 5 decimal places to avoid rounding issues where the
// values are fractionally different
const roundedPoint1 = mapObj(roundTo5, point1)
const roundedPoint2 = mapObj(roundTo5, point2)

return (
roundedPoint1.x === roundedPoint2.x && roundedPoint1.y === roundedPoint2.y
)
}

// -----------------------------------------------------------------------------
Expand Down

0 comments on commit 9412509

Please sign in to comment.