geometric-library 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/cjs/abstracts/Angle.js +60 -0
- package/dist/cjs/abstracts/Figure.js +147 -0
- package/dist/cjs/abstracts/Flag.js +27 -0
- package/dist/cjs/abstracts/Magnitude.js +25 -0
- package/dist/cjs/abstracts/Point.js +50 -0
- package/dist/cjs/abstracts/Vector.js +74 -0
- package/dist/cjs/figures/ArcCurve.js +132 -0
- package/dist/cjs/figures/Circle.js +43 -0
- package/dist/cjs/figures/CubicBezierCurve.js +149 -0
- package/dist/cjs/figures/Ellipse.js +111 -0
- package/dist/cjs/figures/Line.js +264 -0
- package/dist/cjs/figures/Polygon.js +17 -0
- package/dist/cjs/figures/QuadraticBezierCurve.js +104 -0
- package/dist/cjs/index.js +48 -0
- package/dist/cjs/types/index.js +2 -0
- package/dist/cjs/utilities/Calculator.js +153 -0
- package/dist/cjs/utilities/index.js +10 -0
- package/dist/esm/abstracts/Angle.js +56 -0
- package/dist/esm/abstracts/Figure.js +143 -0
- package/dist/esm/abstracts/Flag.js +23 -0
- package/dist/esm/abstracts/Magnitude.js +21 -0
- package/dist/esm/abstracts/Point.js +46 -0
- package/dist/esm/abstracts/Vector.js +70 -0
- package/dist/esm/figures/ArcCurve.js +128 -0
- package/dist/esm/figures/Circle.js +39 -0
- package/dist/esm/figures/CubicBezierCurve.js +145 -0
- package/dist/esm/figures/Ellipse.js +107 -0
- package/dist/esm/figures/Line.js +260 -0
- package/dist/esm/figures/Polygon.js +13 -0
- package/dist/esm/figures/QuadraticBezierCurve.js +100 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/utilities/Calculator.js +149 -0
- package/dist/esm/utilities/index.js +7 -0
- package/dist/types/abstracts/Angle.d.ts +18 -0
- package/dist/types/abstracts/Figure.d.ts +22 -0
- package/dist/types/abstracts/Flag.d.ts +10 -0
- package/dist/types/abstracts/Magnitude.d.ts +9 -0
- package/dist/types/abstracts/Point.d.ts +14 -0
- package/dist/types/abstracts/Vector.d.ts +20 -0
- package/dist/types/figures/ArcCurve.d.ts +23 -0
- package/dist/types/figures/Circle.d.ts +12 -0
- package/dist/types/figures/CubicBezierCurve.d.ts +23 -0
- package/dist/types/figures/Ellipse.d.ts +26 -0
- package/dist/types/figures/Line.d.ts +44 -0
- package/dist/types/figures/Polygon.d.ts +7 -0
- package/dist/types/figures/QuadraticBezierCurve.d.ts +21 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/types/index.d.ts +144 -0
- package/dist/types/utilities/Calculator.d.ts +49 -0
- package/dist/types/utilities/index.d.ts +6 -0
- package/package.json +60 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
export class Calculator {
|
|
3
|
+
_instance;
|
|
4
|
+
constructor(arg) {
|
|
5
|
+
this._instance = new Decimal(arg);
|
|
6
|
+
}
|
|
7
|
+
// STATIC METHODS
|
|
8
|
+
static abs(arg) {
|
|
9
|
+
return Calculator.computeUnaryOperation('abs', arg);
|
|
10
|
+
}
|
|
11
|
+
static acos(arg) {
|
|
12
|
+
return Calculator.computeUnaryOperation('acos', arg);
|
|
13
|
+
}
|
|
14
|
+
static add(first, second) {
|
|
15
|
+
return Calculator.computeBinaryOperation('add', [first, second]);
|
|
16
|
+
}
|
|
17
|
+
static atan(arg) {
|
|
18
|
+
return Calculator.computeUnaryOperation('atan', arg);
|
|
19
|
+
}
|
|
20
|
+
static atan2(first, second) {
|
|
21
|
+
return Calculator.computeBinaryOperation('atan2', [first, second]);
|
|
22
|
+
}
|
|
23
|
+
static cos(arg) {
|
|
24
|
+
return Calculator.computeUnaryOperation('cos', arg);
|
|
25
|
+
}
|
|
26
|
+
static div(first, second) {
|
|
27
|
+
return Calculator.computeBinaryOperation('div', [first, second]);
|
|
28
|
+
}
|
|
29
|
+
static max(args) {
|
|
30
|
+
return Calculator.computeIndefiniteOperation('max', args);
|
|
31
|
+
}
|
|
32
|
+
static min(args) {
|
|
33
|
+
return Calculator.computeIndefiniteOperation('min', args);
|
|
34
|
+
}
|
|
35
|
+
static mod(first, second) {
|
|
36
|
+
return Calculator.computeBinaryOperation('mod', [first, second]);
|
|
37
|
+
}
|
|
38
|
+
static mul(first, second) {
|
|
39
|
+
return Calculator.computeBinaryOperation('mul', [first, second]);
|
|
40
|
+
}
|
|
41
|
+
static neg(arg) {
|
|
42
|
+
return Calculator.computeUnaryOperation('neg', arg);
|
|
43
|
+
}
|
|
44
|
+
static pow(first, second) {
|
|
45
|
+
return Calculator.computeBinaryOperation('pow', [first, second]);
|
|
46
|
+
}
|
|
47
|
+
static sin(arg) {
|
|
48
|
+
return Calculator.computeUnaryOperation('sin', arg);
|
|
49
|
+
}
|
|
50
|
+
static sqrt(arg) {
|
|
51
|
+
return Calculator.computeUnaryOperation('sqrt', arg);
|
|
52
|
+
}
|
|
53
|
+
static sub(first, second) {
|
|
54
|
+
return Calculator.computeBinaryOperation('sub', [first, second]);
|
|
55
|
+
}
|
|
56
|
+
static tan(arg) {
|
|
57
|
+
return Calculator.computeUnaryOperation('tan', arg);
|
|
58
|
+
}
|
|
59
|
+
// PRIVATE METHODS
|
|
60
|
+
static computeBinaryOperation(operation, args) {
|
|
61
|
+
const [a, b] = Calculator.toDecimalArgs(args);
|
|
62
|
+
const result = Decimal[operation](a, b);
|
|
63
|
+
const roundedResult = this.roundDecimalWithPrecision(result);
|
|
64
|
+
return new Calculator(roundedResult);
|
|
65
|
+
}
|
|
66
|
+
static computeIndefiniteOperation(operation, args) {
|
|
67
|
+
const nargs = Calculator.toDecimalArgs(args);
|
|
68
|
+
const result = Decimal[operation](...nargs);
|
|
69
|
+
const roundedResult = this.roundDecimalWithPrecision(result);
|
|
70
|
+
return new Calculator(roundedResult);
|
|
71
|
+
}
|
|
72
|
+
static computeUnaryOperation(operation, arg) {
|
|
73
|
+
const [a] = Calculator.toDecimalArgs([arg]);
|
|
74
|
+
const result = new Decimal(a)[operation]();
|
|
75
|
+
const roundedResult = this.roundDecimalWithPrecision(result);
|
|
76
|
+
return new Calculator(roundedResult);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @todo The precision calculation could be improved to test at what decimal point is the distance less
|
|
80
|
+
* than epsilon, and then to round up to that point instead of choosing an arbitrary precision.
|
|
81
|
+
*/
|
|
82
|
+
static roundDecimalWithPrecision(value) {
|
|
83
|
+
const epsilon = new Decimal('1e-8');
|
|
84
|
+
const distanceToLowerInt = value.sub(value.floor());
|
|
85
|
+
const distanceToUpperInt = value.ceil().sub(value);
|
|
86
|
+
if (distanceToLowerInt.lte(epsilon)) {
|
|
87
|
+
return value.floor().toNumber();
|
|
88
|
+
}
|
|
89
|
+
if (distanceToUpperInt.lte(epsilon)) {
|
|
90
|
+
return value.ceil().toNumber();
|
|
91
|
+
}
|
|
92
|
+
return value.toNumber();
|
|
93
|
+
}
|
|
94
|
+
static toDecimalArgs(args) {
|
|
95
|
+
return args.map((arg) => +arg);
|
|
96
|
+
}
|
|
97
|
+
// INSTANCE METHODS
|
|
98
|
+
abs() {
|
|
99
|
+
return Calculator.computeUnaryOperation('abs', this);
|
|
100
|
+
}
|
|
101
|
+
acos() {
|
|
102
|
+
return Calculator.computeUnaryOperation('acos', this);
|
|
103
|
+
}
|
|
104
|
+
add(second) {
|
|
105
|
+
return Calculator.computeBinaryOperation('add', [this, second]);
|
|
106
|
+
}
|
|
107
|
+
atan() {
|
|
108
|
+
return Calculator.computeUnaryOperation('atan', this);
|
|
109
|
+
}
|
|
110
|
+
atan2(second) {
|
|
111
|
+
return Calculator.computeBinaryOperation('atan2', [this, second]);
|
|
112
|
+
}
|
|
113
|
+
cos() {
|
|
114
|
+
return Calculator.computeUnaryOperation('cos', this);
|
|
115
|
+
}
|
|
116
|
+
div(second) {
|
|
117
|
+
return Calculator.computeBinaryOperation('div', [this, second]);
|
|
118
|
+
}
|
|
119
|
+
isFinite() {
|
|
120
|
+
return this._instance.isFinite();
|
|
121
|
+
}
|
|
122
|
+
mod(second) {
|
|
123
|
+
return Calculator.computeBinaryOperation('mod', [this, second]);
|
|
124
|
+
}
|
|
125
|
+
mul(second) {
|
|
126
|
+
return Calculator.computeBinaryOperation('mul', [this, second]);
|
|
127
|
+
}
|
|
128
|
+
neg() {
|
|
129
|
+
return Calculator.computeUnaryOperation('neg', this);
|
|
130
|
+
}
|
|
131
|
+
pow(second) {
|
|
132
|
+
return Calculator.computeBinaryOperation('pow', [this, second]);
|
|
133
|
+
}
|
|
134
|
+
sin() {
|
|
135
|
+
return Calculator.computeUnaryOperation('sin', this);
|
|
136
|
+
}
|
|
137
|
+
sqrt() {
|
|
138
|
+
return Calculator.computeUnaryOperation('sqrt', this);
|
|
139
|
+
}
|
|
140
|
+
sub(second) {
|
|
141
|
+
return Calculator.computeBinaryOperation('sub', [this, second]);
|
|
142
|
+
}
|
|
143
|
+
tan() {
|
|
144
|
+
return Calculator.computeUnaryOperation('tan', this);
|
|
145
|
+
}
|
|
146
|
+
valueOf() {
|
|
147
|
+
return this._instance.toNumber();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Calculator } from './Calculator';
|
|
2
|
+
import { Point } from '../abstracts/Point';
|
|
3
|
+
import { Line } from '../figures/Line';
|
|
4
|
+
export const coordinateOrigin = new Point([0, 0]);
|
|
5
|
+
export const xAxis = new Line([coordinateOrigin, new Point([1, 0])]);
|
|
6
|
+
export const yAxis = new Line([coordinateOrigin, new Point([0, 1])]);
|
|
7
|
+
export const PI2 = +Calculator.mul(Math.PI, 2); // 360 degrees
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IAngle, TAngleUnit } from '../types';
|
|
2
|
+
export declare class Angle implements IAngle {
|
|
3
|
+
private _radians;
|
|
4
|
+
constructor(value: number, unit: TAngleUnit);
|
|
5
|
+
get cos(): number;
|
|
6
|
+
get cot(): number;
|
|
7
|
+
get degrees(): number;
|
|
8
|
+
get radians(): number;
|
|
9
|
+
get sin(): number;
|
|
10
|
+
get tan(): number;
|
|
11
|
+
static toDegrees(radians: number): number;
|
|
12
|
+
static toRadians(degrees: number): number;
|
|
13
|
+
clone(): IAngle;
|
|
14
|
+
normalize(): this;
|
|
15
|
+
replace(value: number, unit: TAngleUnit): this;
|
|
16
|
+
scale(factor: number): this;
|
|
17
|
+
valueOf(): number;
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IAngle, IBoundingBox, IFigure, ILine, IMagnitude, IPoint, IVector, TFigureValues } from '../types';
|
|
2
|
+
export declare abstract class Figure implements IFigure {
|
|
3
|
+
protected angles: IAngle[];
|
|
4
|
+
protected isRelative: boolean;
|
|
5
|
+
protected magnitudes: IMagnitude[];
|
|
6
|
+
protected points: IPoint[];
|
|
7
|
+
protected vectors: IVector[];
|
|
8
|
+
private _values;
|
|
9
|
+
constructor(values: TFigureValues);
|
|
10
|
+
get boundingBox(): IBoundingBox;
|
|
11
|
+
get values(): TFigureValues;
|
|
12
|
+
/**
|
|
13
|
+
* @todo Figure out a better way to type narrow than iterating again.
|
|
14
|
+
*/
|
|
15
|
+
protected set values(values: TFigureValues);
|
|
16
|
+
protected static computeBoundingBox(points: IPoint[]): IBoundingBox;
|
|
17
|
+
private static getNoPointsErrorMessage;
|
|
18
|
+
reflect(about: IPoint | ILine): this;
|
|
19
|
+
rotate(phi: IAngle, about?: IPoint): this;
|
|
20
|
+
scale(factor: number, about?: IPoint): this;
|
|
21
|
+
translate(vector: IVector): this;
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IAngle, IPoint, IVector, TPointValues } from '../types';
|
|
2
|
+
export declare class Point implements IPoint {
|
|
3
|
+
private _x;
|
|
4
|
+
private _y;
|
|
5
|
+
constructor([x, y]: TPointValues);
|
|
6
|
+
get values(): TPointValues;
|
|
7
|
+
get x(): number;
|
|
8
|
+
get y(): number;
|
|
9
|
+
clone(): Point;
|
|
10
|
+
reflect(about: IPoint): this;
|
|
11
|
+
replace(point: Point): this;
|
|
12
|
+
rotate(phi: IAngle, about?: IPoint): this;
|
|
13
|
+
translate(vector: IVector): this;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IVector, TVectorValues, TSegment, IAngle } from '../types';
|
|
2
|
+
export declare class Vector implements IVector {
|
|
3
|
+
private _dx;
|
|
4
|
+
private _dy;
|
|
5
|
+
constructor(values: TVectorValues | TSegment);
|
|
6
|
+
get dx(): number;
|
|
7
|
+
get dy(): number;
|
|
8
|
+
get magnitude(): number;
|
|
9
|
+
get values(): TVectorValues;
|
|
10
|
+
angleTo(vector: Vector): IAngle;
|
|
11
|
+
clone(): Vector;
|
|
12
|
+
dotProduct(vector: Vector): number;
|
|
13
|
+
reflect({ x, y }: {
|
|
14
|
+
x: boolean;
|
|
15
|
+
y: boolean;
|
|
16
|
+
}): this;
|
|
17
|
+
replace(vector: Vector): this;
|
|
18
|
+
rotate(phi: IAngle): this;
|
|
19
|
+
scale(factor: number): this;
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IArcCurve, IBoundingBox, ILine, IPoint, TArcValues } from '../types';
|
|
2
|
+
import { Figure } from '../abstracts/Figure';
|
|
3
|
+
export declare class ArcCurve extends Figure implements IArcCurve {
|
|
4
|
+
private ellipse;
|
|
5
|
+
private largeArcFlag;
|
|
6
|
+
private phi;
|
|
7
|
+
private rx;
|
|
8
|
+
private ry;
|
|
9
|
+
private sweepFlag;
|
|
10
|
+
constructor(values: TArcValues);
|
|
11
|
+
get boundingBox(): IBoundingBox;
|
|
12
|
+
get center(): IPoint;
|
|
13
|
+
get criticalPoints(): IPoint[];
|
|
14
|
+
private get P0();
|
|
15
|
+
private get P1();
|
|
16
|
+
clone(): ArcCurve;
|
|
17
|
+
reflect(about: IPoint | ILine): this;
|
|
18
|
+
private adjustRadii;
|
|
19
|
+
private computeCenter;
|
|
20
|
+
private computeCenterPrime;
|
|
21
|
+
private computeP0Prime;
|
|
22
|
+
private computeThetaRange;
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ICircle, IEllipse, IMagnitude, TCircleValues, TEllipseCriticalPoints, TFigureValues } from '../types';
|
|
2
|
+
import { Ellipse } from './Ellipse';
|
|
3
|
+
export declare class Circle extends Ellipse implements ICircle {
|
|
4
|
+
private _radius;
|
|
5
|
+
constructor(values: TCircleValues);
|
|
6
|
+
get isCircle(): boolean;
|
|
7
|
+
get radius(): IMagnitude;
|
|
8
|
+
get values(): TFigureValues;
|
|
9
|
+
set values(values: TFigureValues);
|
|
10
|
+
clone(): Circle;
|
|
11
|
+
protected computeCriticalPoints(ellipse?: IEllipse): TEllipseCriticalPoints;
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IAngle, IBoundingBox, ICubicBezierCurve, ILine, IPoint, IVector, TCubicBezierValues } from '../types';
|
|
2
|
+
import { Figure } from '../abstracts/Figure';
|
|
3
|
+
export declare class CubicBezierCurve extends Figure implements ICubicBezierCurve {
|
|
4
|
+
private _criticalPoints;
|
|
5
|
+
constructor(values: TCubicBezierValues);
|
|
6
|
+
get boundingBox(): IBoundingBox;
|
|
7
|
+
get criticalPoints(): IPoint[];
|
|
8
|
+
private get P0();
|
|
9
|
+
private get P1();
|
|
10
|
+
private get P2();
|
|
11
|
+
private get P3();
|
|
12
|
+
clone(): CubicBezierCurve;
|
|
13
|
+
recompute(): void;
|
|
14
|
+
reflect(about: IPoint | ILine): this;
|
|
15
|
+
rotate(phi: IAngle, about?: IPoint | undefined): this;
|
|
16
|
+
scale(factor: number, about?: IPoint): this;
|
|
17
|
+
translate(vector: IVector): this;
|
|
18
|
+
private computeCriticalPoints;
|
|
19
|
+
private computeCriticalPointsTValues;
|
|
20
|
+
private getCoordinateAtParameter;
|
|
21
|
+
private getPointAtParameter;
|
|
22
|
+
private isValidParameter;
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TEllipseValues, IBoundingBox, IPoint, IEllipse, TEllipseCriticalPoints, IMagnitude, IVector, ILine, IAngle } from '../types';
|
|
2
|
+
import { Figure } from '../abstracts/Figure';
|
|
3
|
+
export declare class Ellipse extends Figure implements IEllipse {
|
|
4
|
+
private _center;
|
|
5
|
+
private _criticalPoints;
|
|
6
|
+
private _phi;
|
|
7
|
+
private _rx;
|
|
8
|
+
private _ry;
|
|
9
|
+
constructor(values: TEllipseValues);
|
|
10
|
+
get boundingBox(): IBoundingBox;
|
|
11
|
+
get center(): IPoint;
|
|
12
|
+
get criticalPoints(): TEllipseCriticalPoints;
|
|
13
|
+
get isCircle(): boolean;
|
|
14
|
+
get phi(): IAngle;
|
|
15
|
+
get rx(): IMagnitude;
|
|
16
|
+
get ry(): IMagnitude;
|
|
17
|
+
clone(): IEllipse;
|
|
18
|
+
computePointForTheta(theta: IAngle, ellipse?: IEllipse): IPoint;
|
|
19
|
+
computeThetaForPoint({ x, y }: IPoint): IAngle;
|
|
20
|
+
reflect(about: IPoint | ILine): this;
|
|
21
|
+
rotate(alpha: IAngle, about?: IPoint | undefined): this;
|
|
22
|
+
scale(factor: number, about?: IPoint): this;
|
|
23
|
+
translate(vector: IVector): this;
|
|
24
|
+
protected computeCriticalPoints(ellipse?: IEllipse): TEllipseCriticalPoints;
|
|
25
|
+
private recompute;
|
|
26
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { IAngle, ILine, IPoint, IVector, TLineValues } from '../types';
|
|
2
|
+
import { Figure } from '../abstracts/Figure';
|
|
3
|
+
export declare class Line extends Figure implements ILine {
|
|
4
|
+
private _P0;
|
|
5
|
+
private _P1;
|
|
6
|
+
private _V;
|
|
7
|
+
private _reciprocal;
|
|
8
|
+
private _slope;
|
|
9
|
+
private _xIntercept;
|
|
10
|
+
private _yIntercept;
|
|
11
|
+
constructor(values: TLineValues);
|
|
12
|
+
get P0(): IPoint;
|
|
13
|
+
get P1(): IPoint;
|
|
14
|
+
get V(): IVector;
|
|
15
|
+
get a(): number;
|
|
16
|
+
get b(): 1 | 0 | -1;
|
|
17
|
+
get c(): number;
|
|
18
|
+
get isHorizontal(): boolean;
|
|
19
|
+
get isVertical(): boolean;
|
|
20
|
+
get reciprocal(): number | undefined;
|
|
21
|
+
get slope(): number | undefined;
|
|
22
|
+
get xIntercept(): number | undefined;
|
|
23
|
+
get yIntercept(): number | undefined;
|
|
24
|
+
angleTo(line: ILine): IAngle;
|
|
25
|
+
clone(): Line;
|
|
26
|
+
getIntersectionPoint(line: ILine): IPoint | undefined;
|
|
27
|
+
getPerpendicularProjection(point: IPoint): IPoint;
|
|
28
|
+
getPerpendicularThrough(point: IPoint): ILine;
|
|
29
|
+
getPointAtParameter(t: number): IPoint;
|
|
30
|
+
getXValueAtY(y: number): number | undefined;
|
|
31
|
+
getYValueAtX(x: number): number | undefined;
|
|
32
|
+
hasPoint(P: IPoint): boolean;
|
|
33
|
+
isParallelTo(line: ILine): boolean;
|
|
34
|
+
isPerpendicularTo(line: ILine): boolean;
|
|
35
|
+
reflect(about: ILine | IPoint): this;
|
|
36
|
+
rotate(phi: IAngle, about?: IPoint | undefined): this;
|
|
37
|
+
scale(factor: number, about?: IPoint): this;
|
|
38
|
+
translate(vector: IVector): this;
|
|
39
|
+
private computeReciprocal;
|
|
40
|
+
private computeSlope;
|
|
41
|
+
private computeXIntercept;
|
|
42
|
+
private computeYIntercept;
|
|
43
|
+
private recompute;
|
|
44
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IAngle, IBoundingBox, ILine, IPoint, IQuadraticBezierCurve, IVector, TQuadraticBezierValues } from '../types';
|
|
2
|
+
import { Figure } from '../abstracts/Figure';
|
|
3
|
+
export declare class QuadraticBezierCurve extends Figure implements IQuadraticBezierCurve {
|
|
4
|
+
private _criticalPoints;
|
|
5
|
+
constructor(values: TQuadraticBezierValues);
|
|
6
|
+
get boundingBox(): IBoundingBox;
|
|
7
|
+
get criticalPoints(): IPoint[];
|
|
8
|
+
private get P0();
|
|
9
|
+
private get P1();
|
|
10
|
+
private get P2();
|
|
11
|
+
clone(): QuadraticBezierCurve;
|
|
12
|
+
recompute(): void;
|
|
13
|
+
reflect(about: IPoint | ILine): this;
|
|
14
|
+
rotate(phi: IAngle, about?: IPoint | undefined): this;
|
|
15
|
+
scale(factor: number, about?: IPoint): this;
|
|
16
|
+
translate(vector: IVector): this;
|
|
17
|
+
private computeCriticalPoints;
|
|
18
|
+
private getCoordinateAtParameter;
|
|
19
|
+
private getCriticalPointTValue;
|
|
20
|
+
private getPointAtParameter;
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { Angle } from './abstracts/Angle';
|
|
2
|
+
export { Figure } from './abstracts/Figure';
|
|
3
|
+
export { Flag } from './abstracts/Flag';
|
|
4
|
+
export { Magnitude } from './abstracts/Magnitude';
|
|
5
|
+
export { Point } from './abstracts/Point';
|
|
6
|
+
export { Vector } from './abstracts/Vector.js';
|
|
7
|
+
export { ArcCurve } from './figures/ArcCurve';
|
|
8
|
+
export { Circle } from './figures/Circle';
|
|
9
|
+
export { CubicBezierCurve } from './figures/CubicBezierCurve';
|
|
10
|
+
export { Ellipse } from './figures/Ellipse';
|
|
11
|
+
export { Line } from './figures/Line';
|
|
12
|
+
export { Polygon } from './figures/Polygon';
|
|
13
|
+
export { QuadraticBezierCurve } from './figures/QuadraticBezierCurve';
|
|
14
|
+
export { Calculator } from './utilities/Calculator';
|
|
15
|
+
export * from './utilities';
|
|
16
|
+
export * from './types';
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
export type TSegment = [IPoint, IPoint];
|
|
2
|
+
export type TAxis = 'x' | 'y';
|
|
3
|
+
export type TAxii = ['x', 'y'];
|
|
4
|
+
export interface IBoundingBox {
|
|
5
|
+
xMax: number;
|
|
6
|
+
xMin: number;
|
|
7
|
+
yMax: number;
|
|
8
|
+
yMin: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ISize {
|
|
11
|
+
height: number;
|
|
12
|
+
width: number;
|
|
13
|
+
}
|
|
14
|
+
export interface IClonable<T> {
|
|
15
|
+
clone(): T;
|
|
16
|
+
}
|
|
17
|
+
export interface IFlag extends IClonable<IFlag> {
|
|
18
|
+
readonly value: boolean;
|
|
19
|
+
invert(): this;
|
|
20
|
+
replace(value: boolean): this;
|
|
21
|
+
valueOf(): number;
|
|
22
|
+
}
|
|
23
|
+
export type TAngleUnit = 'radians' | 'degrees';
|
|
24
|
+
export interface IAngle extends IClonable<IAngle> {
|
|
25
|
+
readonly cos: number;
|
|
26
|
+
readonly cot: number;
|
|
27
|
+
readonly degrees: number;
|
|
28
|
+
readonly radians: number;
|
|
29
|
+
readonly sin: number;
|
|
30
|
+
readonly tan: number;
|
|
31
|
+
normalize(): this;
|
|
32
|
+
replace(value: number, unit: TAngleUnit): this;
|
|
33
|
+
scale(factor: number): this;
|
|
34
|
+
valueOf(): number;
|
|
35
|
+
}
|
|
36
|
+
export type TAngleRange = [IAngle, IAngle];
|
|
37
|
+
export interface IMagnitude extends IClonable<IMagnitude> {
|
|
38
|
+
replace(value: number): this;
|
|
39
|
+
scale(factor: number): this;
|
|
40
|
+
valueOf(): number;
|
|
41
|
+
}
|
|
42
|
+
export type TPointValues = [number, number];
|
|
43
|
+
export interface IPoint extends IClonable<IPoint> {
|
|
44
|
+
readonly values: TPointValues;
|
|
45
|
+
readonly x: number;
|
|
46
|
+
readonly y: number;
|
|
47
|
+
reflect(about: IPoint): this;
|
|
48
|
+
replace(point: IPoint): this;
|
|
49
|
+
rotate(phi: IAngle, about?: IPoint): this;
|
|
50
|
+
translate(vector: IVector): this;
|
|
51
|
+
}
|
|
52
|
+
export type TVectorValues = [number, number];
|
|
53
|
+
export interface IVector extends IClonable<IVector> {
|
|
54
|
+
readonly dx: number;
|
|
55
|
+
readonly dy: number;
|
|
56
|
+
readonly values: TVectorValues;
|
|
57
|
+
angleTo(vector: IVector): IAngle;
|
|
58
|
+
dotProduct(vector: IVector): number;
|
|
59
|
+
reflect(about: {
|
|
60
|
+
x: boolean;
|
|
61
|
+
y: boolean;
|
|
62
|
+
}): this;
|
|
63
|
+
replace(vector: IVector): this;
|
|
64
|
+
rotate(phi: IAngle): this;
|
|
65
|
+
scale(factor: number): this;
|
|
66
|
+
}
|
|
67
|
+
export type TFigureValue = IFlag | IMagnitude | IAngle | IPoint | IVector;
|
|
68
|
+
export type TFigureValues = [IPoint, ...TFigureValue[]];
|
|
69
|
+
export interface IFigure {
|
|
70
|
+
readonly boundingBox: IBoundingBox;
|
|
71
|
+
readonly values: TFigureValues;
|
|
72
|
+
reflect(about: IPoint | ILine): this;
|
|
73
|
+
rotate(phi: IAngle, about?: IPoint): this;
|
|
74
|
+
scale(factor: number, about?: IPoint): this;
|
|
75
|
+
translate(vector: IVector): this;
|
|
76
|
+
}
|
|
77
|
+
export type TLineRelativeValues = [IPoint, IVector];
|
|
78
|
+
export type TLineAbsoluteValues = [IPoint, IPoint];
|
|
79
|
+
export type TLineValues = TLineAbsoluteValues | TLineRelativeValues;
|
|
80
|
+
export interface ILine extends IFigure, IClonable<ILine> {
|
|
81
|
+
readonly P0: IPoint;
|
|
82
|
+
readonly P1: IPoint;
|
|
83
|
+
readonly V: IVector;
|
|
84
|
+
readonly a: number;
|
|
85
|
+
readonly b: number;
|
|
86
|
+
readonly c: number;
|
|
87
|
+
readonly isHorizontal: boolean;
|
|
88
|
+
readonly isVertical: boolean;
|
|
89
|
+
readonly reciprocal: number | undefined;
|
|
90
|
+
readonly slope: number | undefined;
|
|
91
|
+
readonly xIntercept: number | undefined;
|
|
92
|
+
readonly yIntercept: number | undefined;
|
|
93
|
+
angleTo(reference: ILine | IVector): IAngle;
|
|
94
|
+
getIntersectionPoint(line: ILine): IPoint | undefined;
|
|
95
|
+
getPerpendicularProjection(point: IPoint): IPoint;
|
|
96
|
+
getPerpendicularThrough(point: IPoint): ILine;
|
|
97
|
+
getPointAtParameter(t: number): IPoint | undefined;
|
|
98
|
+
getXValueAtY(y: number): number | undefined;
|
|
99
|
+
getYValueAtX(x: number): number | undefined;
|
|
100
|
+
hasPoint(point: IPoint): boolean;
|
|
101
|
+
isParallelTo(line: ILine): boolean;
|
|
102
|
+
isPerpendicularTo(line: ILine): boolean;
|
|
103
|
+
}
|
|
104
|
+
export type TEllipseValues = [IPoint, IMagnitude, IMagnitude, IAngle];
|
|
105
|
+
export type TEllipseCriticalPoints = [IPoint, IPoint, IPoint, IPoint];
|
|
106
|
+
export interface IEllipse extends IFigure, IClonable<IEllipse> {
|
|
107
|
+
readonly center: IPoint;
|
|
108
|
+
readonly criticalPoints: TEllipseCriticalPoints;
|
|
109
|
+
readonly phi: IAngle;
|
|
110
|
+
readonly rx: IMagnitude;
|
|
111
|
+
readonly ry: IMagnitude;
|
|
112
|
+
computePointForTheta(theta: IAngle): IPoint;
|
|
113
|
+
computeThetaForPoint(point: IPoint): IAngle;
|
|
114
|
+
}
|
|
115
|
+
export type TCircleValues = [IPoint, IMagnitude];
|
|
116
|
+
export interface ICircle extends IFigure, IClonable<ICircle> {
|
|
117
|
+
readonly center: IPoint;
|
|
118
|
+
readonly criticalPoints: TEllipseCriticalPoints;
|
|
119
|
+
readonly phi: IAngle;
|
|
120
|
+
readonly radius: IMagnitude;
|
|
121
|
+
}
|
|
122
|
+
export type TArcAbsoluteValues = [IPoint, IMagnitude, IMagnitude, IAngle, IFlag, IFlag, IPoint];
|
|
123
|
+
export type TArcRelativeValues = [IPoint, IMagnitude, IMagnitude, IAngle, IFlag, IFlag, IVector];
|
|
124
|
+
export type TArcValues = TArcAbsoluteValues | TArcRelativeValues;
|
|
125
|
+
export interface IArcCurve extends IFigure, IClonable<IArcCurve> {
|
|
126
|
+
readonly center: IPoint;
|
|
127
|
+
readonly criticalPoints: IPoint[];
|
|
128
|
+
}
|
|
129
|
+
export type TCubicBezierAbsoluteValues = [IPoint, IPoint, IPoint, IPoint];
|
|
130
|
+
export type TCubicBezierRelativeValues = [IPoint, IVector, IVector, IVector];
|
|
131
|
+
export type TCubicBezierValues = TCubicBezierAbsoluteValues | TCubicBezierRelativeValues;
|
|
132
|
+
export interface ICubicBezierCurve extends IFigure, IClonable<ICubicBezierCurve> {
|
|
133
|
+
readonly criticalPoints: IPoint[];
|
|
134
|
+
}
|
|
135
|
+
export type TQuadraticBezierAbsoluteValues = [IPoint, IPoint, IPoint];
|
|
136
|
+
export type TQuadraticBezierRelativeValues = [IPoint, IVector, IVector];
|
|
137
|
+
export type TQuadraticBezierValues = TQuadraticBezierAbsoluteValues | TQuadraticBezierRelativeValues;
|
|
138
|
+
export interface IQuadraticBezierCurve extends IFigure, IClonable<IQuadraticBezierCurve> {
|
|
139
|
+
readonly criticalPoints: IPoint[];
|
|
140
|
+
}
|
|
141
|
+
export type TPolygonValues = [IPoint, IPoint, IPoint, ...IPoint[]];
|
|
142
|
+
export interface IPolygon extends IClonable<IPolygon> {
|
|
143
|
+
readonly sides: number;
|
|
144
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
type TInput = Calculator | number;
|
|
2
|
+
export declare class Calculator {
|
|
3
|
+
private _instance;
|
|
4
|
+
constructor(arg: number);
|
|
5
|
+
static abs(arg: TInput): Calculator;
|
|
6
|
+
static acos(arg: TInput): Calculator;
|
|
7
|
+
static add(first: TInput, second: TInput): Calculator;
|
|
8
|
+
static atan(arg: TInput): Calculator;
|
|
9
|
+
static atan2(first: TInput, second: TInput): Calculator;
|
|
10
|
+
static cos(arg: TInput): Calculator;
|
|
11
|
+
static div(first: TInput, second: TInput): Calculator;
|
|
12
|
+
static max(args: TInput[]): Calculator;
|
|
13
|
+
static min(args: TInput[]): Calculator;
|
|
14
|
+
static mod(first: TInput, second: TInput): Calculator;
|
|
15
|
+
static mul(first: TInput, second: TInput): Calculator;
|
|
16
|
+
static neg(arg: TInput): Calculator;
|
|
17
|
+
static pow(first: TInput, second: TInput): Calculator;
|
|
18
|
+
static sin(arg: TInput): Calculator;
|
|
19
|
+
static sqrt(arg: TInput): Calculator;
|
|
20
|
+
static sub(first: TInput, second: TInput): Calculator;
|
|
21
|
+
static tan(arg: TInput): Calculator;
|
|
22
|
+
private static computeBinaryOperation;
|
|
23
|
+
private static computeIndefiniteOperation;
|
|
24
|
+
private static computeUnaryOperation;
|
|
25
|
+
/**
|
|
26
|
+
* @todo The precision calculation could be improved to test at what decimal point is the distance less
|
|
27
|
+
* than epsilon, and then to round up to that point instead of choosing an arbitrary precision.
|
|
28
|
+
*/
|
|
29
|
+
private static roundDecimalWithPrecision;
|
|
30
|
+
private static toDecimalArgs;
|
|
31
|
+
abs(): Calculator;
|
|
32
|
+
acos(): Calculator;
|
|
33
|
+
add(second: TInput): Calculator;
|
|
34
|
+
atan(): Calculator;
|
|
35
|
+
atan2(second: TInput): Calculator;
|
|
36
|
+
cos(): Calculator;
|
|
37
|
+
div(second: TInput): Calculator;
|
|
38
|
+
isFinite(): boolean;
|
|
39
|
+
mod(second: TInput): Calculator;
|
|
40
|
+
mul(second: TInput): Calculator;
|
|
41
|
+
neg(): Calculator;
|
|
42
|
+
pow(second: TInput): Calculator;
|
|
43
|
+
sin(): Calculator;
|
|
44
|
+
sqrt(): Calculator;
|
|
45
|
+
sub(second: TInput): Calculator;
|
|
46
|
+
tan(): Calculator;
|
|
47
|
+
valueOf(): number;
|
|
48
|
+
}
|
|
49
|
+
export {};
|