-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Tidy MathListIndex #159
base: master
Are you sure you want to change the base?
Conversation
Yes. |
Getting errors I'm having trouble diagnosing. Inputs: 1, power, 2 Debug code gives:
I have the feeling it's to do with mutability and the static void InsertAtAtomIndexAndAdvance(this MathList self, int atomIndex, MathAtom atom, ref MathListIndex advance Independently of getting this PR working, it's good to remove the Once this PR goes in and the immutable change we will have a clean base to work on #117 . Any thoughts @Happypig375 ? |
@@ -19,11 +19,11 @@ dotnet_sort_system_directives_first = true | |||
# C# formatting settings | |||
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#c-formatting-settings | |||
csharp_new_line_before_catch = false | |||
csharp_new_line_before_else = false | |||
#csharp_new_line_before_else = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
csharp_new_line_before_finally = false | ||
csharp_new_line_before_members_in_object_initializers = false | ||
csharp_new_line_before_members_in_anonymous_types = false | ||
csharp_new_line_before_open_brace = none | ||
#csharp_new_line_before_open_brace = none |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
case MathListSubIndexType.Superscript: | ||
self.Atoms[index.AtomIndex].Superscript.InsertAndAdvance(ref index.SubIndex, atom, advanceType); | ||
case (MathListSubIndexType.Superscript, MathListIndex subIndex): | ||
self.Atoms[index.AtomIndex].Superscript.InsertAndAdvance(ref subIndex, atom, advanceType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ref now mutates the local instead of the index. Same below.
Array.IndexOf(typeof(MathListSubIndexType).GetEnumValues(), index.SubIndexType) == -1 | ||
? $"{index.SubIndexType} is an invalid subindex type." | ||
: $"{index.SubIndexType} not found at index {index.AtomIndex}.") { } | ||
Array.IndexOf(typeof(MathListSubIndexType).GetEnumValues(), index.SubIndexInfo!.Value.SubIndexType) == -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exception will appear when SubIndexInfo is null
<packageSources> | ||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> | ||
</packageSources> | ||
</configuration> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
|
||
/// <summary>Factory function to create a `MathListIndex` with no subindexes.</summary> | ||
/// <param name="index">The index of the atom that the `MathListIndex` points at.</param> | ||
public static MathListIndex Level0Index(int index) => new MathListIndex(index, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be made into a default parameter of constructor
I don't think removing refs can be independent of this PR. Currently InsertAtAtomIndexAndAdvance advances the advance parameter and now that behaviour is gone, hence test failures. |
return self.InsertAtAtomIndexAndAdvance(atomIndex, atom, advanceType); | ||
case (MathListSubIndexType type, MathListIndex subIndex): | ||
switch (type) { | ||
case MathListSubIndexType.BetweenBaseAndScripts: // TODO: finish this section |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand this case. The docs on BetweenBaseAndScripts
has The position in the subindex is an index into the nucleus, must be 1
and I don't understand that exactly. Could you help with this part @Happypig375 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AtomIndex of the SubIndex must be 1 for SubIndexType BetweenBaseAndScripts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got that far...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 12^3
, is there a MathListIndex of 2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The right boundary of the whole MathList. (for insertions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the MathListIndex of 2 in 12^3
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The right boundary of the whole MathList. (for insertions)
Cursor position | MathListIndex |
---|---|
‸12^3 | 0 |
1‸2^3 | 1 |
12‸^3 | 1, BetweenBaseAndScripts:1 |
12^‸3 | 1, Superscript:0 |
12^3‸ | 1, Superscript:1 (to the right of 3) OR 2 (to the right of the entire MathList) |
Currently MathListIndex is supposed to have a SubIndex if an only if SubIndexType <> MathListSubIndexType.None. (Can you confirm that @Happypig375 ?)
This PR brings this constraint into the type structure, removing
MathListSubIndexType.None
and having: