pimath 0.0.113 → 0.0.115
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/dist/pi.js +149 -44
- package/dist/pi.js.map +1 -1
- package/dist/pi.min.js +1 -1
- package/dist/pi.min.js.map +1 -1
- package/docs/assets/highlight.css +3 -3
- package/docs/assets/main.js +58 -52
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +488 -621
- package/docs/classes/Logicalset.Logicalset.html +212 -0
- package/docs/classes/Polynom.Rational.html +388 -4
- package/docs/classes/Vector-1.Vector.html +448 -0
- package/docs/classes/Vector.Point.html +342 -1
- package/docs/classes/algebra_equation.Equation.html +749 -22
- package/docs/classes/algebra_linearSystem.LinearSystem.html +397 -1
- package/docs/classes/algebra_monom.Monom.html +906 -110
- package/docs/classes/algebra_polynom.Polynom.html +1258 -28
- package/docs/classes/coefficients_fraction.Fraction.html +929 -17
- package/docs/classes/expressions_numexp.NumExp.html +236 -1
- package/docs/classes/expressions_polynomexp.PolynomExpFactor.html +317 -1
- package/docs/classes/expressions_polynomexp.PolynomExpProduct.html +285 -1
- package/docs/classes/geometry_circle.Circle.html +476 -3
- package/docs/classes/geometry_line.Line.html +719 -3
- package/docs/classes/geometry_triangle.Triangle.html +417 -14
- package/docs/classes/numeric.Numeric.html +263 -14
- package/docs/classes/shutingyard.Shutingyard.html +246 -16
- package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +88 -1
- package/docs/enums/geometry_line.LinePropriety.html +102 -1
- package/docs/enums/shutingyard.ShutingyardMode.html +102 -1
- package/docs/enums/shutingyard.ShutingyardType.html +116 -1
- package/docs/index.html +56 -2
- package/docs/interfaces/algebra_equation.ISolution.html +109 -3
- package/docs/interfaces/algebra_polynom.IEuclidian.html +92 -1
- package/docs/interfaces/geometry_triangle.remarquableLines.html +150 -1
- package/docs/modules/Logicalset.html +74 -3
- package/docs/modules/Polynom.html +74 -3
- package/docs/modules/Vector-1.html +74 -0
- package/docs/modules/Vector.html +74 -3
- package/docs/modules/algebra_equation.html +81 -1
- package/docs/modules/algebra_linearSystem.html +71 -1
- package/docs/modules/algebra_monom.html +76 -1
- package/docs/modules/algebra_polynom.html +81 -1
- package/docs/modules/coefficients_fraction.html +76 -1
- package/docs/modules/expressions_numexp.html +71 -1
- package/docs/modules/expressions_polynomexp.html +73 -1
- package/docs/modules/geometry_circle.html +71 -1
- package/docs/modules/geometry_line.html +76 -1
- package/docs/modules/geometry_triangle.html +76 -1
- package/docs/modules/numeric.html +71 -1
- package/docs/modules/shutingyard.html +90 -1
- package/docs/modules.html +76 -1
- package/docs/types/algebra_monom.literalType.html +70 -0
- package/docs/types/algebra_polynom.PolynomParsingType.html +66 -0
- package/docs/types/coefficients_fraction.FractionParsingType.html +65 -0
- package/docs/types/shutingyard.Token.html +76 -0
- package/docs/types/shutingyard.tokenType.html +81 -0
- package/docs/variables/shutingyard.tokenConstant.html +74 -0
- package/esm/index.js.map +1 -1
- package/esm/maths/geometry/line.d.ts +21 -17
- package/esm/maths/geometry/line.js +68 -40
- package/esm/maths/geometry/line.js.map +1 -1
- package/esm/maths/geometry/point.d.ts +2 -0
- package/esm/maths/geometry/point.js +3 -0
- package/esm/maths/geometry/point.js.map +1 -1
- package/esm/maths/geometry/vector.d.ts +3 -1
- package/esm/maths/geometry/vector.js +6 -4
- package/esm/maths/geometry/vector.js.map +1 -1
- package/esm/maths/randomization/random.d.ts +3 -1
- package/esm/maths/randomization/random.js +5 -0
- package/esm/maths/randomization/random.js.map +1 -1
- package/esm/maths/randomization/rndGeometryLine.js.map +1 -1
- package/esm/maths/randomization/rndGeometryPoint.d.ts +12 -0
- package/esm/maths/randomization/rndGeometryPoint.js +61 -0
- package/esm/maths/randomization/rndGeometryPoint.js.map +1 -0
- package/esm/maths/randomization/rndTypes.d.ts +6 -0
- package/package.json +8 -8
- package/src/index.ts +1 -0
- package/src/maths/geometry/line.ts +116 -76
- package/src/maths/geometry/point.ts +4 -0
- package/src/maths/geometry/vector.ts +8 -5
- package/src/maths/randomization/random.ts +14 -1
- package/src/maths/randomization/rndGeometryLine.ts +5 -6
- package/src/maths/randomization/rndGeometryPoint.ts +69 -0
- package/src/maths/randomization/rndTypes.ts +8 -0
- package/tests/geometry/line.test.ts +13 -0
- package/docs/assets/icons.css +0 -1043
- package/docs/assets/icons.png +0 -0
- package/docs/assets/icons@2x.png +0 -0
- package/docs/assets/widgets.png +0 -0
- package/docs/assets/widgets@2x.png +0 -0
- package/docs/classes/Logicalset.Logicalset-1.html +0 -5
- package/docs/classes/Vector.Vector-1.html +0 -1
- package/docs/classes/coefficients_nthroot.NthRoot.html +0 -3
- package/docs/modules/coefficients_nthroot.html +0 -1
|
@@ -8,30 +8,21 @@ import {Numeric} from "../numeric";
|
|
|
8
8
|
import {Fraction} from "../coefficients/fraction";
|
|
9
9
|
import {Equation} from "../algebra/equation";
|
|
10
10
|
import {Polynom} from "../algebra/polynom";
|
|
11
|
+
import {Random} from "../randomization/random";
|
|
11
12
|
|
|
12
13
|
export enum LinePropriety {
|
|
13
14
|
None,
|
|
14
|
-
Parallel='parallel',
|
|
15
|
+
Parallel = 'parallel',
|
|
15
16
|
Perpendicular = 'perpendicular',
|
|
16
17
|
Tangent = 'tangent'
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export class Line {
|
|
20
21
|
// A line is defined as the canonical form
|
|
21
|
-
// ax + by + c = 0
|
|
22
|
-
private _a: Fraction;
|
|
23
|
-
private _b: Fraction;
|
|
24
|
-
private _c: Fraction;
|
|
25
|
-
private _OA: Point;
|
|
26
|
-
private _d: Vector;
|
|
27
|
-
private _n: Vector;
|
|
28
|
-
private _exists: boolean
|
|
29
|
-
|
|
30
|
-
private _referencePropriety: LinePropriety
|
|
31
|
-
private _referenceLine: Line
|
|
32
|
-
|
|
33
22
|
static PERPENDICULAR = LinePropriety.Perpendicular
|
|
34
23
|
static PARALLEL = LinePropriety.Parallel
|
|
24
|
+
private _referencePropriety: LinePropriety
|
|
25
|
+
private _referenceLine: Line
|
|
35
26
|
|
|
36
27
|
constructor(...values: unknown[]) {
|
|
37
28
|
|
|
@@ -44,31 +35,88 @@ export class Line {
|
|
|
44
35
|
return this;
|
|
45
36
|
}
|
|
46
37
|
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
// ax + by + c = 0
|
|
39
|
+
private _a: Fraction;
|
|
40
|
+
|
|
41
|
+
get a(): Fraction {
|
|
42
|
+
return this._a;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
set a(value: Fraction) {
|
|
46
|
+
this._a = value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private _b: Fraction;
|
|
50
|
+
|
|
51
|
+
get b(): Fraction {
|
|
52
|
+
return this._b;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
set b(value: Fraction) {
|
|
56
|
+
this._b = value;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private _c: Fraction;
|
|
60
|
+
|
|
61
|
+
get c(): Fraction {
|
|
62
|
+
return this._c;
|
|
49
63
|
}
|
|
50
64
|
|
|
51
65
|
// ------------------------------------------
|
|
52
66
|
// Getter and setter
|
|
67
|
+
|
|
68
|
+
set c(value: Fraction) {
|
|
69
|
+
this._c = value;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private _OA: Point;
|
|
73
|
+
|
|
74
|
+
get OA(): Point {
|
|
75
|
+
return this._OA;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
set OA(value: Point) {
|
|
79
|
+
this._OA = value;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private _d: Vector;
|
|
83
|
+
|
|
84
|
+
get d(): Vector {
|
|
85
|
+
return this._d;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
set d(value: Vector) {
|
|
89
|
+
this._d = value;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private _n: Vector;
|
|
93
|
+
|
|
94
|
+
get n(): Vector {
|
|
95
|
+
return this._n;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private _exists: boolean
|
|
99
|
+
|
|
100
|
+
get exists(): boolean {
|
|
101
|
+
return this._exists;
|
|
102
|
+
}
|
|
103
|
+
|
|
53
104
|
// ------------------------------------------
|
|
54
105
|
get equation(): Equation {
|
|
55
106
|
return new Equation(new Polynom().parse('xy', this._a, this._b, this._c), new Polynom('0')).simplify();
|
|
56
107
|
}
|
|
57
108
|
|
|
58
|
-
get tex(): { canonical: string, mxh: string, parametric: string
|
|
109
|
+
get tex(): { canonical: string, mxh: string, parametric: string, equation: string } {
|
|
59
110
|
// canonical => ax + by + c = 0
|
|
60
111
|
// mxh => y = -a/b x - c/b
|
|
61
112
|
// parametric => (xy) = OA + k*d
|
|
62
113
|
// equation => ax + by = -c
|
|
63
114
|
|
|
64
|
-
console.log('BEFORE', this.equation.tex)
|
|
65
115
|
let canonical = this.equation.clone().reorder(true);
|
|
66
|
-
console.log('CANONCIAL', canonical.tex)
|
|
67
116
|
// Make sur the first item is positive.
|
|
68
117
|
if (this._a.isNegative()) {
|
|
69
118
|
canonical.multiply(-1);
|
|
70
119
|
}
|
|
71
|
-
console.log('CANONCIAL (multiply)', canonical.tex)
|
|
72
120
|
|
|
73
121
|
const d = this._d.clone().simplifyDirection()
|
|
74
122
|
|
|
@@ -98,46 +146,6 @@ export class Line {
|
|
|
98
146
|
}
|
|
99
147
|
}
|
|
100
148
|
|
|
101
|
-
get a(): Fraction {
|
|
102
|
-
return this._a;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
set a(value: Fraction) {
|
|
106
|
-
this._a = value;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
get b(): Fraction {
|
|
110
|
-
return this._b;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
set b(value: Fraction) {
|
|
114
|
-
this._b = value;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
get c(): Fraction {
|
|
118
|
-
return this._c;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
set c(value: Fraction) {
|
|
122
|
-
this._c = value;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
get OA(): Point {
|
|
126
|
-
return this._OA;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
set OA(value: Point) {
|
|
130
|
-
this._OA = value;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
get d(): Vector {
|
|
134
|
-
return this._d;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
get n(): Vector {
|
|
138
|
-
return this._n;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
149
|
get normal(): Vector {
|
|
142
150
|
return new Vector(this._a, this._b);
|
|
143
151
|
}
|
|
@@ -146,10 +154,6 @@ export class Line {
|
|
|
146
154
|
return this._d.clone()
|
|
147
155
|
}
|
|
148
156
|
|
|
149
|
-
set d(value: Vector) {
|
|
150
|
-
this._d = value;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
157
|
get slope(): Fraction {
|
|
154
158
|
return this._a.clone().opposed().divide(this._b);
|
|
155
159
|
}
|
|
@@ -158,8 +162,30 @@ export class Line {
|
|
|
158
162
|
return this._c.clone().opposed().divide(this._b);
|
|
159
163
|
}
|
|
160
164
|
|
|
165
|
+
randomPoint = (k?: number): Point => {
|
|
166
|
+
// Return a random point on the line.
|
|
167
|
+
return this._d
|
|
168
|
+
.clone()
|
|
169
|
+
.multiplyByScalar(Random.numberSym((k===undefined || k<=1)?3:k, false))
|
|
170
|
+
.add(this._OA.asVector)
|
|
171
|
+
.asPoint
|
|
172
|
+
}
|
|
173
|
+
randomNearPoint = (k?: number): Point => {
|
|
174
|
+
let pt = this.randomPoint(k)
|
|
175
|
+
|
|
176
|
+
let maxIterationTest = 10
|
|
177
|
+
while(this.isOnLine(pt) && maxIterationTest>0){
|
|
178
|
+
pt.x.add(Random.numberSym(1, false))
|
|
179
|
+
pt.y.add(Random.numberSym(1, false))
|
|
180
|
+
maxIterationTest--
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
return pt
|
|
184
|
+
}
|
|
185
|
+
|
|
161
186
|
// ------------------------------------------
|
|
162
187
|
// Creation / parsing functions
|
|
188
|
+
|
|
163
189
|
// ------------------------------------------
|
|
164
190
|
/**
|
|
165
191
|
* Parse data to a line
|
|
@@ -212,18 +238,18 @@ export class Line {
|
|
|
212
238
|
(values[2] instanceof Fraction || typeof values[2] === 'number')
|
|
213
239
|
) {
|
|
214
240
|
return this.parseByCoefficient(values[0], values[1], values[2]);
|
|
215
|
-
}else if (
|
|
241
|
+
} else if (
|
|
216
242
|
values[0] instanceof Point && values[1] instanceof Vector
|
|
217
|
-
){
|
|
218
|
-
if(values[2] === LinePropriety.Perpendicular){
|
|
243
|
+
) {
|
|
244
|
+
if (values[2] === LinePropriety.Perpendicular) {
|
|
219
245
|
return this.parseByPointAndNormal(values[0], values[1])
|
|
220
|
-
}else if (values[2] === LinePropriety.Parallel){
|
|
246
|
+
} else if (values[2] === LinePropriety.Parallel) {
|
|
221
247
|
return this.parseByPointAndVector(values[0], values[1])
|
|
222
248
|
}
|
|
223
|
-
}else if (values[0] instanceof Point && values[1] instanceof Line
|
|
224
|
-
if(values[2]===LinePropriety.Parallel || values[2]===null) {
|
|
249
|
+
} else if (values[0] instanceof Point && values[1] instanceof Line) {
|
|
250
|
+
if (values[2] === LinePropriety.Parallel || values[2] === null) {
|
|
225
251
|
return this.parseByPointAndLine(values[0], values[1], LinePropriety.Parallel)
|
|
226
|
-
}else{
|
|
252
|
+
} else {
|
|
227
253
|
return this.parseByPointAndLine(values[0], values[1], LinePropriety.Perpendicular)
|
|
228
254
|
}
|
|
229
255
|
}
|
|
@@ -338,13 +364,27 @@ export class Line {
|
|
|
338
364
|
// ------------------------------------------
|
|
339
365
|
// Mathematical operations
|
|
340
366
|
// ------------------------------------------
|
|
341
|
-
|
|
367
|
+
isOnLine = (pt: Point): Boolean => {
|
|
368
|
+
return this._a.clone()
|
|
369
|
+
.multiply(pt.x)
|
|
370
|
+
.add(
|
|
371
|
+
this._b.clone()
|
|
372
|
+
.multiply(pt.y)
|
|
373
|
+
)
|
|
374
|
+
.add(this._c)
|
|
375
|
+
.isZero()
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
isParallelTo = (line: Line): Boolean => {
|
|
342
379
|
// Do they have the isSame direction ?
|
|
343
380
|
return this.slope.isEqual(line.slope) && this.height.isNotEqual(line.height);
|
|
344
381
|
}
|
|
345
382
|
isSameAs = (line: Line): Boolean => {
|
|
346
383
|
return this.slope.isEqual(line.slope) && this.height.isEqual(line.height);
|
|
347
384
|
}
|
|
385
|
+
isPerpendicularTo = (line: Line): Boolean => {
|
|
386
|
+
return this.d.isNormalTo(line.d)
|
|
387
|
+
}
|
|
348
388
|
isVertical = (): Boolean => {
|
|
349
389
|
return this.slope.isInfinity()
|
|
350
390
|
}
|
|
@@ -388,7 +428,7 @@ export class Line {
|
|
|
388
428
|
// TODO : handle no y in the line canonical form
|
|
389
429
|
}
|
|
390
430
|
|
|
391
|
-
if (this.
|
|
431
|
+
if (this.isParallelTo(line)) {
|
|
392
432
|
Pt.x = null;
|
|
393
433
|
Pt.y = null;
|
|
394
434
|
isParallel = true;
|
|
@@ -460,20 +500,20 @@ export class Line {
|
|
|
460
500
|
return false;
|
|
461
501
|
}
|
|
462
502
|
|
|
463
|
-
getValueAtX = (value: Fraction|number): Fraction => {
|
|
503
|
+
getValueAtX = (value: Fraction | number): Fraction => {
|
|
464
504
|
const equ = this.equation.clone().isolate('y'),
|
|
465
505
|
F = new Fraction(value)
|
|
466
506
|
|
|
467
|
-
if(equ instanceof Equation){
|
|
507
|
+
if (equ instanceof Equation) {
|
|
468
508
|
return equ.right.evaluate({x: F})
|
|
469
509
|
}
|
|
470
510
|
return
|
|
471
511
|
}
|
|
472
|
-
getValueAtY = (value: Fraction|number): Fraction => {
|
|
512
|
+
getValueAtY = (value: Fraction | number): Fraction => {
|
|
473
513
|
const equ = this.equation.clone().isolate('x'),
|
|
474
514
|
F = new Fraction(value)
|
|
475
515
|
|
|
476
|
-
if(equ instanceof Equation){
|
|
516
|
+
if (equ instanceof Equation) {
|
|
477
517
|
return equ.right.evaluate({y: F})
|
|
478
518
|
}
|
|
479
519
|
return
|
|
@@ -67,6 +67,10 @@ export class Point {
|
|
|
67
67
|
return `(${pts.join(';')})`
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
get asVector(): Vector {
|
|
71
|
+
return new Vector(this.x, this.y)
|
|
72
|
+
}
|
|
73
|
+
|
|
70
74
|
// ------------------------------------------
|
|
71
75
|
// Creation / parsing functions
|
|
72
76
|
// ------------------------------------------
|
|
@@ -50,6 +50,10 @@ export class Vector {
|
|
|
50
50
|
return `\\begin{pmatrix}${this._x.tex} \\\\\ ${this._y.tex} \\end{pmatrix}`
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
get asPoint(): Point {
|
|
54
|
+
return new Point(this.x, this.y)
|
|
55
|
+
}
|
|
56
|
+
|
|
53
57
|
// ------------------------------------------
|
|
54
58
|
// Creation / parsing functions
|
|
55
59
|
// ------------------------------------------
|
|
@@ -162,13 +166,12 @@ export class Vector {
|
|
|
162
166
|
}
|
|
163
167
|
|
|
164
168
|
scalarProductWithVector = (V: Vector): Fraction => {
|
|
165
|
-
|
|
166
|
-
return this._x.clone().multiply(V.x).add(this._y.clone().multiply(V.y));
|
|
169
|
+
return Vector.scalarProduct(this, V)
|
|
170
|
+
// return this._x.clone().multiply(V.x).add(this._y.clone().multiply(V.y));
|
|
167
171
|
}
|
|
168
172
|
|
|
169
|
-
static scalarProduct = (v1: Vector, v2: Vector):
|
|
170
|
-
|
|
171
|
-
return v1.x.value * v2.x.value + v1.y.value * v2.y.value;
|
|
173
|
+
static scalarProduct = (v1: Vector, v2: Vector): Fraction => {
|
|
174
|
+
return v1.x.clone().multiply(v2.x).add(v1.y.clone().multiply(v2.y));
|
|
172
175
|
};
|
|
173
176
|
|
|
174
177
|
normal = (): Vector => {
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import {rndPolynom} from "./rndPolynom";
|
|
2
2
|
import {rndMonom} from "./rndMonom";
|
|
3
3
|
import {rndHelpers} from "./rndHelpers";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
randomCoefficientConfig,
|
|
6
|
+
randomGeometryLineConfig,
|
|
7
|
+
randomGeometryPointConfig,
|
|
8
|
+
randomMonomConfig,
|
|
9
|
+
randomPolynomConfig
|
|
10
|
+
} from "./rndTypes";
|
|
5
11
|
import {rndFraction} from "./rndFraction";
|
|
6
12
|
import {Polynom} from "../algebra/polynom";
|
|
7
13
|
import {Monom} from "../algebra/monom";
|
|
8
14
|
import {Fraction} from "../coefficients/fraction";
|
|
9
15
|
import {Line} from "../geometry/line";
|
|
10
16
|
import {rndGeometryLine} from "./rndGeometryLine";
|
|
17
|
+
import {Point} from "../geometry/point";
|
|
18
|
+
import {rndGeometryPoint} from "./rndGeometryPoint";
|
|
11
19
|
|
|
12
20
|
export * from "./rndTypes"
|
|
13
21
|
|
|
@@ -56,5 +64,10 @@ export namespace Random {
|
|
|
56
64
|
export function line(config?: randomGeometryLineConfig): Line {
|
|
57
65
|
return (new rndGeometryLine(config).generate())
|
|
58
66
|
}
|
|
67
|
+
|
|
68
|
+
export function point(config?: randomGeometryPointConfig): Point {
|
|
69
|
+
return (new rndGeometryPoint(config).generate())
|
|
70
|
+
}
|
|
71
|
+
|
|
59
72
|
}
|
|
60
73
|
}
|
|
@@ -2,7 +2,6 @@ import {randomCore} from "./randomCore";
|
|
|
2
2
|
import {Random, randomGeometryLineConfig} from "./random";
|
|
3
3
|
import {Line} from "../geometry/line";
|
|
4
4
|
import {Vector} from "../geometry/vector";
|
|
5
|
-
import {PiMath} from "../../index";
|
|
6
5
|
import {Point} from "../geometry/point";
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -34,17 +33,17 @@ export class rndGeometryLine extends randomCore {
|
|
|
34
33
|
Random.numberSym(10)
|
|
35
34
|
)
|
|
36
35
|
|
|
37
|
-
while(d.isNull){
|
|
36
|
+
while (d.isNull) {
|
|
38
37
|
d.x = Random.numberSym(10)
|
|
39
38
|
d.y = Random.numberSym(10)
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
if(this._config.slope===1){
|
|
43
|
-
if(d.x.sign()!==d.y.sign()){
|
|
41
|
+
if (this._config.slope === 1) {
|
|
42
|
+
if (d.x.sign() !== d.y.sign()) {
|
|
44
43
|
d.y.opposed()
|
|
45
44
|
}
|
|
46
|
-
}else if(this._config.slope
|
|
47
|
-
if(d.x.sign()!==d.y.sign()){
|
|
45
|
+
} else if (this._config.slope === -1) {
|
|
46
|
+
if (d.x.sign() !== d.y.sign()) {
|
|
48
47
|
d.y.opposed()
|
|
49
48
|
}
|
|
50
49
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {randomCore} from "./randomCore";
|
|
2
|
+
import {Random, randomGeometryPointConfig} from "./random";
|
|
3
|
+
import {Point} from "../geometry/point";
|
|
4
|
+
import {Fraction} from "../coefficients/fraction";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create a random monom based on a based configuration
|
|
8
|
+
*/
|
|
9
|
+
export class rndGeometryPoint extends randomCore {
|
|
10
|
+
declare protected _config: randomGeometryPointConfig
|
|
11
|
+
declare protected _defaultConfig: randomGeometryPointConfig
|
|
12
|
+
|
|
13
|
+
constructor(userConfig?: randomGeometryPointConfig) {
|
|
14
|
+
super();
|
|
15
|
+
|
|
16
|
+
this._defaultConfig = {
|
|
17
|
+
axis: true,
|
|
18
|
+
fraction: false,
|
|
19
|
+
max: 10
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
this._config = this.mergeConfig(userConfig, this._defaultConfig)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
generate = (): Point => {
|
|
26
|
+
let x: Fraction, y: Fraction,
|
|
27
|
+
zeroX = this._config.axis === true || this._config.axis === 'x',
|
|
28
|
+
zeroY = this._config.axis === true || this._config.axis === 'y'
|
|
29
|
+
|
|
30
|
+
x = this._config.fraction ?
|
|
31
|
+
Random.fraction({max: this._config.max, zero: zeroX}) :
|
|
32
|
+
new Fraction(Random.numberSym(this._config.max, zeroX))
|
|
33
|
+
|
|
34
|
+
y = this._config.fraction ?
|
|
35
|
+
Random.fraction({max: this._config.max, zero: zeroY}) :
|
|
36
|
+
new Fraction(Random.numberSym(this._config.max, zeroY))
|
|
37
|
+
|
|
38
|
+
if (+this._config.quadrant === 1) {
|
|
39
|
+
x.abs()
|
|
40
|
+
y.abs()
|
|
41
|
+
}
|
|
42
|
+
if (+this._config.quadrant === 2) {
|
|
43
|
+
if (x.isPositive()) {
|
|
44
|
+
x.opposed()
|
|
45
|
+
}
|
|
46
|
+
if (y.isNegative()) {
|
|
47
|
+
y.opposed()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (+this._config.quadrant === 3) {
|
|
51
|
+
if (x.isPositive()) {
|
|
52
|
+
x.opposed()
|
|
53
|
+
}
|
|
54
|
+
if (y.isPositive()) {
|
|
55
|
+
y.opposed()
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (+this._config.quadrant === 4) {
|
|
59
|
+
if (x.isNegative()) {
|
|
60
|
+
x.opposed()
|
|
61
|
+
}
|
|
62
|
+
if (y.isPositive()) {
|
|
63
|
+
y.opposed()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return new Point(x, y)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -27,3 +27,11 @@ export type randomGeometryLineConfig = {
|
|
|
27
27
|
A: { x: number | Fraction, y: number | Fraction },
|
|
28
28
|
slope?: Fraction | string | number,
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export type randomGeometryPointConfig = {
|
|
33
|
+
quadrant?: number,
|
|
34
|
+
axis?: string | boolean,
|
|
35
|
+
fraction?: boolean,
|
|
36
|
+
max?: number
|
|
37
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {describe} from "mocha";
|
|
2
2
|
import {Line} from "../../src/maths/geometry/line";
|
|
3
|
+
import {Point} from "../../src/maths/geometry/point";
|
|
4
|
+
import {expect} from "chai";
|
|
3
5
|
|
|
4
6
|
describe('Geometry Line', function () {
|
|
5
7
|
it('should evaluate coordinates', function () {
|
|
@@ -19,4 +21,15 @@ describe('Geometry Line', function () {
|
|
|
19
21
|
console.log(tex.parametric)
|
|
20
22
|
});
|
|
21
23
|
|
|
24
|
+
it('should parse line from canonical coefficient', function () {
|
|
25
|
+
let L = new Line(3, 2, 1)
|
|
26
|
+
|
|
27
|
+
let P1 = new Point(-2, 3),
|
|
28
|
+
P2 = new Point(-3, 4)
|
|
29
|
+
expect(L.isOnLine(P1)).to.be.false
|
|
30
|
+
expect(L.isOnLine(P2)).to.be.true
|
|
31
|
+
|
|
32
|
+
console.log(L.randomNearPoint(20).display)
|
|
33
|
+
})
|
|
34
|
+
|
|
22
35
|
});
|