Skip to content

Commit

Permalink
feat(vector): primitives with toCSSVars method
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTelanie committed Apr 7, 2020
1 parent 7b87f8a commit 9e9ec6c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/degree.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ class ADegree {
* @returns {string}
*/
toString() {
return `${this[ANGLE] * RAD_TO_DEG}deg`;
return `{ "angle": ${this[ANGLE]} }`;
}

toCSSVars(name, target) {
let prefix = '';
if (name) {
prefix = `-${name}`;
}
target = target || {};
target[`-${prefix}-angle`] = `${this[ANGLE] * RAD_TO_DEG}deg`;
return target;
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ class APoint {
return `{ "x": ${this.x}, "y": ${this.y} }`;
}

toCSSVars(name, target) {
let prefix = '';
if (name) {
prefix = `-${name}`;
}
target = target || {};
target[`-${prefix}-x`] = this.x;
target[`-${prefix}-y`] = this.y;
return target;
}

/**
*
* @returns {number}
Expand Down
16 changes: 14 additions & 2 deletions src/quaternion.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
FORWARD, LEFT, RIGHT, UP, Vector, Victor
} from './vector';
import { isArray, multQuatVec } from './util';
import { formatNumber } from './formatter';
import { cachedFunction } from './operator';
import { degree, isAngle } from './degree';

Expand Down Expand Up @@ -264,7 +263,20 @@ class AQuaternion {
* @returns {string}
*/
toString() {
return `{ x: ${formatNumber(this.x)}, y: ${formatNumber(this.y)}, z: ${formatNumber(this.z)}, w: ${formatNumber(this.w)} }`;
return `{ "x": ${this.x}, "y": ${this.y}, "z": ${this.z}, "w": ${this.w} }`;
}

toCSSVars(name, target) {
let prefix = '';
if (name) {
prefix = `-${name}`;
}
target = target || {};
target[`-${prefix}-x`] = this.x;
target[`-${prefix}-y`] = this.y;
target[`-${prefix}-z`] = this.z;
target[`-${prefix}-w`] = this.w;
return target;
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ class AVector {
return `{ "x": ${this.x}, "y": ${this.y}, "z": ${this.z} }`;
}

toCSSVars(name, target) {
let prefix = '';
if (name) {
prefix = `-${name}`;
}
target = target || {};
target[`-${prefix}-x`] = this.x;
target[`-${prefix}-y`] = this.y;
target[`-${prefix}-z`] = this.z;
return target;
}

/**
*
* @returns {number}
Expand Down

0 comments on commit 9e9ec6c

Please sign in to comment.