Skip to content
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

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft

[WIP] Tidy MathListIndex #159

wants to merge 16 commits into from

Conversation

charlesroddie
Copy link
Collaborator

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:

public (MathListSubIndexType SubIndexType, MathListIndex SubIndex)? SubIndexInfo;

@charlesroddie charlesroddie changed the title Tidy MathListIndex [WIP] Tidy MathListIndex Aug 11, 2020
@Happypig375
Copy link
Collaborator

Yes.

@charlesroddie
Copy link
Collaborator Author

Getting errors I'm having trouble diagnosing.

Inputs: 1, power, 2

Debug code gives:

InsertAndAdvance index before: [0, Superscript:0]
InsertAndAdvance index before: [0]
InsertAtAtomIndexAndAdvance atom: Number 2
InsertAtAtomIndexAndAdvance advance before: [0]
InsertAtAtomIndexAndAdvance advance after: [1]
InsertAndAdvance index at end: [1]
InsertAndAdvance index at end: [0, Superscript:0] // should be [0, Superscript:1]

I have the feeling it's to do with mutability and the refs. I didn't consider the refs when editing.

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 refs and make MathList immutable. This would involve more recursive code. But it could be good to get this PR working before tackling that I think.

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
Copy link
Collaborator

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
Copy link
Collaborator

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);
Copy link
Collaborator

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
Copy link
Collaborator

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>
Copy link
Collaborator

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);
Copy link
Collaborator

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

@Happypig375
Copy link
Collaborator

Independently of getting this PR working, it's good to remove the refs

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
Copy link
Collaborator Author

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 ?

Copy link
Collaborator

@Happypig375 Happypig375 Aug 16, 2020

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got that far...

Copy link
Collaborator Author

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?

Copy link
Collaborator

@Happypig375 Happypig375 Aug 16, 2020

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)

Copy link
Collaborator Author

@charlesroddie charlesroddie Aug 16, 2020

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?

Copy link
Collaborator

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)

@Happypig375 Happypig375 added the Type/Housekeeping This includes internal only changes. label Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type/Housekeeping This includes internal only changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants