Skip to content

Commit

Permalink
Remove scale function from lineInterpolate
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryStevens committed Jun 6, 2023
1 parent a8e314d commit bf8c0cb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 45 deletions.
26 changes: 8 additions & 18 deletions build/geometric.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,17 @@
x2 = _line$2[0],
y2 = _line$2[1];

var x = scale([0, 1], [x1, x2]);
var y = scale([0, 1], [y1, y2]);
return function (t) {
var t0 = clamp ? t < 0 ? 0 : t > 1 ? 1 : t : t;
return [x(t0), y(t0)];
var x = function x(v) {
return (x2 - x1) * v + x1;
};
} // A linear scale

function scale(_ref, _ref2) {
var _ref3 = _slicedToArray(_ref, 2),
d0 = _ref3[0],
d1 = _ref3[1];

var _ref4 = _slicedToArray(_ref2, 2),
r0 = _ref4[0],
r1 = _ref4[1];
var y = function y(v) {
return (y2 - y1) * v + y1;
};

var dx = d1 - d0;
var rx = r1 - r0;
return function (v) {
return rx * ((v - d0) / dx) + r0;
return function (t) {
var t0 = clamp ? t < 0 ? 0 : t > 1 ? 1 : t : t;
return [x(t0), y(t0)];
};
}

Expand Down
1 change: 0 additions & 1 deletion build/geometric.min.js

This file was deleted.

Binary file removed build/geometric.zip
Binary file not shown.
42 changes: 26 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 3 additions & 10 deletions src/lines/lineInterpolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@
// even if t is greater than 1 or less then 0.
export function lineInterpolate(line, clamp = false){
const [[x1, y1], [x2, y2]] = line;
const x = scale([0, 1], [x1, x2]);
const y = scale([0, 1], [y1, y2]);
const x = v => (x2 - x1) * v + x1;
const y = v => (y2 - y1) * v + y1;
return t => {
const t0 = clamp ? t < 0 ? 0 : t > 1 ? 1 : t : t;
return [x(t0), y(t0)];
return [ x(t0), y(t0) ];
}
}

// A linear scale
function scale([d0, d1], [r0, r1]){
const dx = d1 - d0;
const rx = r1 - r0;
return v => rx * ((v - d0) / dx) + r0;
}

0 comments on commit bf8c0cb

Please sign in to comment.