mirror of
https://github.com/ArthurSonzogni/Diagon.git
synced 2026-08-29 08:34:44 +08:00
Optimize output with mixed pow/subscript.
This fixes: https://github.com/ArthurSonzogni/Diagon/issues/1
This commit is contained in:
@@ -150,6 +150,19 @@ Draw ComposeDiagonalDown(const Draw& A, const Draw& B) {
|
||||
return composition;
|
||||
}
|
||||
|
||||
// Useful for x_a^b
|
||||
Draw ComposeDiagonalUpAndDown(const Draw& A, const Draw& B, const Draw& C) {
|
||||
Draw composition;
|
||||
composition.Append(B, A.dim_x, 0);
|
||||
composition.Append(A, 0, B.dim_y);
|
||||
composition.Append(C, A.dim_x, B.dim_y + A.dim_y);
|
||||
|
||||
composition.center_x = composition.dim_x / 2;
|
||||
composition.center_y = A.center_y + B.dim_y;
|
||||
|
||||
return composition;
|
||||
}
|
||||
|
||||
Draw WrapWithParenthesis(const Draw& element, Style* style) {
|
||||
Draw draw;
|
||||
draw.Resize(element.dim_x + 2, element.dim_y);
|
||||
@@ -340,6 +353,21 @@ Draw Parse(MathParser::FactorContext* context,
|
||||
bool suppress_parenthesis) {
|
||||
suppress_parenthesis &= (context->valueBang().size() == 1);
|
||||
Draw draw = Parse(context->valueBang(0), style, suppress_parenthesis);
|
||||
|
||||
// Optimization for a_b^c and a^c:
|
||||
if (context->valueBang().size() == 3) {
|
||||
if (context->powop(0)->POW() && context->powop(1)->SUBSCRIPT()) {
|
||||
return ComposeDiagonalUpAndDown(
|
||||
draw, Parse(context->valueBang(1), style, false),
|
||||
Parse(context->valueBang(2), style, false));
|
||||
}
|
||||
if (context->powop(1)->POW() && context->powop(0)->SUBSCRIPT()) {
|
||||
return ComposeDiagonalUpAndDown(
|
||||
draw, Parse(context->valueBang(2), style, false),
|
||||
Parse(context->valueBang(1), style, false));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < context->valueBang().size(); ++i) {
|
||||
auto* compose =
|
||||
context->powop(i - 1)->POW() ? ComposeDiagonalUp : ComposeDiagonalDown;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
3
|
||||
A
|
||||
2
|
||||
|
||||
2
|
||||
A
|
||||
3
|
||||
3
|
||||
A
|
||||
2
|
||||
|
||||
2
|
||||
A
|
||||
3
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
3
|
||||
A
|
||||
2
|
||||
|
||||
2
|
||||
A
|
||||
3
|
||||
3
|
||||
A
|
||||
2
|
||||
|
||||
2
|
||||
A
|
||||
3
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
A_\left(1 + 2\right) \\
|
||||
A_{\left(1 + 2\right)} \\
|
||||
\\
|
||||
A_1 + 2 \\
|
||||
A_{1 + 2} \\
|
||||
\\
|
||||
A^\left(1 + 2\right) \\
|
||||
A^{\left(1 + 2\right)} \\
|
||||
\\
|
||||
A^1 + 2
|
||||
A^{1 + 2}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
\int_{b}^{c} a \\
|
||||
\\
|
||||
\int_{x = 1}^{100} x^2 \\
|
||||
\int_{x = 1}^{100} x^{2} \\
|
||||
\\
|
||||
\int_{x = 1}^{100} \frac{1}{2} \\
|
||||
\\
|
||||
\int_{x = 1}^{100} \frac{x^2}{2} \\
|
||||
\int_{x = 1}^{100} \frac{x^{2}}{2} \\
|
||||
\\
|
||||
\int_{bbbbbbbbbbbb}^{c} a \\
|
||||
\\
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
A_2^3 \\
|
||||
A_{2}^{3} \\
|
||||
\\
|
||||
A^2_3
|
||||
A^{2}_{3}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
A^2 \\
|
||||
A^{2} \\
|
||||
\\
|
||||
A^\left(\frac{1}{2}\right)^\sqrt{2} \\
|
||||
A^{\left(\frac{1}{2}\right)}^{\sqrt{2}} \\
|
||||
\\
|
||||
\left(A^\left(\frac{1}{2}\right)\right)^\sqrt{2} \\
|
||||
\left(A^{\left(\frac{1}{2}\right)}\right)^{\sqrt{2}} \\
|
||||
\\
|
||||
A^\left(\left(\frac{1}{2}\right)^\sqrt{2}\right) \\
|
||||
A^{\left(\left(\frac{1}{2}\right)^{\sqrt{2}}\right)} \\
|
||||
\\
|
||||
A^421 + \frac{1}{2} \\
|
||||
A^{421} + \frac{1}{2} \\
|
||||
\\
|
||||
\frac{A^421}{2}
|
||||
\frac{A^{421}}{2}
|
||||
|
||||
@@ -1 +1 @@
|
||||
speed = \sqrt{\left(\frac{df}{dx}\right)^2 + \left(\frac{df}{dy}\right)^2}
|
||||
speed = \sqrt{\left(\frac{df}{dx}\right)^{2} + \left(\frac{df}{dy}\right)^{2}}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"hello world" \\
|
||||
\\
|
||||
"A_B"_"C_D" \\
|
||||
"A_B"_{"C_D"} \\
|
||||
\\
|
||||
"" \\
|
||||
\\
|
||||
1^"2^3"^4
|
||||
1^{"2^3"}^{4}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
A_2 \\
|
||||
A_{2} \\
|
||||
\\
|
||||
A_\left(\frac{1}{2}\right)_\sqrt{2} \\
|
||||
A_{\left(\frac{1}{2}\right)}_{\sqrt{2}} \\
|
||||
\\
|
||||
\left(A_\left(\frac{1}{2}\right)\right)_\sqrt{2} \\
|
||||
\left(A_{\left(\frac{1}{2}\right)}\right)_{\sqrt{2}} \\
|
||||
\\
|
||||
A_\left(\left(\frac{1}{2}\right)_\sqrt{2}\right) \\
|
||||
A_{\left(\left(\frac{1}{2}\right)_{\sqrt{2}}\right)} \\
|
||||
\\
|
||||
A_421 + \frac{1}{2} \\
|
||||
A_{421} + \frac{1}{2} \\
|
||||
\\
|
||||
\frac{A_421}{2}
|
||||
\frac{A_{421}}{2}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
\sum_{b}^{c} a \\
|
||||
\\
|
||||
\sum_{x = 1}^{100} x^2 \\
|
||||
\sum_{x = 1}^{100} x^{2} \\
|
||||
\\
|
||||
\sum_{x = 1}^{100} \frac{1}{2} \\
|
||||
\\
|
||||
\sum_{x = 1}^{100} \frac{x^2}{2} \\
|
||||
\sum_{x = 1}^{100} \frac{x^{2}}{2} \\
|
||||
\\
|
||||
\sum_{bbbbbbbbbbbb}^{c} a \\
|
||||
\\
|
||||
|
||||
@@ -4,7 +4,7 @@ f'\left(x\right) \\
|
||||
\\
|
||||
a123456789°à@çè|#~#& \\
|
||||
\\
|
||||
2_2m \\
|
||||
2_{2m} \\
|
||||
\\
|
||||
2é8fsdmoiuuç \\
|
||||
\\
|
||||
|
||||
Reference in New Issue
Block a user