From 7299fdca9a12636817cd383e5bc00840b382cda0 Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Wed, 26 Aug 2015 17:37:16 +0200 Subject: [PATCH] adds interpolation for ambiguous cases --- examples/contour.html | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/examples/contour.html b/examples/contour.html index 6a1c8b9..ea9c0cc 100644 --- a/examples/contour.html +++ b/examples/contour.html @@ -177,13 +177,41 @@ else if (type === 5 || type === 10) { var diff = [previousPos.x - currentPos.x, previousPos.y - currentPos.y]; if (diff[0] === -1){ - return {x: currentPos.x, y: currentPos.y - 1}; + return { + x: currentPos.x, + y: currentPos.y - 1, + interpolation: { + x: lerp(cornerValues[1], cornerValues[0], contourValue), + y: lerp(cornerValues[3], cornerValues[0], contourValue) + } + }; } else if (diff[0] === 1){ - return {x: currentPos.x, y: currentPos.y + 1}; + return { + x: currentPos.x, + y: currentPos.y + 1, + interpolation: { + x: lerp(cornerValues[3], cornerValues[2], contourValue), + y: lerp(cornerValues[1], cornerValues[2], contourValue) + } + }; } else if (diff[1] === -1){ - return {x: currentPos.x + 1, y: currentPos.y}; + return { + x: currentPos.x + 1, + y: currentPos.y, + interpolation: { + x: lerp(cornerValues[1], cornerValues[0], contourValue), + y: lerp(cornerValues[3], cornerValues[0], contourValue) + } + }; } else if (diff[1] === 1){ - return {x: currentPos.x - 1, y: currentPos.y}; + return { + x: currentPos.x - 1, + y: currentPos.y, + interpolation: { + x: lerp(cornerValues[3], cornerValues[2], contourValue), + y: lerp(cornerValues[1], cornerValues[2], contourValue) + } + }; } }