Skip to content

Commit e128535

Browse files
committed
feat(vector): vector and point using cahedFactory
1 parent ec4515c commit e128535

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/point.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
cachedGetter,
55
cachedValueOf,
66
operatorCalc,
7-
defineVectorLength
7+
defineVectorLength,
8+
cachedFactory
89
} from './operator';
910
import formatNumber from './formatter';
1011

@@ -328,6 +329,8 @@ export function calc(alg) {
328329
return operatorCalc(alg);
329330
}
330331

332+
const pointFactory = cachedFactory(Point);
333+
331334
/**
332335
* @typedef {(alg: Alg) => PointType} PointAlg
333336
* @typedef {(x: number , y: number) => PointType} PointCon
@@ -336,9 +339,11 @@ export function calc(alg) {
336339
* @type {point}
337340
*/
338341
export const point = function point(x, y) {
339-
return new Point(x, y);
342+
return pointFactory(x, y);
340343
};
341344

345+
const ipointFactory = cachedFactory(IPoint);
346+
342347
/**
343348
* @typedef {(alg: Alg) => IPointType} IPointAlg
344349
* @typedef {(x: number , y: number) => IPointType} IPointCon
@@ -347,5 +352,5 @@ export const point = function point(x, y) {
347352
* @type {ipoint}
348353
*/
349354
export const ipoint = function ipoint(x, y) {
350-
return new IPoint(x, y);
355+
return ipointFactory(x, y);
351356
};

src/vector.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
cachedGetter,
55
cachedValueOf,
66
operatorCalc,
7-
defineVectorLength
7+
defineVectorLength,
8+
cachedFactory
89
} from './operator';
910
import formatNumber from './formatter';
1011

@@ -401,6 +402,8 @@ export function calc(alg) {
401402
return operatorCalc(alg);
402403
}
403404

405+
const vectorFactory = cachedFactory(Vector);
406+
404407
/**
405408
* @typedef {(alg: Alg) => VectorType} VectorAlg
406409
* @typedef {(x: number , y: number, z: number) => VectorType} VectorCon
@@ -409,9 +412,11 @@ export function calc(alg) {
409412
* @type { vector }
410413
*/
411414
export const vector = function vector(x, y, z) {
412-
return new Vector(x, y, z);
415+
return vectorFactory(x, y, z);
413416
};
414417

418+
const victorFactory = cachedFactory(Victor);
419+
415420
/**
416421
* @typedef {(alg: Alg) => VictorType} VictorAlg
417422
* @typedef {(x: number , y: number, z: number) => VictorType} VictorCon
@@ -420,5 +425,5 @@ export const vector = function vector(x, y, z) {
420425
* @type { victor }
421426
*/
422427
export const victor = function victor(x, y, z) {
423-
return new Victor(x, y, z);
428+
return victorFactory(x, y, z);
424429
};

0 commit comments

Comments
 (0)