Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CSharpMath.Core.Tests/Atom/DictionaryTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CSharpMath.Atom;
using Xunit;

namespace CSharpMath.Core.Tests {
namespace CSharpMath.Core.AtomTests {
public class DictionaryTests {
private AliasBiDictionary<string, int> InitTestDict() =>
new AliasBiDictionary<string, int> {
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Core.Tests/Atom/LaTeXParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using CSharpMath.Atom.Atoms;
using Xunit;

namespace CSharpMath.Core.Tests {
namespace CSharpMath.Core.AtomTests {
public class LaTeXParserTest {
public static MathList ParseLaTeX(string latex) {
var builder = new LaTeXParser(latex);
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Core.Tests/Atom/LaTeXSettingsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Linq;
using Xunit;
namespace CSharpMath.Core.Tests {
namespace CSharpMath.Core.AtomTests {
using CSharpMath.Atom;
using CSharpMath.Atom.Atoms;
using static LaTeXParserTest;
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Core.Tests/Atom/MathAtomTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using CSharpMath.Atom.Atoms;
using Xunit;

namespace CSharpMath.Core.Tests {
namespace CSharpMath.Core.AtomTests {
public class MathAtomTest {
internal static void CheckClone(MathAtom? original, MathAtom? clone) =>
MathListTest.CheckClone(original, clone);
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Core.Tests/Atom/MathListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using CSharpMath.Atom.Atoms;
using Xunit;

namespace CSharpMath.Core.Tests {
namespace CSharpMath.Core.AtomTests {
using Range = Atom.Range;
public class MathListTest {
internal static void CheckClone(MathAtom? original, MathAtom? clone) {
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Core.Tests/Display/ApproximateAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Runtime.CompilerServices;
using Xunit;

namespace CSharpMath.Core.Tests {
namespace CSharpMath.Core.DisplayTests {
[DebuggerStepThrough] // Debugger should stop at the line that uses these functions
public static class Approximately {
const double DefaultTolerance = 0.001;
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Core.Tests/Display/FontChangingTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CSharpMath.Core.Tests {
namespace CSharpMath.Core.DisplayTests {
using Atom;
using Xunit;
public class FontChangingTests {
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Core.Tests/Display/MockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Xunit;
using TGlyph = System.Text.Rune;

namespace CSharpMath.Core.Tests {
namespace CSharpMath.Core.DisplayTests {
using BackEnd;
// purpose of this class is to make sure our mocks behave as expected.
public class MockTests {
Expand Down
4 changes: 2 additions & 2 deletions CSharpMath.Core.Tests/Display/TypesetterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
using TFont = CSharpMath.Core.BackEnd.TestFont;
using TGlyph = System.Text.Rune;

namespace CSharpMath.Core.Tests {
namespace CSharpMath.Core.DisplayTests {
public class TypesetterTests {
internal static ListDisplay<TFont, TGlyph> ParseLaTeXToDisplay(string latex) =>
Typesetter.CreateLine(LaTeXParserTest.ParseLaTeX(latex), _font, _context, LineStyle.Display);
Typesetter.CreateLine(AtomTests.LaTeXParserTest.ParseLaTeX(latex), _font, _context, LineStyle.Display);

private static readonly TFont _font = new TFont(20);
private static readonly TypesettingContext<TFont, TGlyph> _context = BackEnd.TestTypesettingContext.Instance;
Expand Down
4 changes: 2 additions & 2 deletions CSharpMath.Core.Tests/Editor/CaretTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Xunit;
using TGlyph = System.Text.Rune;

namespace CSharpMath.Core.Tests {
namespace CSharpMath.Core.EditorTests {
using Atom;
using BackEnd;
using Editor;
Expand Down Expand Up @@ -212,7 +212,7 @@ public void ShowRestingPlaceholdersOnCaretVisible() {
Assert.True(keyboard.InsertionPositionHighlighted);
Assert.False(keyboard.ShouldDrawCaret);

keyboard.InsertionIndex = MathListIndex.Level0Index(keyboard.MathList.Count);
keyboard.InsertionIndex = new MathListIndex(keyboard.MathList.Count);
Assert.True(keyboard.InsertionPositionHighlighted);
Assert.True(keyboard.ShouldDrawCaret);
Assert.Equal(LaTeXSettings.PlaceholderRestingNucleus, outer.Nucleus);
Expand Down
15 changes: 5 additions & 10 deletions CSharpMath.Core.Tests/Editor/IndexForPointTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Drawing;
using Xunit;

namespace CSharpMath.Core.Tests {
namespace CSharpMath.Core.EditorTests {
using Atom;
using BackEnd;
using Editor;
Expand All @@ -14,18 +14,13 @@ public void Add((double x, double y) point,
int index, params (SubIndex subType, int subIndex)[] subIndexRecursive) {
switch (subIndexRecursive.Length) {
case 0:
var mathListIndex = MathListIndex.Level0Index(index);
var mathListIndex = new MathListIndex(index);
goto default;
case var _:
mathListIndex = MathListIndex.Level0Index(
subIndexRecursive[^1].subIndex);
mathListIndex = new(subIndexRecursive[^1].subIndex);
for (var i = subIndexRecursive.Length - 2; i >= 0; i--)
mathListIndex = MathListIndex.IndexAtLocation(
subIndexRecursive[i].subIndex,
subIndexRecursive[i + 1].subType,
mathListIndex);
mathListIndex = MathListIndex.IndexAtLocation(index,
subIndexRecursive[0].subType, mathListIndex);
mathListIndex = mathListIndex.Wrap(subIndexRecursive[i].subIndex, subIndexRecursive[i + 1].subType);
mathListIndex = mathListIndex.Wrap(index, subIndexRecursive[0].subType);
goto default;
default:
Add(new PointF((float)point.x, (float)point.y), mathListIndex);
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Core.Tests/Editor/KeyPressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using T = Xunit.InlineDataAttribute;
using TGlyph = System.Text.Rune;

namespace CSharpMath.Core.Tests {
namespace CSharpMath.Core.EditorTests {
using BackEnd;
using Editor;
public class KeyPressTests {
Expand Down
4 changes: 2 additions & 2 deletions CSharpMath.Core.Tests/Editor/PointForIndexTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Drawing;
using Xunit;

namespace CSharpMath.Core.Tests {
using Atom;
namespace CSharpMath.Core.EditorTests {
using BackEnd;
using DisplayTests;
using Editor;
using static IndexForPointTests;
// Use CSharpMath.Core.Example to visualize the test cases
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Rendering.Tests/TestRendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected void Run<TContent>(
return;
}

Core.Tests.Approximately.Equal(expectedStream.Length, actualStream.Length, expectedStream.Length * FileSizeTolerance);
Core.DisplayTests.Approximately.Equal(expectedStream.Length, actualStream.Length, expectedStream.Length * FileSizeTolerance);
if (FileSizeTolerance == 0)
Assert.True(contentsMatch, "The images differ.");
}
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath/Atom/MathList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class MathList : IMathObject, IList<MathAtom>, IReadOnlyList<MathAtom>, I
public MathList(params MathAtom[] atoms) => Atoms = new List<MathAtom>(atoms);

/// <returns>The last <see cref="MathAtom"/> that is not a <see cref="Comment"/>,
/// or <see cref="null"/> when <see cref="Atoms"/> is empty.</returns>
/// or <see langword="null"/> when <see cref="Atoms"/> is empty.</returns>
#if !NETSTANDARD2_0 && !NET45
[System.Diagnostics.CodeAnalysis.DisallowNull]
#endif
Expand Down
1 change: 1 addition & 0 deletions CSharpMath/CSharpMath.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="IsExternalInit" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="System.Memory" Version="4.6.3" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" />
Expand Down
24 changes: 11 additions & 13 deletions CSharpMath/Editor/Extensions/FractionDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,30 @@ namespace CSharpMath.Editor {
using Display.FrontEnd;

partial class Extensions {
public static MathListIndex IndexForPoint<TFont, TGlyph>(
public static MathListIndex? IndexForPoint<TFont, TGlyph>(
this FractionDisplay<TFont, TGlyph> self,
TypesettingContext<TFont, TGlyph> context,
PointF point) where TFont : IFont<TGlyph> =>
// We can be before or after the fraction
point.X < self.Position.X - PixelDelta
//We are before the fraction, so
? MathListIndex.Level0Index(self.Range.Location)
// We are before the fraction
? new(self.Range.Location)
: point.X > self.Position.X + self.Width + PixelDelta
//We are after the fraction
? MathListIndex.Level0Index(self.Range.End)
// We are after the fraction
? new(self.Range.End)
: point.Y > self.LinePosition + PixelDelta
? MathListIndex.IndexAtLocation(self.Range.Location,
MathListSubIndexType.Numerator, self.Numerator.IndexForPoint(context, point))
? self.Numerator.IndexForPoint(context, point)?.Wrap(self.Range.Location, MathListSubIndexType.Numerator)
: point.Y < self.LinePosition - PixelDelta
? MathListIndex.IndexAtLocation(self.Range.Location,
MathListSubIndexType.Denominator, self.Denominator.IndexForPoint(context, point))
? self.Denominator.IndexForPoint(context, point)?.Wrap(self.Range.Location, MathListSubIndexType.Denominator)
: point.X > self.Position.X + self.Width / 2
? MathListIndex.Level0Index(self.Range.End)
: MathListIndex.Level0Index(self.Range.Location);
? new(self.Range.End)
: new(self.Range.Location);

public static PointF? PointForIndex<TFont, TGlyph>(
this FractionDisplay<TFont, TGlyph> self,
TypesettingContext<TFont, TGlyph> _,
MathListIndex index) where TFont : IFont<TGlyph> =>
index.SubIndexType != MathListSubIndexType.None
index.SubIndexInfo is { }
? throw new ArgumentException
("The subindex must be none to get the closest point for it.", nameof(index))
: index.AtomIndex == self.Range.End
Expand All @@ -42,7 +40,7 @@ public static MathListIndex IndexForPoint<TFont, TGlyph>(
public static void HighlightCharacterAt<TFont, TGlyph>(
this FractionDisplay<TFont, TGlyph> self,
MathListIndex index, Color color) where TFont : IFont<TGlyph> {
if (index.SubIndexType != MathListSubIndexType.None)
if (index.SubIndexInfo is { })
throw new ArgumentException
("The subindex must be none to get the highlight a character in it.", nameof(index));
self.Highlight(color);
Expand Down
8 changes: 4 additions & 4 deletions CSharpMath/Editor/Extensions/IGlyphDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public static MathListIndex IndexForPoint<TFont, TGlyph>(
TypesettingContext<TFont, TGlyph> _,
PointF point) where TFont : IFont<TGlyph> =>
point.X > self.Position.X + self.Width / 2
? MathListIndex.Level0Index(self.Range.End)
: MathListIndex.Level0Index(self.Range.Location);
? new(self.Range.End)
: new(self.Range.Location);

public static PointF? PointForIndex<TFont, TGlyph>(
this IGlyphDisplay<TFont, TGlyph> self,
TypesettingContext<TFont, TGlyph> _,
MathListIndex index) where TFont : IFont<TGlyph> =>
index.SubIndexType != MathListSubIndexType.None
index.SubIndexInfo is { }
? throw new ArgumentException
("The subindex must be none to get the closest point for it.", nameof(index))
: index.AtomIndex == self.Range.End
Expand All @@ -29,7 +29,7 @@ public static MathListIndex IndexForPoint<TFont, TGlyph>(
public static void HighlightCharacterAt<TFont, TGlyph>(
this IGlyphDisplay<TFont, TGlyph> self,
MathListIndex index, Color color) where TFont : IFont<TGlyph> {
if (index.SubIndexType != MathListSubIndexType.None)
if (index.SubIndexInfo is { })
throw new ArgumentException
("The subindex must be none to get the highlight a character in it.", nameof(index));
self.Highlight(color);
Expand Down
13 changes: 6 additions & 7 deletions CSharpMath/Editor/Extensions/InnerDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@ namespace CSharpMath.Editor {
using Display.FrontEnd;

partial class Extensions {
public static MathListIndex IndexForPoint<TFont, TGlyph>(
public static MathListIndex? IndexForPoint<TFont, TGlyph>(
this InnerDisplay<TFont, TGlyph> self,
TypesettingContext<TFont, TGlyph> context,
PointF point) where TFont : IFont<TGlyph> =>
// We can be before or after the inner
point.X < self.Position.X + (self.Left?.Width / 2 ?? 0)
//We are before the inner, so
? MathListIndex.Level0Index(self.Range.Location)
? new(self.Range.Location)
: point.X > self.Position.X + self.Width - (self.Right?.Width / 2 ?? 0)
//We are after the inner
? MathListIndex.Level0Index(self.Range.End)
: MathListIndex.IndexAtLocation(self.Range.Location,
MathListSubIndexType.Inner, self.Inner.IndexForPoint(context, point));
? new(self.Range.End)
: self.Inner.IndexForPoint(context, point)?.Wrap(self.Range.Location, MathListSubIndexType.Inner);

public static PointF? PointForIndex<TFont, TGlyph>(
this InnerDisplay<TFont, TGlyph> self,
TypesettingContext<TFont, TGlyph> _,
MathListIndex index) where TFont : IFont<TGlyph> =>
index.SubIndexType != MathListSubIndexType.None
index.SubIndexInfo is { }
? throw new ArgumentException
("The subindex must be none to get the closest point for it.", nameof(index))
: index.AtomIndex == self.Range.End
Expand All @@ -35,7 +34,7 @@ public static MathListIndex IndexForPoint<TFont, TGlyph>(
public static void HighlightCharacterAt<TFont, TGlyph>(
this InnerDisplay<TFont, TGlyph> self,
MathListIndex index, Color color) where TFont : IFont<TGlyph> {
if (index.SubIndexType != MathListSubIndexType.None)
if (index.SubIndexInfo is { })
throw new ArgumentException
("The subindex must be none to get the highlight a character in it.", nameof(index));
self.Highlight(color);
Expand Down
23 changes: 10 additions & 13 deletions CSharpMath/Editor/Extensions/LargeOpLimitsDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,32 @@ namespace CSharpMath.Editor {
using Display.FrontEnd;

partial class Extensions {
public static MathListIndex IndexForPoint<TFont, TGlyph>(
public static MathListIndex? IndexForPoint<TFont, TGlyph>(
this LargeOpLimitsDisplay<TFont, TGlyph> self,
TypesettingContext<TFont, TGlyph> context,
PointF point) where TFont : IFont<TGlyph> =>
// We can be before or after the large operator
point.X < self.Position.X - PixelDelta
// We are before the large operator, so
? MathListIndex.Level0Index(self.Range.Location)
? new(self.Range.Location)
: point.X > self.Position.X + self.Width + PixelDelta
// We are after the large operator
? MathListIndex.Level0Index(self.Range.End)
? new(self.Range.End)
: self.UpperLimit is { } u && point.Y > self.Position.Y + u.Position.Y - PixelDelta
? MathListIndex.IndexAtLocation(self.Range.Location,
MathListSubIndexType.Superscript, u.IndexForPoint(context, point))
? u.IndexForPoint(context, point)?.Wrap(self.Range.Location, MathListSubIndexType.Superscript)
: self.LowerLimit is { } l && point.Y < self.Position.Y + l.Position.Y + l.DisplayBounds().Height + PixelDelta
? MathListIndex.IndexAtLocation(self.Range.Location,
MathListSubIndexType.Subscript, l.IndexForPoint(context, point))
? l.IndexForPoint(context, point)?.Wrap(self.Range.Location, MathListSubIndexType.Subscript)
: point.X > self.Position.X + self.Width * 3 / 4
? MathListIndex.Level0Index(self.Range.End)
? new(self.Range.End)
: point.X > self.Position.X + self.Width / 2
? MathListIndex.IndexAtLocation(self.Range.Location,
MathListSubIndexType.BetweenBaseAndScripts, MathListIndex.Level0Index(1))
: MathListIndex.Level0Index(self.Range.Location);
? new(self.Range.Location, new(MathListSubIndexType.BetweenBaseAndScripts, new(1)))
: new(self.Range.Location);

public static PointF? PointForIndex<TFont, TGlyph>(
this LargeOpLimitsDisplay<TFont, TGlyph> self,
TypesettingContext<TFont, TGlyph> _,
MathListIndex index) where TFont : IFont<TGlyph> =>
index.SubIndexType != MathListSubIndexType.None
index.SubIndexInfo is { }
? throw new ArgumentException
("The subindex must be none to get the closest point for it.", nameof(index))
: index.AtomIndex == self.Range.End
Expand All @@ -46,7 +43,7 @@ public static MathListIndex IndexForPoint<TFont, TGlyph>(
public static void HighlightCharacterAt<TFont, TGlyph>(
this LargeOpLimitsDisplay<TFont, TGlyph> self,
MathListIndex index, Color color) where TFont : IFont<TGlyph> {
if (index.SubIndexType != MathListSubIndexType.None)
if (index.SubIndexInfo is { })
throw new ArgumentException
("The subindex must be none to get the highlight a character in it.", nameof(index));
self.Highlight(color);
Expand Down
Loading
Loading