From 0e3e6953c36a1b61201dec36b4792ec77edda06b Mon Sep 17 00:00:00 2001 From: Pedr Date: Wed, 8 Jan 2025 13:56:09 +0000 Subject: [PATCH] fix: Check defaults for nil --- .../interpolatePointOnSurfaceBilinear.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/interpolate/pointOnSurface/interpolatePointOnSurfaceBilinear.ts b/src/interpolate/pointOnSurface/interpolatePointOnSurfaceBilinear.ts index d0eb4d2..ea0c2a7 100644 --- a/src/interpolate/pointOnSurface/interpolatePointOnSurfaceBilinear.ts +++ b/src/interpolate/pointOnSurface/interpolatePointOnSurfaceBilinear.ts @@ -2,10 +2,12 @@ import type { BoundingCurves, GetCoordinateOnSurfaceConfig, InterpolatePointOnCurve, + InterpolationParameters, InterpolationParametersRequired, Point, } from '../../types' import { Coordinate } from '../../types' +import { isNil } from '../../utils/is' // ----------------------------------------------------------------------------- // Utils @@ -43,25 +45,28 @@ const clampT = (t: number): number => Math.min(Math.max(t, 0), 1) * rounding errors. * * @param {BoundingCurves} boundingCurves - The bounding curves of the surface containing top, bottom, left and right curves. - * @param {InterpolationParametersRequired} params - The interpolation parameters. + * @param {InterpolationParameters} params - The interpolation parameters. * @param {InterpolatePointOnCurve} interpolatePointOnCurveU - The function to interpolate a point on the u-axis curves. * @param {InterpolatePointOnCurve} interpolatePointOnCurveV - The function to interpolate a point on the v-axis curves. * @returns {Point} The interpolated 3D point on the surface {x, y, z}. */ const interpolatePointOnSurfaceBilinear = ( { top, bottom, left, right }: BoundingCurves, - params: InterpolationParametersRequired, + params: InterpolationParameters, interpolatePointOnCurveU: InterpolatePointOnCurve, interpolatePointOnCurveV: InterpolatePointOnCurve ): Point => { + const uOpposite = isNil(params.uOpposite) ? params.u : params.uOpposite + const vOpposite = isNil(params.vOpposite) ? params.v : params.vOpposite + // Due to potential minute rounding errors we clamp these values to avoid // issues with the interpolators which expect a range of 0–1. const paramsClamped = { u: clampT(params.u), - uOpposite: clampT(params.uOpposite), + uOpposite: clampT(uOpposite), v: clampT(params.v), - vOpposite: clampT(params.vOpposite), - } + vOpposite: clampT(vOpposite), + } as InterpolationParametersRequired const boundaryPoints = { top: interpolatePointOnCurveU(paramsClamped.u, top),