Skip to content

Commit

Permalink
fix(operator): correct handling for 4th channel
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTelanie committed Jul 9, 2020
1 parent ee2622e commit 13685c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const X = 0;
const Y = 1;
const Z = 2;
const W = 3;
const DEFAULT = undefined;
const VECTOR_LENGTH = Symbol('vector length');
const GET_SOURCE = Symbol('get source');
Expand Down Expand Up @@ -37,7 +38,7 @@ function getVectorLength(vec) {
if (getSource) {
return getSource(vec).length;
}
return vec[VECTOR_LENGTH] !== 2 ? 3 : 2;
return vec[VECTOR_LENGTH] || 3;
}

function getVectorValue(vec, index) {
Expand All @@ -57,6 +58,9 @@ function getVectorValue(vec, index) {
if (index === Z) {
return vec.z;
}
if (index === W) {
return vec.w;
}
// really?
return undefined;
}
Expand All @@ -78,6 +82,9 @@ function setVectorValue(vec, index, value) {
if (index === Z) {
vec.z = value;
}
if (index === W) {
vec.w = value;
}
}

function maxVector(v1, v2) {
Expand Down Expand Up @@ -185,6 +192,10 @@ function bindCache(org) {
resultCacheIndex += 1;
return resultCache[resultCacheIndex];
}
if (inProgress === W) {
resultCacheIndex += 1;
return resultCache[resultCacheIndex];
}
return org.apply(this, args);
};
}
Expand Down
4 changes: 2 additions & 2 deletions test/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ const colorTest = (color, Color) => {

it('should be calculated by assigned statement', () => {
const pos = color(5, 6, 7, 8);
const dir = color(1, 0, 1, 0);
const dir = color(1, 0, 1, 1);
const scale = color(() => dir * pos);

assert.equal(scale.x, 5);
assert.equal(scale.y, 0);
assert.equal(scale.z, 7);
assert.equal(scale.w, 0);
assert.equal(scale.w, 8);
});

it('should be calculated by assigned statement with only numbers', () => {
Expand Down

0 comments on commit 13685c9

Please sign in to comment.