Skip to content

Commit 10c2040

Browse files
committed
Completely obliterated MathAtomType from existence
1 parent e12b4c4 commit 10c2040

File tree

94 files changed

+990
-1266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+990
-1266
lines changed

CSharpMath.Apple/AppleMathView.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
using CSharpMath.Atoms;
12
using CSharpMath.Display;
2-
using CSharpMath.Enumerations;
33
using CSharpMath.FrontEnd;
4-
using CSharpMath.Atoms;
54
using CoreGraphics;
65
using UIKit;
76
using TGlyph = System.UInt16;

CSharpMath.Apple/Typesetting/JsonMathTable.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ public override float RadicalExtraAscender(TFont font) =>
133133
private const string _startConnectorKey = "startConnector";
134134
private const string _extenderKey = "extender";
135135
private const string _glyphKey = "glyph";
136-
public override IEnumerable<GlyphPart<TGlyph>> GetVerticalGlyphAssembly(TGlyph rawGlyph, TFont font) =>
136+
public override IEnumerable<Display.Text.GlyphPart<TGlyph>> GetVerticalGlyphAssembly
137+
(TGlyph rawGlyph, TFont font) =>
137138
_assemblyTable[GlyphNameProvider.GetGlyphName(rawGlyph)]?[_assemblyPartsKey] is JArray parts
138139
? parts.Select(partInfo =>
139-
new GlyphPart<TGlyph>(
140+
new Display.Text.GlyphPart<TGlyph>(
140141
GlyphNameProvider.GetGlyph(partInfo[_glyphKey].Value<string>()),
141142
FontUnitsToPt(font, partInfo[_advanceKey].Value<int>()),
142143
FontUnitsToPt(font, partInfo[_startConnectorKey].Value<int>()),

CSharpMath.Editor.Tests/IndexForPointTests.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Drawing;
22
using CSharpMath.Atoms;
3-
using CSharpMath.Enumerations;
43
using CSharpMath.Tests.FrontEnd;
54
using Xunit;
65

CSharpMath.Editor/Extensions/IDisplay.cs

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
using System;
2-
using System.Collections.Generic;
31
using System.Drawing;
4-
using System.Text;
52

63
namespace CSharpMath.Editor {
7-
using Range = Atoms.Range;
84
using Display;
5+
using Display.Text;
96

107
public static partial class DisplayEditingExtensions {
11-
///<summary>Number of pixels outside the bound to allow a point to be considered as part of the bounds.</summary>
8+
/// <summary>
9+
/// Number of pixels outside the bound to allow a point to be considered as part of the bounds.
10+
/// </summary>
1211
public const float PixelDelta = 2;
1312

14-
///<summary>Calculates the manhattan distance from a point to the nearest boundary of the rectangle.</summary>
13+
/// <summary>
14+
/// Calculates the manhattan distance from a point to the nearest boundary of the rectangle.
15+
/// </summary>
1516
public static float DistanceFromPointToRect(PointF point, RectangleF rect) {
1617
float distance = 0;
1718
if (point.X < rect.X)
@@ -27,9 +28,9 @@ public static float DistanceFromPointToRect(PointF point, RectangleF rect) {
2728
}
2829

2930
/// <summary>
30-
/// Finds the index in the mathlist before which a new character should be inserted.Returns null if it cannot find the index.
31+
/// Finds the index in the mathlist before which a new character should be inserted.
32+
/// Returns null if it cannot find the index.
3133
/// </summary>
32-
/// <returns>Null if it cannot find the index.</returns>
3334
public static MathListIndex? IndexForPoint<TFont, TGlyph>(
3435
this IDisplay<TFont, TGlyph> display,
3536
FrontEnd.TypesettingContext<TFont, TGlyph> context, PointF point)
@@ -52,7 +53,9 @@ public static float DistanceFromPointToRect(PointF point, RectangleF rect) {
5253
ListDisplay<TFont, TGlyph> list => list.PointForIndex(context, index),
5354
_ => null,
5455
};
55-
public static void HighlightCharacterAt<TFont, TGlyph>(this IDisplay<TFont, TGlyph> display, MathListIndex index, Structures.Color color) where TFont : IFont<TGlyph> {
56+
public static void HighlightCharacterAt<TFont, TGlyph>
57+
(this IDisplay<TFont, TGlyph> display, MathListIndex index, Structures.Color color)
58+
where TFont : IFont<TGlyph> {
5659
switch (display) {
5760
case TextLineDisplay<TFont, TGlyph> text:
5861
text.HighlightCharacterAt(index, color);
@@ -70,7 +73,8 @@ public static void HighlightCharacterAt<TFont, TGlyph>(this IDisplay<TFont, TGly
7073
break;
7174
}
7275
}
73-
public static void Highlight<TFont, TGlyph>(this IDisplay<TFont, TGlyph> display, Structures.Color color) where TFont : IFont<TGlyph> {
76+
public static void Highlight<TFont, TGlyph>(this IDisplay<TFont, TGlyph> display, Structures.Color color)
77+
where TFont : IFont<TGlyph> {
7478
switch (display) {
7579
case TextLineDisplay<TFont, TGlyph> text:
7680
text.Highlight(color);

CSharpMath.Editor/Extensions/ListDisplay.cs

+24-15
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ partial class DisplayEditingExtensions {
3838
: MathListIndex.Level0Index(self.Range.Location);
3939
else if (translatedPoint.X >= self.Width + PixelDelta) {
4040
// if closest is a script
41-
if (closest != null && closest is ListDisplay<TFont, TGlyph> ld
42-
&& ld.LinePosition != Enumerations.LinePosition.Regular) {
41+
if (closest is ListDisplay<TFont, TGlyph> ld && ld.LinePosition != LinePosition.Regular) {
4342
// then we try to find its parent
4443
var parent = self.Displays.FirstOrDefault(d => d.HasScript && d.Range.Contains(ld.IndexInParent));
4544
if (parent != null) {
@@ -73,20 +72,27 @@ partial class DisplayEditingExtensions {
7372

7473
var index = displayWithPoint.IndexForPoint(context, translatedPoint);
7574
if (displayWithPoint is ListDisplay<TFont, TGlyph> closestLine) {
76-
if (closestLine.LinePosition is Enumerations.LinePosition.Regular)
77-
throw new ArgumentException(
78-
$"{nameof(ListDisplay<TFont, TGlyph>)} {nameof(ListDisplay<TFont, TGlyph>.LinePosition)} {nameof(Enumerations.LinePosition.Regular)} " +
75+
if (closestLine.LinePosition is LinePosition.Regular)
76+
throw new ArgumentException(nameof(ListDisplay<TFont, TGlyph>) + " " +
77+
nameof(ListDisplay<TFont, TGlyph>.LinePosition) + " " + nameof(LinePosition.Regular) + " " +
7978
$"inside an {nameof(ListDisplay<TFont, TGlyph>)} - shouldn't happen", nameof(self));
8079
// This is a subscript or a superscript, return the right type of subindex
81-
var indexType = closestLine.LinePosition is Enumerations.LinePosition.Subscript ? MathListSubIndexType.Subscript : MathListSubIndexType.Superscript;
80+
var indexType =
81+
closestLine.LinePosition is LinePosition.Subscript
82+
? MathListSubIndexType.Subscript
83+
: MathListSubIndexType.Superscript;
8284
// The index of the atom this denotes.
8385
if (closestLine.IndexInParent is int.MinValue)
84-
throw new ArgumentException($"Index was not set for a {indexType} in the {nameof(ListDisplay<TFont, TGlyph>)}.", nameof(self));
86+
throw new ArgumentException
87+
($"Index was not set for a {indexType} in the {nameof(ListDisplay<TFont, TGlyph>)}.", nameof(self));
8588
return MathListIndex.IndexAtLocation(closestLine.IndexInParent, indexType, index);
8689
} else if (displayWithPoint.HasScript)
87-
//The display list has a subscript or a superscript. If the index is at the end of the atom, then we need to put it before the sub/super script rather than after.
90+
// The display list has a subscript or a superscript.
91+
// If the index is at the end of the atom,
92+
// then we need to put it before the sub/super script rather than after.
8893
if (index?.AtomIndex == displayWithPoint.Range.End)
89-
return MathListIndex.IndexAtLocation(index.AtomIndex - 1, MathListSubIndexType.BetweenBaseAndScripts, MathListIndex.Level0Index(1));
94+
return MathListIndex.IndexAtLocation
95+
(index.AtomIndex - 1, MathListSubIndexType.BetweenBaseAndScripts, MathListIndex.Level0Index(1));
9096
return index;
9197
}
9298

@@ -126,8 +132,10 @@ partial class DisplayEditingExtensions {
126132
return null;
127133
}
128134

129-
public static void HighlightCharacterAt<TFont, TGlyph>(this ListDisplay<TFont, TGlyph> self, MathListIndex index, Color color) where TFont : IFont<TGlyph> {
130-
if (self.Range.Contains(index.AtomIndex) && self.SubDisplayForIndex(index) is IDisplay<TFont, TGlyph> display)
135+
public static void HighlightCharacterAt<TFont, TGlyph>(this ListDisplay<TFont, TGlyph> self,
136+
MathListIndex index, Color color) where TFont : IFont<TGlyph> {
137+
if (self.Range.Contains(index.AtomIndex)
138+
&& self.SubDisplayForIndex(index) is IDisplay<TFont, TGlyph> display)
131139
if (index.SubIndexType is MathListSubIndexType.BetweenBaseAndScripts
132140
|| index.SubIndexType is MathListSubIndexType.None)
133141
display.HighlightCharacterAt(index, color);
@@ -151,9 +159,9 @@ public static void Highlight<TFont, TGlyph>(this ListDisplay<TFont, TGlyph> self
151159
&& index.AtomIndex == list.IndexInParent
152160
// This is the right character for the sub/superscript, check that it's type matches the index
153161
&&
154-
(list.LinePosition is Enumerations.LinePosition.Subscript
162+
(list.LinePosition is LinePosition.Subscript
155163
&& index.SubIndexType is MathListSubIndexType.Subscript
156-
|| list.LinePosition is Enumerations.LinePosition.Superscript
164+
|| list.LinePosition is LinePosition.Superscript
157165
&& index.SubIndexType is MathListSubIndexType.Superscript))
158166
return list;
159167
else { }
@@ -178,9 +186,10 @@ public static void Highlight<TFont, TGlyph>(this ListDisplay<TFont, TGlyph> self
178186
case MathListSubIndexType.Superscript:
179187
case MathListSubIndexType.Subscript:
180188
default:
181-
throw new InvalidCodePathException("Superscripts and subscripts should have been handled in a separate case above.");
189+
throw new InvalidCodePathException
190+
("Superscripts and subscripts should have been handled in a separate case above.");
182191
}
183192
return null;
184193
}
185194
}
186-
}
195+
}

CSharpMath.Editor/Extensions/MathList.cs

+15-18
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ static void InsertAtAtomIndexAndAdvance(this MathList self, int atomIndex, MathA
1010
if (atomIndex < 0 || atomIndex > self.Count)
1111
throw new IndexOutOfRangeException($"Index {atomIndex} is out of bounds for list of size {self.Atoms.Count}");
1212
// Test for placeholder to the right of index, e.g. \sqrt{‸■} -> \sqrt{2‸}
13-
if (atomIndex < self.Count && self[atomIndex] is MathAtom placeholder &&
14-
placeholder?.AtomType is Enumerations.MathAtomType.Placeholder) {
13+
if (atomIndex < self.Count && self[atomIndex] is Atom.Placeholder placeholder) {
1514
if (placeholder.Superscript is MathList super) {
1615
if (atom.Superscript != null) super.Append(atom.Superscript);
1716
atom.Superscript = super;
@@ -57,7 +56,7 @@ public static void InsertAndAdvance(this MathList self, ref MathListIndex index,
5756
break;
5857
case MathListSubIndexType.Degree:
5958
case MathListSubIndexType.Radicand:
60-
if (!(self.Atoms[index.AtomIndex] is Atom.Radical radical && radical.AtomType == Enumerations.MathAtomType.Radical))
59+
if (!(self.Atoms[index.AtomIndex] is Atom.Radical radical))
6160
throw new SubIndexTypeMismatchException(typeof(Atom.Radical), index);
6261
if (index.SubIndexType == MathListSubIndexType.Degree)
6362
if (radical.Degree is null) throw new SubIndexTypeMismatchException(index);
@@ -66,8 +65,7 @@ public static void InsertAndAdvance(this MathList self, ref MathListIndex index,
6665
break;
6766
case MathListSubIndexType.Numerator:
6867
case MathListSubIndexType.Denominator:
69-
if (!(self.Atoms[index.AtomIndex] is Atom.Fraction frac
70-
&& frac.AtomType == Enumerations.MathAtomType.Fraction))
68+
if (!(self.Atoms[index.AtomIndex] is Atom.Fraction frac))
7169
throw new SubIndexTypeMismatchException(typeof(Atom.Fraction), index);
7270
if (index.SubIndexType == MathListSubIndexType.Numerator)
7371
if (frac.Numerator is null)
@@ -113,12 +111,12 @@ public static void RemoveAt(this MathList self, ref MathListIndex index) {
113111
self.Atoms[index.AtomIndex - 1] is MathAtom previous &&
114112
previous.Subscript is null &&
115113
previous.Superscript is null &&
116-
previous.AtomType switch {
117-
Enumerations.MathAtomType.BinaryOperator => false,
118-
Enumerations.MathAtomType.UnaryOperator => false,
119-
Enumerations.MathAtomType.Relation => false,
120-
Enumerations.MathAtomType.Punctuation => false,
121-
Enumerations.MathAtomType.Space => false,
114+
previous switch {
115+
Atom.BinaryOperator _ => false,
116+
Atom.UnaryOperator _ => false,
117+
Atom.Relation _ => false,
118+
Atom.Punctuation _ => false,
119+
Atom.Space _ => false,
122120
_ => true
123121
}) {
124122
previous.Superscript = currentAtom.Superscript;
@@ -141,8 +139,7 @@ previous.Superscript is null &&
141139
return;
142140
case MathListSubIndexType.Radicand:
143141
case MathListSubIndexType.Degree:
144-
if (!(self.Atoms[index.AtomIndex] is Atom.Radical radical
145-
&& radical.AtomType == Enumerations.MathAtomType.Radical))
142+
if (!(self.Atoms[index.AtomIndex] is Atom.Radical radical))
146143
throw new SubIndexTypeMismatchException(typeof(Atom.Radical), index);
147144
if (index.SubIndexType == MathListSubIndexType.Degree)
148145
if (radical.Degree is null) throw new SubIndexTypeMismatchException(index);
@@ -151,7 +148,7 @@ previous.Superscript is null &&
151148
break;
152149
case MathListSubIndexType.Numerator:
153150
case MathListSubIndexType.Denominator:
154-
if (!(self.Atoms[index.AtomIndex] is Atom.Fraction frac && frac.AtomType == Enumerations.MathAtomType.Fraction))
151+
if (!(self.Atoms[index.AtomIndex] is Atom.Fraction frac))
155152
throw new SubIndexTypeMismatchException(typeof(Atom.Fraction), index);
156153
if (index.SubIndexType == MathListSubIndexType.Numerator)
157154
if (frac.Numerator is null) throw new SubIndexTypeMismatchException(index);
@@ -196,7 +193,7 @@ public static void RemoveAtoms(this MathList self, MathListRange? nullableRange)
196193
throw new NotSupportedException("Nuclear fission is not supported");
197194
case MathListSubIndexType.Radicand:
198195
case MathListSubIndexType.Degree:
199-
if (!(self.Atoms[start.AtomIndex] is Atom.Radical radical && radical.AtomType == Enumerations.MathAtomType.Radical))
196+
if (!(self.Atoms[start.AtomIndex] is Atom.Radical radical))
200197
throw new SubIndexTypeMismatchException(typeof(Atom.Radical), start);
201198
if (start.SubIndexType == MathListSubIndexType.Degree)
202199
if (radical.Degree is null)
@@ -206,7 +203,7 @@ public static void RemoveAtoms(this MathList self, MathListRange? nullableRange)
206203
break;
207204
case MathListSubIndexType.Numerator:
208205
case MathListSubIndexType.Denominator:
209-
if (!(self.Atoms[start.AtomIndex] is Atom.Fraction frac && frac.AtomType == Enumerations.MathAtomType.Fraction))
206+
if (!(self.Atoms[start.AtomIndex] is Atom.Fraction frac))
210207
throw new SubIndexTypeMismatchException(typeof(Atom.Fraction), start);
211208
if (start.SubIndexType == MathListSubIndexType.Numerator)
212209
if (frac.Numerator is null) throw new SubIndexTypeMismatchException(start);
@@ -244,15 +241,15 @@ public static void RemoveAtoms(this MathList self, MathListRange? nullableRange)
244241
case MathListSubIndexType.Radicand:
245242
case MathListSubIndexType.Degree:
246243
return
247-
atom is Atom.Radical radical && radical.AtomType == Enumerations.MathAtomType.Radical
244+
atom is Atom.Radical radical
248245
? index.SubIndexType == MathListSubIndexType.Degree
249246
? radical.Degree?.AtomAt(index.SubIndex)
250247
: radical.Radicand?.AtomAt(index.SubIndex)
251248
: null;
252249
case MathListSubIndexType.Numerator:
253250
case MathListSubIndexType.Denominator:
254251
return
255-
atom is Atom.Fraction frac && frac.AtomType == Enumerations.MathAtomType.Fraction
252+
atom is Atom.Fraction frac
256253
? index.SubIndexType == MathListSubIndexType.Denominator
257254
? frac.Denominator?.AtomAt(index.SubIndex)
258255
: frac.Numerator?.AtomAt(index.SubIndex)

0 commit comments

Comments
 (0)