Skip to content

Commit

Permalink
feat(vector): vector and point using cahedFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTelanie committed May 15, 2019
1 parent ec4515c commit e128535
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
cachedGetter,
cachedValueOf,
operatorCalc,
defineVectorLength
defineVectorLength,
cachedFactory
} from './operator';
import formatNumber from './formatter';

Expand Down Expand Up @@ -328,6 +329,8 @@ export function calc(alg) {
return operatorCalc(alg);
}

const pointFactory = cachedFactory(Point);

/**
* @typedef {(alg: Alg) => PointType} PointAlg
* @typedef {(x: number , y: number) => PointType} PointCon
Expand All @@ -336,9 +339,11 @@ export function calc(alg) {
* @type {point}
*/
export const point = function point(x, y) {
return new Point(x, y);
return pointFactory(x, y);
};

const ipointFactory = cachedFactory(IPoint);

/**
* @typedef {(alg: Alg) => IPointType} IPointAlg
* @typedef {(x: number , y: number) => IPointType} IPointCon
Expand All @@ -347,5 +352,5 @@ export const point = function point(x, y) {
* @type {ipoint}
*/
export const ipoint = function ipoint(x, y) {
return new IPoint(x, y);
return ipointFactory(x, y);
};
11 changes: 8 additions & 3 deletions src/vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
cachedGetter,
cachedValueOf,
operatorCalc,
defineVectorLength
defineVectorLength,
cachedFactory
} from './operator';
import formatNumber from './formatter';

Expand Down Expand Up @@ -401,6 +402,8 @@ export function calc(alg) {
return operatorCalc(alg);
}

const vectorFactory = cachedFactory(Vector);

/**
* @typedef {(alg: Alg) => VectorType} VectorAlg
* @typedef {(x: number , y: number, z: number) => VectorType} VectorCon
Expand All @@ -409,9 +412,11 @@ export function calc(alg) {
* @type { vector }
*/
export const vector = function vector(x, y, z) {
return new Vector(x, y, z);
return vectorFactory(x, y, z);
};

const victorFactory = cachedFactory(Victor);

/**
* @typedef {(alg: Alg) => VictorType} VictorAlg
* @typedef {(x: number , y: number, z: number) => VictorType} VictorCon
Expand All @@ -420,5 +425,5 @@ export const vector = function vector(x, y, z) {
* @type { victor }
*/
export const victor = function victor(x, y, z) {
return new Victor(x, y, z);
return victorFactory(x, y, z);
};

0 comments on commit e128535

Please sign in to comment.