Skip to content

Commit dd6c3b2

Browse files
committed
normalize line segment arg order when compare
1 parent 8b24d71 commit dd6c3b2

File tree

8 files changed

+21
-11
lines changed

8 files changed

+21
-11
lines changed

build/math-expressions.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/math-expressions_umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/expression/equality.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ const equals = function (expr, other, {
2525
let exprNormalized = expr.evaluate_numbers({ max_digits: Infinity })
2626
.normalize_function_names()
2727
.normalize_applied_functions()
28-
.normalize_angle_arg_order()
28+
.normalize_angle_linesegment_arg_order()
2929
.remove_scaling_units()
3030
.simplify();
3131
let otherNormalized = other.evaluate_numbers({ max_digits: Infinity })
3232
.normalize_function_names()
3333
.normalize_applied_functions()
34-
.normalize_angle_arg_order()
34+
.normalize_angle_linesegment_arg_order()
3535
.remove_scaling_units()
3636
.simplify();
3737

lib/expression/equality/syntax.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ export const equals = function (expr, other, {
1414
let exprNormalized = expr
1515
.normalize_function_names()
1616
.normalize_applied_functions()
17-
.normalize_angle_arg_order();
17+
.normalize_angle_linesegment_arg_order();
1818
let otherNormalized = other
1919
.normalize_function_names()
2020
.normalize_applied_functions()
21-
.normalize_angle_arg_order();
21+
.normalize_angle_linesegment_arg_order();
2222

2323
return tree_equal(exprNormalized.tree, otherNormalized.tree, {
2424
allowed_error_in_numbers: allowed_error_in_numbers,

lib/expression/normalization/standard_form.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function constants_to_floats(expr_or_tree) {
223223

224224
}
225225

226-
function normalize_angle_arg_order(expr_or_tree) {
226+
function normalize_angle_linesegment_arg_order(expr_or_tree) {
227227
var tree = get_tree(expr_or_tree);
228228

229229
if (!Array.isArray(tree)) {
@@ -237,11 +237,17 @@ function normalize_angle_arg_order(expr_or_tree) {
237237
operands.reverse();
238238
return [operator, ...operands];
239239
}
240+
241+
if(operator === "linesegment" && operands.length === 2 && compare_function(operands[0], operands[1]) === 1) {
242+
operands.reverse();
243+
return [operator, ...operands];
244+
}
245+
240246
return tree;
241247
}
242248

243249
export {
244250
normalize_function_names, normalize_applied_functions, log_subscript_to_two_arg_log,
245251
substitute_abs, default_order, constants_to_floats,
246-
normalize_angle_arg_order
252+
normalize_angle_linesegment_arg_order
247253
};

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "math-expressions",
33
"description": "Perform basic equality testing and symbolic computations on mathematical expressions involving transcendental functions",
4-
"version": "2.0.0-alpha57",
4+
"version": "2.0.0-alpha58",
55
"author": {
66
"name": "Jim Fowler",
77
"email": "[email protected]",

spec/slow_math-expressions.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ describe("expression", function () {
376376
['x++--y', 'x+y'],
377377
['x--y', 'x+y'],
378378
['∠ABC', '∠CBA'],
379+
['linesegment(A,B)', 'linesegment(B,A)'],
379380
['$5', '$3+$2'],
380381
['$5', '$9-$4'],
381382
['$xy+a$b', '$(xy+ab)'],
@@ -487,6 +488,7 @@ describe("expression", function () {
487488
['log^2(x)', 'log(x)^2'],
488489
['ln^2(x)', 'ln(x)^2'],
489490
['∠ABC', '∠ACB'],
491+
['linesegment(A,B)', 'linesegment(A,C)'],
490492
['$5', '5'],
491493
['$x', 'x'],
492494
['∫_a^b xdx', '∫_(2a)^b xdx'],
@@ -635,6 +637,7 @@ describe("expression", function () {
635637
["f'''(x)", "f(x)'''"],
636638
['x+-y', 'x-y'],
637639
['∠ABC', '∠CBA'],
640+
['linesegment(A,B)', 'linesegment(B,A)'],
638641
];
639642

640643
_.each(symbolic_equivalences, function (equiv) {
@@ -839,6 +842,7 @@ describe("expression", function () {
839842
['x++--y', 'x+y'],
840843
['x--y', 'x+y'],
841844
['∠ABC', '∠ACB'],
845+
['linesegment(A,B)', 'linesegment(A,C)'],
842846
['50%', '1/2'],
843847
['180 deg', 'pi'],
844848
['x ∈ A', 'A ∋ x'],

0 commit comments

Comments
 (0)