Skip to content

Commit

Permalink
feat(vector): continue prepare code for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTelanie committed Aug 16, 2019
1 parent 6366a76 commit 06ad72c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 29 deletions.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ export {

/**
* @param {() => number} alg
* @return {(Vector | Victor | IVector | Point | IPoint) & number}
* @return {(Vector | Victor | IVector | Point | IPoint) & number | number}
*/
export function calc(alg) {
return operatorCalc(alg);
}

export default Vector;

export const Export = {
Vector, Victor, IVector, Point, IPoint
};
64 changes: 49 additions & 15 deletions src/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import formatNumber from './formatter';

/* eslint class-methods-use-this: 0 */
/* eslint-disable no-unused-vars */
/* eslint-disable no-dupe-keys */

const X = 0;
const Y = 1;
Expand Down Expand Up @@ -56,6 +57,7 @@ class APoint {
/**
* @param {number | (Alg)} x
* @param {number} [y]
* @hidden
*/
constructor(x, y) {
if (typeof x === 'function') {
Expand Down Expand Up @@ -147,14 +149,14 @@ class APoint {
/**
* @param {(point: APointType) => number} alg
* @returns {this}
* @throws NotImplementedError
* @throws NotImplementedError
*/
calc(alg) {
throw new Error('calc() not implemented');
}

/**
* @throws NotImplementedError
* @throws NotImplementedError
* @returns {APoint}
*/
clone() {
Expand Down Expand Up @@ -272,8 +274,14 @@ cachedGetter(APoint, 'lengthSq');
/**
* Point
*
* **constructor**
* ___
* new Point(x: *number*, y: *number*): [[Point]]
*
*
*
* **constructor**
* ___
* new Point(alg: (*function*(): *number*)): [[Point]]
*
*/
Expand Down Expand Up @@ -329,6 +337,8 @@ export class Point extends APoint {
/**
* IPoint
*
* **constructors**
* ___
* new IPoint(x: *number*, y: *number*): [[IPoint]]
*
* new IPoint(alg: (*function*(): *number*)): [[IPoint]]
Expand All @@ -346,6 +356,7 @@ export class IPoint extends APoint {
/**
* @param {Alg} alg
* @return {PointType | IPointType}
* @hidden
*/
export function calc(alg) {
return operatorCalc(alg);
Expand All @@ -354,29 +365,52 @@ export function calc(alg) {
const pointFactory = cachedFactory(Point);

/**
* *function* point(x: *number*, y: *number*): [[Point]] & *number*
*
* *function* point(alg: (*function*(): *number*)): [[Point]] & *number*
*
* @typedef {(alg: Alg) => PointType} PointAlg
* @typedef {(x: number , y: number) => PointType} PointCon
* @typedef {PointAlg & PointCon}
* @typedef {PointAlg & PointCon} point
* @type {point}
* @hidden
*/
export const point = function point(x, y) {
export function point(x, y) {
return pointFactory(x, y);
};
}

const ipointFactory = cachedFactory(IPoint);

/**
* *function* ipoint(x: *number*, y: *number*): [[IPoint]] & *number*
*
* *function* ipoint(alg: (*function*(): *number*)): [[IPoint]] & *number*
*
* @typedef {(alg: Alg) => IPointType} IPointAlg
* @typedef {(x: number , y: number) => IPointType} IPointCon
* @typedef {IPointAlg & IPointCon}
*/
export const ipoint = function ipoint(x, y) {
* @hidden
*/
export function ipoint(x, y) {
return ipointFactory(x, y);
}

export const Export = {
/**
* @param {Alg} alg
* @return {PointType | IPointType}
*/
calc: alg => operatorCalc(alg),

/**
* @type {PointAlg}
*/
point: alg => pointFactory(alg),

/**
* @type {PointCon}
*/
point: (x, y) => pointFactory(x, y),

/**
* @type {IPointAlg}
*/
ipoint: alg => ipointFactory(alg),

/**
* @type {IPointCon}
*/
ipoint: (x, y) => ipointFactory(x, y)
};
51 changes: 38 additions & 13 deletions src/vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ipoint } from './point';

/* eslint class-methods-use-this: 0 */
/* eslint-disable no-unused-vars */
/* eslint-disable no-dupe-keys */

const X = 0;
const Y = 1;
Expand Down Expand Up @@ -45,6 +46,7 @@ class AVector {
}
}


/**
* @returns {number}
*/
Expand Down Expand Up @@ -191,15 +193,15 @@ class AVector {
/**
* @param {(vector: AVectorType) => number} arg
* @returns {this}
* @throws NotImplementedError
* @throws NotImplementedError
*/
calc(arg) {
throw new Error('calc() not implemented');
}

/**
*
* @throws NotImplementedError
* @throws NotImplementedError
* @return {AVectorType}
*/
clone() {
Expand Down Expand Up @@ -462,6 +464,7 @@ export class Victor extends AVector {
/**
* @param {Alg} alg
* @return {VectorType | VictorType}
* @hidden
*/
export function calc(alg) {
return operatorCalc(alg);
Expand All @@ -470,29 +473,51 @@ export function calc(alg) {
const vectorFactory = cachedFactory(Vector);

/**
* *function* vector(x: *number*, y: *number*, z: *number*): [[Vector]] & *number*
*
* *function* vector(alg: (*function*(): *number*)): [[Vector]] & *number*
*
* @typedef {(alg: Alg) => VectorType} VectorAlg
* @typedef {(x: number , y: number, z: number) => VectorType} VectorCon
* @typedef {VectorAlg & VectorCon}
* @hidden
*/
export const vector = function vector(x, y, z) {
export function vector(x, y, z) {
return vectorFactory(x, y, z);
};
}

const victorFactory = cachedFactory(Victor);

/**
* *function* victor(x: *number*, y: *number*, z: *number*): [[Victor]] & *number*
*
* *function* victor(alg: (*function*(): *number*)): [[Victor]] & *number*
*
* @typedef {(alg: Alg) => VictorType} VictorAlg
* @typedef {(x: number , y: number, z: number) => VictorType} VictorCon
* @typedef {VictorAlg & VictorCon}
* @hidden
*/
export const victor = function victor(x, y, z) {
export function victor(x, y, z) {
return victorFactory(x, y, z);
}

export const Export = {
/**
* @param {Alg} alg
* @return {VectorType | VictorType}
*/
calc: alg => operatorCalc(alg),

/**
* @type {VectorAlg}
*/
vector: alg => vectorFactory(alg),

/**
* @type {VectorCon}
*/
vector: (x, y) => vectorFactory(x, y),

/**
* @type {VictorAlg}
*/
victor: alg => victorFactory(alg),

/**
* @type {VictorCon}
*/
victor: (x, y) => victorFactory(x, y)
};

0 comments on commit 06ad72c

Please sign in to comment.