Skip to content

Commit

Permalink
Compile for .NET 4.5.2 as well as for .NET Core 3.0 (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Dec 8, 2019
1 parent 3be93a2 commit a115e77
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/WpfMath.Example/WpfMath.Example.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net452</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<UseWpf>true</UseWpf>
<DebugType>Full</DebugType>
Expand Down
18 changes: 10 additions & 8 deletions src/WpfMath/Atoms/MatrixAtom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.Linq;
using WpfMath.Boxes;
using WpfMath.Utils;

namespace WpfMath.Atoms
{
Expand Down Expand Up @@ -48,7 +49,8 @@ private IEnumerable<Box> CreateRowCellBoxes(TexEnvironment environment, ReadOnly
/// <summary>
/// Calculates the height of each row and the width of each column and returns arrays of those.
/// </summary>
private (double[] RowHeights, double[] ColumnWidths) CalculateDimensions(
/// <returns>A tuple of RowHeights and ColumnWidths arrays.</returns>
private Tuple<double[], double[]> CalculateDimensions(
List<List<Box>> matrix,
int columnCount)
{
Expand All @@ -64,7 +66,7 @@ private IEnumerable<Box> CreateRowCellBoxes(TexEnvironment environment, ReadOnly
}
}

return (rowHeights, columnWidths);
return Tuple.Create(rowHeights, columnWidths);
}

private static List<List<CellGaps>> CalculateCellGaps(
Expand Down Expand Up @@ -107,14 +109,14 @@ private VerticalBox ApplyCellPaddings(
var cell = matrix[i][j];

var cellContainer = new VerticalBox();
var (topPadding, bottomPadding) = GetVerticalPadding(i, j);
var (topPadding, bottomPadding) = GetTopBottomPadding(i, j);
cellContainer.Add(topPadding);
cellContainer.Add(cell);
cellContainer.Add(bottomPadding);
cellContainer.Height = cellContainer.TotalHeight;
cellContainer.Depth = 0;

var (leftPadding, rightPadding) = GetHorizontalPadding(i, j);
var (leftPadding, rightPadding) = GetLeftRightPadding(i, j);
if (leftPadding != null) rowContainer.Add(leftPadding);
rowContainer.Add(cellContainer);
rowContainer.Add(rightPadding);
Expand All @@ -130,15 +132,15 @@ private VerticalBox ApplyCellPaddings(

return rowsContainer;

(Box TopPadding, Box BottomPadding) GetVerticalPadding(int i, int j)
Tuple<Box, Box> GetTopBottomPadding(int i, int j)
{
var value = matrixCellGaps[i][j].Vertical;
var topBox = new StrutBox(0.0, VerticalPadding / 2 + value, 0.0, VerticalPadding);
var bottomBox = new StrutBox(0.0, VerticalPadding / 2 + value, 0.0, VerticalPadding);
return (topBox, bottomBox);
return new Tuple<Box, Box>(topBox, bottomBox);
}

(Box LeftPadding, Box RightPadding) GetHorizontalPadding(int i, int j)
Tuple<Box, Box> GetLeftRightPadding(int i, int j)
{
var value = matrixCellGaps[i][j].Horizontal;
var leftPadding = MatrixCellAlignment == MatrixCellAlignment.Left ? 0.0 : value;
Expand All @@ -147,7 +149,7 @@ private VerticalBox ApplyCellPaddings(
? null
: new StrutBox(HorizontalPadding / 2 + leftPadding, 0.0, 0.0, 0.0);
var rightBox = new StrutBox(HorizontalPadding / 2 + rightPadding, 0.0, 0.0, 0.0);
return (leftBox, rightBox);
return new Tuple<Box, Box>(leftBox, rightBox);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/WpfMath/Colors/FloatRgbColorParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public FloatRgbColorParser(AlphaChannelMode alphaChannelMode) : base(alphaChanne

protected override double DefaultAlpha => 1.0;

protected override (bool, double) TryParseComponent(string component)
protected override Tuple<bool, double> TryParseComponent(string component)
{
var success = double.TryParse(
component,
NumberStyles.AllowDecimalPoint,
CultureInfo.InvariantCulture,
out var value);
return (success && value >= 0.0 && value <= 1.0, value);
return Tuple.Create(success && value >= 0.0 && value <= 1.0, value);
}

protected override byte GetByteValue(double val) =>
Expand Down
5 changes: 3 additions & 2 deletions src/WpfMath/Colors/IntegerRgbColorParser.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Globalization;

namespace WpfMath.Colors
Expand All @@ -10,10 +11,10 @@ public IntegerRgbColorParser(AlphaChannelMode alphaChannelMode) : base(alphaChan

protected override byte DefaultAlpha => 255;

protected override (bool, byte) TryParseComponent(string component)
protected override Tuple<bool, byte> TryParseComponent(string component)
{
var success = byte.TryParse(component, NumberStyles.None, CultureInfo.InvariantCulture, out var val);
return (success, val);
return Tuple.Create(success, val);
}

protected override byte GetByteValue(byte val) => val;
Expand Down
4 changes: 3 additions & 1 deletion src/WpfMath/Colors/RgbColorParserBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;
using WpfMath.Utils;

namespace WpfMath.Colors
{
Expand All @@ -26,7 +28,7 @@ protected RgbColorParserBase(AlphaChannelMode alphaChannelMode)

protected abstract T DefaultAlpha { get; }

protected abstract (bool, T) TryParseComponent(string component);
protected abstract Tuple<bool, T> TryParseComponent(string component);
protected abstract byte GetByteValue(T val);

protected override Color? ParseComponents(List<string> components)
Expand Down
15 changes: 15 additions & 0 deletions src/WpfMath/Utils/TupleExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace WpfMath.Utils
{
#if NET452 // not needed for .NET Core 3.0+ because there're System.TupleExtensions
internal static class TupleExtensions
{
public static void Deconstruct<T1, T2>(this Tuple<T1, T2> tuple, out T1 x1, out T2 x2)
{
x1 = tuple.Item1;
x2 = tuple.Item2;
}
}
#endif
}
5 changes: 1 addition & 4 deletions src/WpfMath/WpfMath.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;net461</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net452</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<UseWpf>true</UseWpf>
<OutputType>Library</OutputType>
Expand All @@ -19,7 +19,4 @@
<Resource Include="Fonts\cmr10.ttf" />
<Resource Include="Fonts\cmsy10.ttf" />
</ItemGroup>
<ItemGroup>
<PackageReference Condition="'$(TargetFramework)'=='net461'" Include="System.ValueTuple" Version="4.4.0" />
</ItemGroup>
</Project>

0 comments on commit a115e77

Please sign in to comment.