Skip to content

Commit

Permalink
fix: Clamp t-value for fractional rounding edgecase
Browse files Browse the repository at this point in the history
  • Loading branch information
Undistraction committed Jul 29, 2024
1 parent f2a7690 commit 8208dc5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/utils/coons.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const getCoordinateOnSurface = ({
)
}

const clampT = (t) => Math.min(Math.max(t, 0), 1)

// -----------------------------------------------------------------------------
// Exports
// -----------------------------------------------------------------------------
Expand All @@ -43,11 +45,16 @@ export const getPointOnSurface = (
v,
interpolatePointOnCurve
) => {
// Due to potential minute rounding errors we clamp these values to avoid
// issues with the interpolators which expect a range of 0–1.
const uResolved = clampT(u)
const vResolved = clampT(v)

const boundaryPoints = {
pointOnTopBoundary: interpolatePointOnCurve(u, top),
pointOnBottomBoundary: interpolatePointOnCurve(u, bottom),
pointOnLeftBoundary: interpolatePointOnCurve(v, left),
pointOnRightBoundary: interpolatePointOnCurve(v, right),
pointOnTopBoundary: interpolatePointOnCurve(uResolved, top),
pointOnBottomBoundary: interpolatePointOnCurve(uResolved, bottom),
pointOnLeftBoundary: interpolatePointOnCurve(vResolved, left),
pointOnRightBoundary: interpolatePointOnCurve(vResolved, right),
}

const cornerPoints = {
Expand Down

0 comments on commit 8208dc5

Please sign in to comment.