math-exercises 3.0.27 → 3.0.29

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.
@@ -1 +1 @@
1
- {"version":3,"file":"pieChartReading.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/dataRepresentations/pieChartReading.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAkBT,MAAM,6BAA6B,CAAC;AAuBrC,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAoLF,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,WAAW,CAiBjD,CAAC"}
1
+ {"version":3,"file":"pieChartReading.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/dataRepresentations/pieChartReading.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAkBT,MAAM,6BAA6B,CAAC;AAuBrC,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAkLF,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,WAAW,CAiBjD,CAAC"}
@@ -56,18 +56,16 @@ const getGGBOptions = (identifiers) => {
56
56
  const angleM = angleA +
57
57
  Math.atan2(Math.sin(angleB - angleA), Math.cos(angleB - angleA)) / 2;
58
58
  return [1.2 * Math.cos(angleM), 1.2 * Math.sin(angleM)];
59
- return [
60
- (1.2 * (xA + xB)) / Math.sqrt((xA + xB) ** 2 + (yA + yB) ** 2 + 0.1),
61
- (1.2 * (yA + yB)) / Math.sqrt((xA + xB) ** 2 + (yA + yB) ** 2 + 0.1),
62
- ];
63
59
  };
64
60
  const ggb = new GeogebraConstructor({
65
61
  commands: [
66
62
  `C = Circle((0,0), 1)`,
63
+ `SetFixed(C, true)`,
67
64
  `SetLineThickness(C, 1)`,
68
65
  // ...pointsObj.flatMap((p) => p.toGGBCommand()),
69
66
  ...pointsObj.flatMap((p, i) => [
70
67
  `C_${i} = CircularSector((0,0), ${pointsObj[(i + 1 + pointsObj.length) % pointsObj.length].toMathString()}, ${p.toMathString()})`,
68
+ `SetFixed(C_${i}, true)`,
71
69
  `SetColor(C_${i}, "${colorWithOpacity(colors[i], 80)}")`,
72
70
  `SetLineThickness(C_${i}, 0)`,
73
71
  // `SetCaption(C_${i}, "$\\tiny \\text{${labels[i]}}$")`,
@@ -1,14 +1,14 @@
1
1
  import { Exercise } from "../../../../exercises/exercise.js";
2
+ import { TriangleIdentifiers } from "../../../../math/geometry/triangle.js";
2
3
  type Identifiers = {
3
- vertices: string[];
4
- xA: number;
5
- yA: number;
6
- xB: number;
7
- yB: number;
8
- xC: number;
9
- yC: number;
10
- factor: number;
4
+ ratio: number;
5
+ triangleIdentifiers: TriangleIdentifiers;
6
+ insidePointsNames: string[];
7
+ isPapillon: boolean;
11
8
  };
12
- export declare const thales: Exercise<Identifiers>;
9
+ type Options = {
10
+ configurationType: string;
11
+ };
12
+ export declare const thales: Exercise<Identifiers, Options>;
13
13
  export {};
14
14
  //# sourceMappingURL=thales.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"thales.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/geometry/thales/thales.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAQT,MAAM,6BAA6B,CAAC;AAWrC,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AA2IF,eAAO,MAAM,MAAM,EAAE,QAAQ,CAAC,WAAW,CAcxC,CAAC"}
1
+ {"version":3,"file":"thales.d.ts","sourceRoot":"","sources":["../../../../../src/exercises/math/geometry/thales/thales.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAGL,mBAAmB,EACpB,MAAM,iCAAiC,CAAC;AAuBzC,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAyFF,KAAK,OAAO,GAAG;IACb,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAoIF,eAAO,MAAM,MAAM,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAgBjD,CAAC"}
@@ -1,113 +1,176 @@
1
- import { addValidProp, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
1
+ import { GeneratorOptionTarget, GeneratorOptionType, addValidProp, tryToAddWrongProp, } from "../../../../exercises/exercise.js";
2
2
  import { getDistinctQuestions } from "../../../../exercises/utils/getDistinctQuestions.js";
3
3
  import { GeogebraConstructor } from "../../../../geogebra/geogebraConstructor.js";
4
- import { randint } from "../../../../math/utils/random/randint.js";
4
+ import { Segment } from "../../../../math/geometry/segment.js";
5
+ import { Triangle, TriangleConstructor, } from "../../../../math/geometry/triangle.js";
6
+ import { VectorConstructor } from "../../../../math/geometry/vector.js";
7
+ import { randfloat } from "../../../../math/utils/random/randfloat.js";
5
8
  import { MultiEqualNode } from "../../../../tree/nodes/equations/multiEqualNode.js";
6
- import { LengthNode } from "../../../../tree/nodes/geometry/lengthNode.js";
9
+ import { length } from "../../../../tree/nodes/geometry/lengthNode.js";
7
10
  import { FractionNode } from "../../../../tree/nodes/operators/fractionNode.js";
11
+ import { coinFlip } from "../../../../utils/alea/coinFlip.js";
8
12
  import { shuffle } from "../../../../utils/alea/shuffle.js";
9
- const getThales = () => {
10
- const vertices = [];
11
- const code = 65 + randint(0, 22); // Générer un code de caractère majuscule aléatoire (A-Z)
12
- for (let i = 0; i < 5; i++)
13
- vertices.push(String.fromCharCode(code + i));
14
- const [xA, yA] = [randint(-10, 11), randint(-10, 11)];
15
- let xB, yB, xC, yC;
16
- let d1, d2; // distance entre le point A et B
17
- let theta = 0; // angle entre AB et AC
18
- do {
19
- [xB, yB, xC, yC] = [
20
- randint(-10, 11),
21
- randint(-10, 11),
22
- randint(-10, 11),
23
- randint(-10, 11),
24
- ];
25
- d1 = Math.hypot(xB - xA, yB - yA); // Calculer la distance entre A et B
26
- d2 = Math.hypot(xC - xA, yC - yA); // Calculer la distance entre A et C
27
- theta = Math.acos(((xB - xA) * (xC - xA) + (yB - yA) * (yC - yA)) / (d1 * d2));
28
- } while (!theta ||
29
- theta < 0.35 ||
30
- theta > 2.1 ||
31
- d1 / d2 > 1.3 ||
32
- d1 / d2 < 0.7);
33
- const factor = randint(-5, 6, [-2, -1, 0, 1, 2]) / 10; // facteur = AB/AE, Pour que l'affichage soit acceptable, les valeurs de factor sont +- 0.5 0.4 0.3
34
- const [xD, yD] = [xA + factor * (xB - xA), yA + factor * (yB - yA)];
35
- const [xE, yE] = [xA + factor * (xC - xA), yA + factor * (yC - yA)];
36
- const xMin = Math.min(xA, xB, xC, xD, xE);
37
- const xMax = Math.max(xA, xB, xC, xD, xE);
38
- const yMin = Math.min(yA, yB, yC, yD, yE);
39
- const yMax = Math.max(yA, yB, yC, yD, yE);
13
+ import { randomLetter } from "../../../../utils/strings/randomLetter.js";
14
+ const getSubTriangle = ({ triangle, insidePointsNames, ratio, isPapillon, }) => {
15
+ const [A, B, C] = triangle.points;
16
+ const [dName, eName] = insidePointsNames;
17
+ const vecAC = VectorConstructor.fromPoints(A, C).times((1 - ratio).toTree());
18
+ const pointD = vecAC.getEndPoint(A, dName);
19
+ const vecBC = VectorConstructor.fromPoints(B, C).times((1 - ratio).toTree());
20
+ const pointE = vecBC.getEndPoint(B, eName);
21
+ return new Triangle([pointD, pointE, triangle.points[2]]);
22
+ };
23
+ const getInstruction = (identifiers) => {
24
+ const { triangleIdentifiers, insidePointsNames } = identifiers;
25
+ const triangle = TriangleConstructor.fromIdentifiers(triangleIdentifiers);
26
+ return `En utilisant le théoreme de Thalès, écrire l'égalité des quotients sachant que $\\left(${insidePointsNames.join("")}\\right)//\\left(${triangle.sides[2].toInsideName()}\\right)$.`;
27
+ };
28
+ const getAnswer = (identifiers) => {
29
+ const { triangleIdentifiers, insidePointsNames, isPapillon, ratio } = identifiers;
30
+ const triangle = TriangleConstructor.fromIdentifiers(triangleIdentifiers);
31
+ const subTriangle = getSubTriangle({
32
+ triangle,
33
+ insidePointsNames,
34
+ ratio,
35
+ isPapillon,
36
+ });
37
+ const answer = `\\frac{${triangle.sides[0].toInsideName()}}{${subTriangle.sides[0].toInsideName()}}=\\frac{${triangle.sides[1].toInsideName()}}{${subTriangle.sides[1].toInsideName()}}=\\frac{${triangle.sides[2].toInsideName()}}{${subTriangle.sides[2].toInsideName()}}`;
38
+ return answer;
39
+ };
40
+ const getGGBOptions = (identifiers) => {
41
+ const triangle = TriangleConstructor.fromIdentifiers(identifiers.triangleIdentifiers);
42
+ const subTriangle = getSubTriangle({
43
+ triangle,
44
+ insidePointsNames: identifiers.insidePointsNames,
45
+ ratio: identifiers.ratio,
46
+ isPapillon: identifiers.isPapillon,
47
+ });
48
+ const points = [subTriangle.points[0], subTriangle.points[1]];
49
+ const seg = new Segment(points[0], points[1]);
40
50
  const commands = [
41
- `${vertices[0]} = Point({${xA}, ${yA}})`,
42
- `${vertices[1]} = Point({${xB}, ${yB}})`,
43
- `${vertices[2]} = Point({${xC}, ${yC}})`,
44
- `${vertices[3]} = Point(${vertices[0]}, Vector(${factor}Vector(${vertices[0]},${vertices[1]})))`,
45
- `${vertices[4]} = Intersect(Line(${vertices[3]}, Line(${vertices[1]}, ${vertices[2]})) , Line(${vertices[0]}, ${vertices[2]}))`,
46
- `l = Segment(${vertices[0]}, ${vertices[1]})`,
47
- `i = Segment(${vertices[0]}, ${vertices[2]})`,
48
- `j = Segment(${vertices[1]}, ${vertices[2]})`,
49
- `k = Segment(${vertices[3]}, ${vertices[4]})`,
50
- `If(${factor} < 0, Segment(${vertices[0]}, ${vertices[3]}))`,
51
- `If(${factor} < 0, Segment(${vertices[0]}, ${vertices[4]}))`,
52
- `ShowLabel(${vertices[0]}, true)`,
53
- `ShowLabel(${vertices[1]}, true)`,
54
- `ShowLabel(${vertices[2]}, true)`,
55
- `ShowLabel(${vertices[3]}, true)`,
56
- `ShowLabel(${vertices[4]}, true)`,
51
+ ...triangle.commands,
52
+ ...points.flatMap((p) => p.toGGBCommand({ color: "#444444", size: 4 })),
53
+ ...seg.toGGBCommands(false),
57
54
  ];
58
- const answer = `\\frac{${vertices[0]}${vertices[3]}}{${vertices[0]}${vertices[1]}}=\\frac{${vertices[0]}${vertices[4]}}{${vertices[0]}${vertices[2]}}=\\frac{${vertices[3]}${vertices[4]}}{${vertices[1]}${vertices[2]}}`;
55
+ if (identifiers.isPapillon) {
56
+ commands.push(...new Segment(points[0], triangle.points[2]).toGGBCommands(false));
57
+ commands.push(...new Segment(points[1], triangle.points[2]).toGGBCommands(false));
58
+ }
59
59
  const ggb = new GeogebraConstructor({
60
60
  commands,
61
61
  hideAxes: true,
62
62
  hideGrid: true,
63
63
  });
64
+ let coords = triangle.generateCoords();
65
+ if (identifiers.isPapillon) {
66
+ const subCoords = subTriangle.generateCoords();
67
+ coords = [
68
+ Math.min(subCoords[0], coords[0]),
69
+ Math.max(subCoords[1], coords[1]),
70
+ Math.min(subCoords[2], coords[2]),
71
+ Math.max(subCoords[3], coords[3]),
72
+ ];
73
+ }
74
+ return ggb.getOptions({
75
+ coords: coords,
76
+ });
77
+ };
78
+ const options = [
79
+ {
80
+ id: "configurationType",
81
+ label: "Types de figure",
82
+ defaultValue: "Toutes",
83
+ values: ["Toutes", "Uniquement papillon", "Uniquement non papillon"],
84
+ target: GeneratorOptionTarget.generation,
85
+ type: GeneratorOptionType.select,
86
+ },
87
+ ];
88
+ const getThales = (opts) => {
89
+ const triangle = TriangleConstructor.randomNiceSides({
90
+ randomName: true,
91
+ });
92
+ const summitNames = triangle.points.map((p) => p.name);
93
+ const isPapillon = !opts || opts?.configurationType === "Toutes"
94
+ ? coinFlip()
95
+ : opts.configurationType === "Uniquement papillon"
96
+ ? true
97
+ : false;
98
+ //homothety rapport
99
+ const ratio = !isPapillon ? randfloat(0.2, 0.8, 1) : randfloat(-0.2, -0.8, 1);
100
+ // const ratio = 0.5;
101
+ const dName = randomLetter(true, summitNames);
102
+ const eName = randomLetter(true, [...summitNames, dName]);
103
+ const identifiers = {
104
+ triangleIdentifiers: triangle.toIdentifiers(),
105
+ insidePointsNames: [dName, eName],
106
+ isPapillon,
107
+ ratio,
108
+ };
64
109
  const question = {
65
- instruction: `En utilisant le théoreme de Thalès, écrire l'égalité des quotients sachant que $(${vertices[3]}${vertices[4]})//(${vertices[1]}${vertices[2]})$.`,
66
- answer,
67
- keys: [...vertices, "equal"],
68
- ggbOptions: ggb.getOptions({
69
- coords: [xMin - 1, xMax + 1, yMin - 1, yMax + 1],
70
- }),
110
+ instruction: getInstruction(identifiers),
111
+ answer: getAnswer(identifiers),
112
+ keys: [
113
+ "equal",
114
+ ...triangle.points.map((p) => p.name),
115
+ ...[dName, eName],
116
+ ],
117
+ ggbOptions: getGGBOptions(identifiers),
71
118
  answerFormat: "tex",
72
- identifiers: { vertices, xA, yA, xB, yB, xC, yC, factor },
119
+ identifiers,
73
120
  };
74
121
  return question;
75
122
  };
76
- const getPropositions = (n, { answer, vertices }) => {
123
+ const getPropositions = (n, { answer, ...identifiers }) => {
77
124
  const propositions = [];
78
- const wrongQuotients = [
79
- vertices[0] + vertices[3],
80
- vertices[0] + vertices[1],
81
- vertices[0] + vertices[4],
82
- vertices[0] + vertices[2],
83
- vertices[3] + vertices[4],
84
- vertices[1] + vertices[2],
85
- vertices[1] + vertices[3],
86
- vertices[2] + vertices[4],
125
+ const { triangleIdentifiers, insidePointsNames, isPapillon, ratio } = identifiers;
126
+ const triangle = TriangleConstructor.fromIdentifiers(triangleIdentifiers);
127
+ const subTriangle = getSubTriangle({
128
+ triangle,
129
+ insidePointsNames,
130
+ ratio,
131
+ isPapillon,
132
+ });
133
+ const lengths = [
134
+ ...triangle.sides.map((s) => s.toInsideName()),
135
+ ...subTriangle.sides.map((s) => s.toInsideName()),
87
136
  ];
88
137
  addValidProp(propositions, answer);
89
- const indexRange = Array.from({ length: 8 }, (_, i) => i);
138
+ const indexRange = Array.from({ length: 6 }, (_, i) => i);
90
139
  while (propositions.length < n) {
91
- const rands = shuffle(indexRange).slice(0, 6);
92
- tryToAddWrongProp(propositions, `\\frac{${wrongQuotients[rands[0]]}}{${wrongQuotients[rands[1]]}} =
93
- \\frac{${wrongQuotients[rands[2]]}}{${wrongQuotients[rands[3]]}} =
94
- \\frac{${wrongQuotients[rands[4]]}}{${wrongQuotients[rands[5]]}}`);
140
+ let rands = [];
141
+ do {
142
+ rands = shuffle(indexRange);
143
+ } while ((rands[0] - rands[1] === 3 &&
144
+ rands[2] - rands[3] === 3 &&
145
+ rands[4] - rands[5] === 3) ||
146
+ (rands[0] - rands[1] === -3 &&
147
+ rands[2] - rands[3] === -3 &&
148
+ rands[4] - rands[5] === -3));
149
+ //a,b,c,d,e,f
150
+ //interdire distance = 3 entre a,b c,d e,f
151
+ tryToAddWrongProp(propositions, `\\frac{${lengths[rands[0]]}}{${lengths[rands[1]]}} =
152
+ \\frac{${lengths[rands[2]]}}{${lengths[rands[3]]}} =
153
+ \\frac{${lengths[rands[4]]}}{${lengths[rands[5]]}}`);
95
154
  }
96
155
  return shuffle(propositions);
97
156
  };
98
- const isAnswerValid = (ans, { vertices }) => {
157
+ const isAnswerValid = (ans, { ...identifiers }) => {
158
+ const { triangleIdentifiers, insidePointsNames, isPapillon, ratio } = identifiers;
159
+ const triangle = TriangleConstructor.fromIdentifiers(triangleIdentifiers);
160
+ const subTriangle = getSubTriangle({
161
+ triangle,
162
+ insidePointsNames,
163
+ ratio,
164
+ isPapillon,
165
+ });
99
166
  const lengths = [
100
- new LengthNode(`${vertices[0]}${vertices[3]}`),
101
- new LengthNode(`${vertices[0]}${vertices[1]}`),
102
- new LengthNode(`${vertices[0]}${vertices[4]}`),
103
- new LengthNode(`${vertices[0]}${vertices[2]}`),
104
- new LengthNode(`${vertices[3]}${vertices[4]}`),
105
- new LengthNode(`${vertices[1]}${vertices[2]}`),
106
- ];
167
+ ...triangle.sides.map((s) => s.toInsideName()),
168
+ ...subTriangle.sides.map((s) => s.toInsideName()),
169
+ ].map((s) => length(s));
107
170
  const fractions = [
108
- new FractionNode(lengths[0], lengths[1]),
109
- new FractionNode(lengths[2], lengths[3]),
110
- new FractionNode(lengths[4], lengths[5]),
171
+ new FractionNode(lengths[0], lengths[3]),
172
+ new FractionNode(lengths[1], lengths[4]),
173
+ new FractionNode(lengths[2], lengths[5]),
111
174
  ];
112
175
  const answers = [
113
176
  new MultiEqualNode(fractions),
@@ -119,15 +182,17 @@ const isAnswerValid = (ans, { vertices }) => {
119
182
  export const thales = {
120
183
  id: "thales",
121
184
  connector: "=",
122
- label: "Ecrire l'égalité de Thalès",
123
- levels: ["5ème", "4ème", "3ème", "2nde"],
185
+ label: "Écrire l'égalité de Thalès",
124
186
  isSingleStep: false,
125
- sections: ["Théorème de Thalès", "Géométrie euclidienne"],
126
- generator: (nb) => getDistinctQuestions(getThales, nb),
187
+ generator: (nb, opts) => getDistinctQuestions(() => getThales(opts), nb),
127
188
  qcmTimer: 60,
128
189
  freeTimer: 60,
129
190
  getPropositions,
130
191
  isAnswerValid,
131
192
  hasGeogebra: true,
132
193
  subject: "Mathématiques",
194
+ getAnswer,
195
+ getInstruction,
196
+ getGGBOptions,
197
+ options,
133
198
  };
@@ -137,8 +137,8 @@ const getThalesFindSideQuestion = (opts) => {
137
137
  ? true
138
138
  : false;
139
139
  //homothety rapport
140
- // const ratio = !isPapillon ? randfloat(0.2, 0.8, 1) : randfloat(-0.2, -0.8, 1);
141
- const ratio = 0.5;
140
+ const ratio = !isPapillon ? randfloat(0.2, 0.8, 1) : randfloat(-0.2, -0.8, 1);
141
+ // const ratio = 0.5;
142
142
  const dName = randomLetter(true, summitNames);
143
143
  const eName = randomLetter(true, [...summitNames, dName]);
144
144
  const subTriangle = getSubTriangle({
package/lib/index.d.ts CHANGED
@@ -1071,15 +1071,13 @@ declare const mathExercises: (Exercise<{
1071
1071
  c: number;
1072
1072
  vertices: string[];
1073
1073
  }, {}> | Exercise<{
1074
- vertices: string[];
1075
- xA: number;
1076
- yA: number;
1077
- xB: number;
1078
- yB: number;
1079
- xC: number;
1080
- yC: number;
1081
- factor: number;
1082
- }, {}> | Exercise<{
1074
+ ratio: number;
1075
+ triangleIdentifiers: import("./math/geometry/triangle.js").TriangleIdentifiers;
1076
+ insidePointsNames: string[];
1077
+ isPapillon: boolean;
1078
+ }, {
1079
+ configurationType: string;
1080
+ }> | Exercise<{
1083
1081
  ratio: number;
1084
1082
  triangleIdentifiers: import("./math/geometry/triangle.js").TriangleIdentifiers;
1085
1083
  insidePointsNames: string[];
@@ -1971,15 +1969,13 @@ declare const pcExercises: (Exercise<{
1971
1969
  }, {
1972
1970
  isLog10: boolean;
1973
1971
  }> | Exercise<{
1974
- vertices: string[];
1975
- xA: number;
1976
- yA: number;
1977
- xB: number;
1978
- yB: number;
1979
- xC: number;
1980
- yC: number;
1981
- factor: number;
1982
- }, {}> | Exercise<{
1972
+ ratio: number;
1973
+ triangleIdentifiers: import("./math/geometry/triangle.js").TriangleIdentifiers;
1974
+ insidePointsNames: string[];
1975
+ isPapillon: boolean;
1976
+ }, {
1977
+ configurationType: string;
1978
+ }> | Exercise<{
1983
1979
  ratio: number;
1984
1980
  triangleIdentifiers: import("./math/geometry/triangle.js").TriangleIdentifiers;
1985
1981
  insidePointsNames: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"A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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAA6B,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { AlgebraicNode } from "../algebraicNode.js";
2
2
  import { Node, NodeIds, NodeOptions, NodeType } from "../node.js";
3
3
  export declare function isLengthNode(a: Node): a is LengthNode;
4
+ export declare const length: (a: string) => LengthNode;
4
5
  export declare class LengthNode implements AlgebraicNode {
5
6
  opts?: NodeOptions | undefined;
6
7
  segmentName: string;
@@ -17,7 +18,7 @@ export declare class LengthNode implements AlgebraicNode {
17
18
  toMathjs(): string;
18
19
  toTex(): string;
19
20
  evaluate(vars?: Record<string, number>): number;
20
- simplify(): this;
21
+ simplify(): LengthNode;
21
22
  equals(node: AlgebraicNode): boolean;
22
23
  toDetailedEvaluation(vars: Record<string, AlgebraicNode>): this;
23
24
  derivative(varName?: string | undefined): AlgebraicNode;
@@ -1 +1 @@
1
- {"version":3,"file":"lengthNode.d.ts","sourceRoot":"","sources":["../../../../src/tree/nodes/geometry/lengthNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAClE,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,UAAU,CAErD;AACD,qBAAa,UAAW,YAAW,aAAa;IAC9C,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;gBACP,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW;IAUnD,cAAc;IAGd,aAAa;;;;IAMb,iBAAiB,CAAC,IAAI,CAAC,EAAE,W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E,MAAM,GAAG,SAAS,GAAG,aAAa;CAGxD"}
@@ -2,6 +2,9 @@ import { NodeIds, NodeType } from "../node.js";
2
2
  export function isLengthNode(a) {
3
3
  return a.type === NodeType.mesure;
4
4
  }
5
+ export const length = (a) => {
6
+ return new LengthNode(a);
7
+ };
5
8
  export class LengthNode {
6
9
  opts;
7
10
  segmentName;
@@ -48,7 +51,10 @@ export class LengthNode {
48
51
  return value;
49
52
  }
50
53
  simplify() {
51
- return this;
54
+ const isAlphabeticallyOrdered = (str) => [...str].every((c, i, arr) => i === 0 || arr[i - 1] <= c);
55
+ return isAlphabeticallyOrdered(this.segmentName)
56
+ ? this
57
+ : new LengthNode(this.segmentName.split("").reverse().join(""));
52
58
  }
53
59
  equals(node) {
54
60
  return isLengthNode(node) && node.segmentName === this.segmentName;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "math-exercises",
3
3
  "type": "module",
4
- "version": "3.0.27",
4
+ "version": "3.0.29",
5
5
  "description": "Math exercises generator for middle school and high school",
6
6
  "main": "lib/index.js",
7
7
  "files": [