geometric-library 1.3.0 → 1.4.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.
Files changed (143) hide show
  1. package/README.md +49 -23
  2. package/dist/cjs/abstracts/{Angle.js → angle/Angle.js} +11 -11
  3. package/dist/cjs/abstracts/angle/Angle.types.js +2 -0
  4. package/dist/cjs/abstracts/angle/index.js +18 -0
  5. package/dist/cjs/abstracts/{Figure.js → figure/Figure.js} +45 -30
  6. package/dist/cjs/abstracts/figure/Figure.types.js +2 -0
  7. package/dist/cjs/abstracts/figure/index.js +18 -0
  8. package/dist/cjs/abstracts/{Flag.js → flag/Flag.js} +1 -0
  9. package/dist/cjs/abstracts/flag/Flag.types.js +2 -0
  10. package/dist/cjs/abstracts/flag/index.js +18 -0
  11. package/dist/cjs/abstracts/index.js +22 -0
  12. package/dist/cjs/abstracts/{Magnitude.js → magnitude/Magnitude.js} +6 -2
  13. package/dist/cjs/abstracts/magnitude/Magnitude.types.js +2 -0
  14. package/dist/cjs/abstracts/magnitude/index.js +18 -0
  15. package/dist/cjs/abstracts/{Point.js → point/Point.js} +8 -7
  16. package/dist/cjs/abstracts/point/Point.types.js +2 -0
  17. package/dist/cjs/abstracts/point/index.js +18 -0
  18. package/dist/cjs/abstracts/{Vector.js → vector/Vector.js} +16 -15
  19. package/dist/cjs/abstracts/vector/Vector.types.js +2 -0
  20. package/dist/cjs/abstracts/vector/index.js +18 -0
  21. package/dist/cjs/figures/arc-curve/ArcCurve.js +174 -0
  22. package/dist/cjs/figures/arc-curve/ArcCurve.types.js +2 -0
  23. package/dist/cjs/figures/arc-curve/index.js +18 -0
  24. package/dist/cjs/figures/{Circle.js → circle/Circle.js} +8 -9
  25. package/dist/cjs/figures/circle/Circle.types.js +2 -0
  26. package/dist/cjs/figures/circle/index.js +18 -0
  27. package/dist/cjs/figures/{CubicBezierCurve.js → cubic-bezier-curve/CubicBezierCurve.js} +22 -17
  28. package/dist/cjs/figures/cubic-bezier-curve/CubicBezierCurve.types.js +2 -0
  29. package/dist/cjs/figures/cubic-bezier-curve/index.js +18 -0
  30. package/dist/cjs/figures/ellipse/Ellipse.js +129 -0
  31. package/dist/cjs/figures/ellipse/Ellipse.types.js +2 -0
  32. package/dist/cjs/figures/ellipse/index.js +18 -0
  33. package/dist/cjs/figures/index.js +23 -0
  34. package/dist/cjs/figures/{Line.js → line/Line.js} +78 -59
  35. package/dist/cjs/figures/line/Line.types.js +2 -0
  36. package/dist/cjs/figures/line/index.js +18 -0
  37. package/dist/cjs/figures/polygon/Polygon.js +51 -0
  38. package/dist/cjs/figures/polygon/Polygon.types.js +2 -0
  39. package/dist/cjs/figures/polygon/index.js +18 -0
  40. package/dist/cjs/figures/{QuadraticBezierCurve.js → quadratic-bezier-curve/QuadraticBezierCurve.js} +12 -8
  41. package/dist/cjs/figures/quadratic-bezier-curve/QuadraticBezierCurve.types.js +2 -0
  42. package/dist/cjs/figures/quadratic-bezier-curve/index.js +18 -0
  43. package/dist/cjs/index.js +2 -29
  44. package/dist/cjs/utilities/{Calculator.js → calculator/Calculator.js} +9 -1
  45. package/dist/cjs/utilities/calculator/index.js +17 -0
  46. package/dist/cjs/utilities/index.js +20 -8
  47. package/dist/esm/abstracts/{Angle.js → angle/Angle.js} +4 -4
  48. package/dist/esm/abstracts/angle/Angle.types.js +1 -0
  49. package/dist/esm/abstracts/angle/index.js +2 -0
  50. package/dist/esm/abstracts/{Figure.js → figure/Figure.js} +37 -22
  51. package/dist/esm/abstracts/figure/Figure.types.js +1 -0
  52. package/dist/esm/abstracts/figure/index.js +2 -0
  53. package/dist/esm/abstracts/{Flag.js → flag/Flag.js} +1 -0
  54. package/dist/esm/abstracts/flag/Flag.types.js +1 -0
  55. package/dist/esm/abstracts/flag/index.js +2 -0
  56. package/dist/esm/abstracts/index.js +6 -0
  57. package/dist/esm/abstracts/{Magnitude.js → magnitude/Magnitude.js} +5 -1
  58. package/dist/esm/abstracts/magnitude/Magnitude.types.js +1 -0
  59. package/dist/esm/abstracts/magnitude/index.js +2 -0
  60. package/dist/esm/abstracts/{Point.js → point/Point.js} +2 -1
  61. package/dist/esm/abstracts/point/Point.types.js +1 -0
  62. package/dist/esm/abstracts/point/index.js +2 -0
  63. package/dist/esm/abstracts/{Vector.js → vector/Vector.js} +3 -2
  64. package/dist/esm/abstracts/vector/Vector.types.js +1 -0
  65. package/dist/esm/abstracts/vector/index.js +2 -0
  66. package/dist/esm/figures/{ArcCurve.js → arc-curve/ArcCurve.js} +50 -8
  67. package/dist/esm/figures/arc-curve/ArcCurve.types.js +1 -0
  68. package/dist/esm/figures/arc-curve/index.js +2 -0
  69. package/dist/esm/figures/{Circle.js → circle/Circle.js} +3 -4
  70. package/dist/esm/figures/circle/Circle.types.js +1 -0
  71. package/dist/esm/figures/circle/index.js +2 -0
  72. package/dist/esm/figures/{CubicBezierCurve.js → cubic-bezier-curve/CubicBezierCurve.js} +11 -6
  73. package/dist/esm/figures/cubic-bezier-curve/CubicBezierCurve.types.js +1 -0
  74. package/dist/esm/figures/cubic-bezier-curve/index.js +2 -0
  75. package/dist/esm/figures/{Ellipse.js → ellipse/Ellipse.js} +24 -6
  76. package/dist/esm/figures/ellipse/Ellipse.types.js +1 -0
  77. package/dist/esm/figures/ellipse/index.js +2 -0
  78. package/dist/esm/figures/index.js +7 -0
  79. package/dist/esm/figures/{Line.js → line/Line.js} +57 -38
  80. package/dist/esm/figures/line/Line.types.js +1 -0
  81. package/dist/esm/figures/line/index.js +2 -0
  82. package/dist/esm/figures/polygon/Polygon.js +47 -0
  83. package/dist/esm/figures/polygon/Polygon.types.js +1 -0
  84. package/dist/esm/figures/polygon/index.js +2 -0
  85. package/dist/esm/figures/{QuadraticBezierCurve.js → quadratic-bezier-curve/QuadraticBezierCurve.js} +7 -3
  86. package/dist/esm/figures/quadratic-bezier-curve/QuadraticBezierCurve.types.js +1 -0
  87. package/dist/esm/figures/quadratic-bezier-curve/index.js +2 -0
  88. package/dist/esm/index.js +2 -14
  89. package/dist/esm/utilities/{Calculator.js → calculator/Calculator.js} +9 -1
  90. package/dist/esm/utilities/calculator/index.js +1 -0
  91. package/dist/esm/utilities/index.js +4 -6
  92. package/dist/types/abstracts/{Angle.d.ts → angle/Angle.d.ts} +2 -1
  93. package/dist/types/abstracts/angle/Angle.types.d.ts +16 -0
  94. package/dist/types/abstracts/angle/index.d.ts +2 -0
  95. package/dist/types/abstracts/{Figure.d.ts → figure/Figure.d.ts} +4 -4
  96. package/dist/types/abstracts/figure/Figure.types.d.ts +14 -0
  97. package/dist/types/abstracts/figure/index.d.ts +2 -0
  98. package/dist/types/abstracts/{Flag.d.ts → flag/Flag.d.ts} +2 -1
  99. package/dist/types/abstracts/flag/Flag.types.d.ts +8 -0
  100. package/dist/types/abstracts/flag/index.d.ts +2 -0
  101. package/dist/types/abstracts/index.d.ts +6 -0
  102. package/dist/types/abstracts/{Magnitude.d.ts → magnitude/Magnitude.d.ts} +3 -1
  103. package/dist/types/abstracts/magnitude/Magnitude.types.d.ts +8 -0
  104. package/dist/types/abstracts/magnitude/index.d.ts +2 -0
  105. package/dist/types/abstracts/{Point.d.ts → point/Point.d.ts} +2 -1
  106. package/dist/types/abstracts/point/Point.types.d.ts +13 -0
  107. package/dist/types/abstracts/point/index.d.ts +2 -0
  108. package/dist/types/abstracts/{Vector.d.ts → vector/Vector.d.ts} +3 -1
  109. package/dist/types/abstracts/vector/Vector.types.d.ts +19 -0
  110. package/dist/types/abstracts/vector/index.d.ts +2 -0
  111. package/dist/types/figures/{ArcCurve.d.ts → arc-curve/ArcCurve.d.ts} +7 -2
  112. package/dist/types/figures/arc-curve/ArcCurve.types.d.ts +11 -0
  113. package/dist/types/figures/arc-curve/index.d.ts +2 -0
  114. package/dist/types/figures/{Circle.d.ts → circle/Circle.d.ts} +3 -2
  115. package/dist/types/figures/circle/Circle.types.d.ts +9 -0
  116. package/dist/types/figures/circle/index.d.ts +2 -0
  117. package/dist/types/figures/{CubicBezierCurve.d.ts → cubic-bezier-curve/CubicBezierCurve.d.ts} +4 -2
  118. package/dist/types/figures/cubic-bezier-curve/CubicBezierCurve.types.d.ts +8 -0
  119. package/dist/types/figures/cubic-bezier-curve/index.d.ts +2 -0
  120. package/dist/types/figures/{Ellipse.d.ts → ellipse/Ellipse.d.ts} +5 -2
  121. package/dist/types/figures/ellipse/Ellipse.types.d.ts +16 -0
  122. package/dist/types/figures/ellipse/index.d.ts +2 -0
  123. package/dist/types/figures/index.d.ts +7 -0
  124. package/dist/types/figures/{Line.d.ts → line/Line.d.ts} +6 -4
  125. package/dist/types/figures/line/Line.types.d.ts +30 -0
  126. package/dist/types/figures/line/index.d.ts +2 -0
  127. package/dist/types/figures/polygon/Polygon.d.ts +17 -0
  128. package/dist/types/figures/polygon/Polygon.types.d.ts +8 -0
  129. package/dist/types/figures/polygon/index.d.ts +2 -0
  130. package/dist/types/figures/{QuadraticBezierCurve.d.ts → quadratic-bezier-curve/QuadraticBezierCurve.d.ts} +4 -2
  131. package/dist/types/figures/quadratic-bezier-curve/QuadraticBezierCurve.types.d.ts +8 -0
  132. package/dist/types/figures/quadratic-bezier-curve/index.d.ts +2 -0
  133. package/dist/types/index.d.ts +2 -14
  134. package/dist/types/types/index.d.ts +0 -129
  135. package/dist/types/utilities/{Calculator.d.ts → calculator/Calculator.d.ts} +4 -0
  136. package/dist/types/utilities/calculator/index.d.ts +1 -0
  137. package/dist/types/utilities/index.d.ts +2 -4
  138. package/package.json +24 -18
  139. package/dist/cjs/figures/ArcCurve.js +0 -132
  140. package/dist/cjs/figures/Ellipse.js +0 -111
  141. package/dist/cjs/figures/Polygon.js +0 -17
  142. package/dist/esm/figures/Polygon.js +0 -13
  143. package/dist/types/figures/Polygon.d.ts +0 -7
@@ -1,16 +1,4 @@
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';
1
+ export * from './abstracts';
2
+ export * from './figures';
15
3
  export * from './utilities';
16
4
  export * from './types';
@@ -1,4 +1,3 @@
1
- export type TSegment = [IPoint, IPoint];
2
1
  export type TAxis = 'x' | 'y';
3
2
  export type TAxii = ['x', 'y'];
4
3
  export interface IBoundingBox {
@@ -14,131 +13,3 @@ export interface ISize {
14
13
  export interface IClonable<T> {
15
14
  clone(): T;
16
15
  }
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
- }
@@ -1,5 +1,7 @@
1
1
  type TInput = Calculator | number;
2
2
  export declare class Calculator {
3
+ static readonly EPSILON: number;
4
+ static readonly PI2: number;
3
5
  private _instance;
4
6
  constructor(arg: number);
5
7
  static abs(arg: TInput): Calculator;
@@ -9,6 +11,8 @@ export declare class Calculator {
9
11
  static atan2(first: TInput, second: TInput): Calculator;
10
12
  static cos(arg: TInput): Calculator;
11
13
  static div(first: TInput, second: TInput): Calculator;
14
+ static isEqual(a: number, b: number): boolean;
15
+ static isNearZero(a: number): boolean;
12
16
  static max(args: TInput[]): Calculator;
13
17
  static min(args: TInput[]): Calculator;
14
18
  static mod(first: TInput, second: TInput): Calculator;
@@ -0,0 +1 @@
1
+ export * from './Calculator';
@@ -1,6 +1,4 @@
1
- import { Point } from '../abstracts/Point';
2
- import { Line } from '../figures/Line';
1
+ import { Point } from '../abstracts';
2
+ export * from './calculator';
3
3
  export declare const coordinateOrigin: Point;
4
- export declare const xAxis: Line;
5
- export declare const yAxis: Line;
6
4
  export declare const PI2: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geometric-library",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "A Node based, visually agnostic implementation of geometric functions, both abstract and finite.",
5
5
  "keywords": [
6
6
  "geometry",
@@ -24,12 +24,12 @@
24
24
  "types": "dist/types/index.d.ts",
25
25
  "scripts": {
26
26
  "build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:types",
27
- "build:cjs": "tsc --project tsconfig.cjs.json",
28
- "build:esm": "tsc --project tsconfig.esm.json",
29
- "build:types": "tsc --declaration --emitDeclarationOnly --outDir dist/types",
27
+ "build:cjs": "tsc --project tsconfig.cjs.json && tsc-alias -p tsconfig.cjs.json",
28
+ "build:esm": "tsc --project tsconfig.esm.json && tsc-alias -p tsconfig.esm.json",
29
+ "build:types": "tsc --project tsconfig.types.json && tsc-alias -p tsconfig.types.json",
30
30
  "clean": "rm -rf dist",
31
- "lint": "npx eslint ./src --ext .js,.ts",
32
- "lint:fix": "npx eslint ./src --ext .js,.ts --fix",
31
+ "lint": "npx eslint ./src",
32
+ "lint:fix": "npx eslint ./src --fix",
33
33
  "prepare": "husky",
34
34
  "prettier": "npx prettier . --write",
35
35
  "test": "vitest --watch false",
@@ -40,21 +40,27 @@
40
40
  "decimal.js": "^10.4.3"
41
41
  },
42
42
  "devDependencies": {
43
- "@types/node": "^20.14.2",
44
- "@typescript-eslint/eslint-plugin": "^7.12.0",
45
- "@typescript-eslint/parser": "^7.12.0",
46
- "@vitest/coverage-v8": "^1.6.0",
47
- "eslint": "^8.57.0",
48
- "eslint-config-prettier": "^9.1.0",
49
- "eslint-config-standard": "^17.1.0",
50
- "eslint-import-resolver-typescript": "^3.6.1",
51
- "eslint-plugin-import": "^2.29.1",
43
+ "@commitlint/cli": "^20.4.1",
44
+ "@commitlint/config-conventional": "^20.4.1",
45
+ "@eslint/js": "^9.39.2",
46
+ "@semantic-release/changelog": "^6.0.3",
47
+ "@semantic-release/git": "^10.0.1",
48
+ "@types/node": "^22.19.8",
49
+ "@vitest/coverage-v8": "^4.0.18",
50
+ "eslint": "^9.39.2",
51
+ "eslint-config-prettier": "^10.1.8",
52
+ "eslint-import-resolver-typescript": "^4.4.4",
53
+ "eslint-plugin-import-x": "^4.16.1",
54
+ "globals": "^17.3.0",
52
55
  "husky": "^9.0.11",
53
56
  "prettier": "^3.3.2",
54
57
  "prettier-eslint": "^16.3.0",
55
- "prettier-plugin-packagejson": "^2.5.0",
58
+ "prettier-plugin-packagejson": "^3.0.0",
59
+ "semantic-release": "^25.0.3",
60
+ "tsc-alias": "^1.8.16",
56
61
  "typescript": "^5.1.6",
57
- "vite-tsconfig-paths": "^4.3.2",
58
- "vitest": "^1.6.0"
62
+ "typescript-eslint": "^8.54.0",
63
+ "vite-tsconfig-paths": "^6.0.5",
64
+ "vitest": "^4.0.18"
59
65
  }
60
66
  }
@@ -1,132 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArcCurve = void 0;
4
- const Calculator_1 = require("../utilities/Calculator");
5
- const Point_1 = require("../abstracts/Point");
6
- const Figure_1 = require("../abstracts/Figure");
7
- const Ellipse_1 = require("./Ellipse");
8
- class ArcCurve extends Figure_1.Figure {
9
- ellipse;
10
- largeArcFlag;
11
- phi;
12
- rx;
13
- ry;
14
- sweepFlag;
15
- constructor(values) {
16
- super(values);
17
- const [, rx, ry, phi, largeArcFlag, sweepFlag] = values;
18
- this.rx = rx;
19
- this.ry = ry;
20
- this.phi = phi;
21
- this.largeArcFlag = largeArcFlag;
22
- this.sweepFlag = sweepFlag;
23
- this.adjustRadii();
24
- const center = this.computeCenter();
25
- this.ellipse = new Ellipse_1.Ellipse([center, rx, ry, phi]);
26
- }
27
- get boundingBox() {
28
- const { P0, P1 } = this;
29
- const points = [P0, P1, ...this.criticalPoints];
30
- return Figure_1.Figure.computeBoundingBox(points);
31
- }
32
- get center() {
33
- return this.ellipse.center;
34
- }
35
- get criticalPoints() {
36
- const { ellipse } = this;
37
- const [minTheta, maxTheta] = this.computeThetaRange();
38
- return ellipse.criticalPoints.filter((point) => {
39
- const { P0, P1 } = this;
40
- if ((point.x === P0.x && point.y === P0.y) || (point.x === P1.x && point.y === P1.y)) {
41
- return false;
42
- }
43
- const theta = ellipse.computeThetaForPoint(point);
44
- return +theta >= +minTheta && +theta <= +maxTheta;
45
- });
46
- }
47
- get P0() {
48
- return this.points[0];
49
- }
50
- get P1() {
51
- if (this.isRelative) {
52
- return this.P0.clone().translate(this.vectors[0]);
53
- }
54
- return this.points[1];
55
- }
56
- clone() {
57
- const values = this.values.map((value) => (typeof value === 'object' && 'clone' in value ? value.clone() : value));
58
- return new ArcCurve(values);
59
- }
60
- reflect(about) {
61
- super.reflect(about);
62
- this.sweepFlag.invert();
63
- return this;
64
- }
65
- adjustRadii() {
66
- const { rx, ry } = this;
67
- const P0_prime = this.computeP0Prime();
68
- const { x: x1_prime, y: y1_prime } = P0_prime;
69
- const rx_sq = Calculator_1.Calculator.pow(+rx, 2);
70
- const ry_sq = Calculator_1.Calculator.pow(+ry, 2);
71
- const x1_prime_sq = Calculator_1.Calculator.pow(x1_prime, 2);
72
- const y1_prime_sq = Calculator_1.Calculator.pow(y1_prime, 2);
73
- const radii_check = x1_prime_sq.div(rx_sq).add(y1_prime_sq.div(ry_sq));
74
- if (+radii_check > 1) {
75
- rx.replace(+Calculator_1.Calculator.mul(+rx, radii_check.sqrt()));
76
- ry.replace(+Calculator_1.Calculator.mul(+ry, radii_check.sqrt()));
77
- }
78
- }
79
- computeCenter() {
80
- const { P0, P1, phi } = this;
81
- const center_prime = this.computeCenterPrime();
82
- const { x: x1, y: y1 } = P0;
83
- const { x: x2, y: y2 } = P1;
84
- const { x: cx_prime, y: cy_prime } = center_prime;
85
- const dx = Calculator_1.Calculator.add(x1, x2).div(2);
86
- const dy = Calculator_1.Calculator.add(y1, y2).div(2);
87
- const cx = Calculator_1.Calculator.mul(phi.cos, cx_prime).sub(Calculator_1.Calculator.mul(phi.sin, cy_prime)).add(dx);
88
- const cy = Calculator_1.Calculator.mul(phi.sin, cx_prime).add(Calculator_1.Calculator.mul(phi.cos, cy_prime)).add(dy);
89
- return new Point_1.Point([+cx, +cy]);
90
- }
91
- computeCenterPrime() {
92
- const { largeArcFlag, sweepFlag, rx, ry } = this;
93
- const P0_prime = this.computeP0Prime();
94
- const { x: x1_prime, y: y1_prime } = P0_prime;
95
- const rx_sq = Calculator_1.Calculator.pow(+rx, 2);
96
- const ry_sq = Calculator_1.Calculator.pow(+ry, 2);
97
- const x1_prime_sq = Calculator_1.Calculator.pow(x1_prime, 2);
98
- const y1_prime_sq = Calculator_1.Calculator.pow(y1_prime, 2);
99
- const sign = new Calculator_1.Calculator(+largeArcFlag === +sweepFlag ? -1 : 1);
100
- let sq = rx_sq
101
- .mul(ry_sq)
102
- .sub(rx_sq.mul(y1_prime_sq))
103
- .sub(ry_sq.mul(x1_prime_sq))
104
- .div(rx_sq.mul(y1_prime_sq).add(ry_sq.mul(x1_prime_sq)));
105
- sq = +sq < 0 ? new Calculator_1.Calculator(0) : sq;
106
- const coef = sign.mul(sq.sqrt());
107
- const cx_prime = coef.mul(Calculator_1.Calculator.mul(+rx, y1_prime).div(+ry));
108
- const cy_prime = coef.mul(Calculator_1.Calculator.mul(+ry, x1_prime).div(+rx).neg());
109
- return new Point_1.Point([+cx_prime, +cy_prime]);
110
- }
111
- computeP0Prime() {
112
- const { P0, P1, phi } = this;
113
- const { x: x1, y: y1 } = P0;
114
- const { x: x2, y: y2 } = P1;
115
- const mx = Calculator_1.Calculator.sub(x1, x2).div(2);
116
- const my = Calculator_1.Calculator.sub(y1, y2).div(2);
117
- const x1_prime = Calculator_1.Calculator.mul(phi.cos, mx).add(Calculator_1.Calculator.mul(phi.sin, my));
118
- const y1_prime = Calculator_1.Calculator.mul(phi.sin, mx).neg().add(Calculator_1.Calculator.mul(phi.cos, my));
119
- return new Point_1.Point([+x1_prime, +y1_prime]);
120
- }
121
- computeThetaRange() {
122
- const { P0, P1, ellipse, sweepFlag } = this;
123
- const theta1 = ellipse.computeThetaForPoint(P0);
124
- const theta2 = ellipse.computeThetaForPoint(P1);
125
- if (+theta2 === 0 && !sweepFlag.value) {
126
- theta2.replace(360, 'degrees');
127
- }
128
- const thetaRange = [theta1, theta2].sort((a, b) => +Calculator_1.Calculator.sub(a.radians, b.radians));
129
- return thetaRange;
130
- }
131
- }
132
- exports.ArcCurve = ArcCurve;
@@ -1,111 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Ellipse = void 0;
4
- const Calculator_1 = require("../utilities/Calculator");
5
- const Angle_1 = require("../abstracts/Angle");
6
- const Point_1 = require("../abstracts/Point");
7
- const Figure_1 = require("../abstracts/Figure");
8
- const utilities_1 = require("../utilities");
9
- class Ellipse extends Figure_1.Figure {
10
- _center;
11
- _criticalPoints;
12
- _phi;
13
- _rx;
14
- _ry;
15
- constructor(values) {
16
- super(values);
17
- const [center, rx, ry, phi] = values;
18
- this._center = center;
19
- this._rx = rx;
20
- this._ry = ry;
21
- this._phi = phi;
22
- this._criticalPoints = this.computeCriticalPoints({ center, rx, ry, phi });
23
- }
24
- get boundingBox() {
25
- return Figure_1.Figure.computeBoundingBox(this.criticalPoints);
26
- }
27
- get center() {
28
- return this._center;
29
- }
30
- get criticalPoints() {
31
- return this._criticalPoints;
32
- }
33
- get isCircle() {
34
- return +this.rx === +this.ry;
35
- }
36
- get phi() {
37
- return this._phi;
38
- }
39
- get rx() {
40
- return this._rx;
41
- }
42
- get ry() {
43
- return this._ry;
44
- }
45
- clone() {
46
- const values = this.values.map((value) => value.clone());
47
- return new Ellipse(values);
48
- }
49
- computePointForTheta(theta, ellipse = this) {
50
- const { center, rx, ry, phi } = ellipse;
51
- const x = +Calculator_1.Calculator.mul(+rx, phi.cos).mul(theta.cos).sub(Calculator_1.Calculator.mul(+ry, phi.sin).mul(theta.sin)).add(center.x);
52
- const y = +Calculator_1.Calculator.mul(+rx, phi.sin).mul(theta.cos).add(Calculator_1.Calculator.mul(+ry, phi.cos).mul(theta.sin)).add(center.y);
53
- return new Point_1.Point([x, y]);
54
- }
55
- computeThetaForPoint({ x, y }) {
56
- const { center, phi, rx, ry } = this;
57
- const { x: cx, y: cy } = center;
58
- const dy = Calculator_1.Calculator.sub(y, cy);
59
- const dx = Calculator_1.Calculator.sub(x, cx);
60
- const sinTheta = dy.mul(phi.cos).sub(dx.mul(phi.sin)).div(+ry);
61
- const cosTheta = dx.mul(phi.cos).add(dy.mul(phi.sin)).div(+rx);
62
- const theta = new Angle_1.Angle(+Calculator_1.Calculator.atan2(sinTheta, cosTheta), 'radians').normalize();
63
- return theta;
64
- }
65
- reflect(about) {
66
- super.reflect(about);
67
- if (!this.isCircle && 'V' in about) {
68
- const alpha = about.angleTo(utilities_1.xAxis);
69
- this._phi.replace(+Calculator_1.Calculator.mul(2, alpha.radians).sub(this.phi.radians), 'radians');
70
- this._phi.normalize();
71
- }
72
- this.recompute();
73
- return this;
74
- }
75
- rotate(alpha, about) {
76
- this._center.rotate(alpha, about);
77
- if (!this.isCircle) {
78
- this._phi.replace(+Calculator_1.Calculator.add(this.phi.radians, alpha.radians), 'radians');
79
- this._phi.normalize();
80
- }
81
- this.recompute();
82
- return this;
83
- }
84
- scale(factor, about = new Point_1.Point([0, 0])) {
85
- super.scale(factor, about);
86
- this.recompute();
87
- return this;
88
- }
89
- translate(vector) {
90
- this._center.translate(vector);
91
- this.recompute();
92
- return this;
93
- }
94
- computeCriticalPoints(ellipse = this) {
95
- const { rx, ry, phi } = ellipse;
96
- const { computePointForTheta } = this;
97
- const xThetaPrincipal = new Angle_1.Angle(+Calculator_1.Calculator.neg(+ry).mul(phi.tan).div(+rx).atan(), 'radians');
98
- const yThetaPrincipal = new Angle_1.Angle(+Calculator_1.Calculator.mul(+ry, phi.cot).div(+rx).atan(), 'radians');
99
- const xThetaSecondary = new Angle_1.Angle(+Calculator_1.Calculator.add(+xThetaPrincipal, Math.PI), 'radians');
100
- const yThetaSecondary = new Angle_1.Angle(+Calculator_1.Calculator.add(+yThetaPrincipal, Math.PI), 'radians');
101
- const firstPoint = computePointForTheta(xThetaPrincipal, ellipse);
102
- const secondPoint = computePointForTheta(yThetaPrincipal, ellipse);
103
- const thirdPoint = computePointForTheta(xThetaSecondary, ellipse);
104
- const fourthPoint = computePointForTheta(yThetaSecondary, ellipse);
105
- return [firstPoint, secondPoint, thirdPoint, fourthPoint];
106
- }
107
- recompute() {
108
- this._criticalPoints = this.computeCriticalPoints();
109
- }
110
- }
111
- exports.Ellipse = Ellipse;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Polygon = void 0;
4
- const Figure_1 = require("../abstracts/Figure");
5
- class Polygon extends Figure_1.Figure {
6
- constructor(values) {
7
- super(values);
8
- }
9
- get sides() {
10
- return this.points.length;
11
- }
12
- clone() {
13
- const values = this.values.map((value) => value.clone());
14
- return new Polygon(values);
15
- }
16
- }
17
- exports.Polygon = Polygon;
@@ -1,13 +0,0 @@
1
- import { Figure } from '../abstracts/Figure';
2
- export class Polygon extends Figure {
3
- constructor(values) {
4
- super(values);
5
- }
6
- get sides() {
7
- return this.points.length;
8
- }
9
- clone() {
10
- const values = this.values.map((value) => value.clone());
11
- return new Polygon(values);
12
- }
13
- }
@@ -1,7 +0,0 @@
1
- import { IPolygon, TPolygonValues } from '../types';
2
- import { Figure } from '../abstracts/Figure';
3
- export declare class Polygon extends Figure implements IPolygon {
4
- constructor(values: TPolygonValues);
5
- get sides(): number;
6
- clone(): Polygon;
7
- }