Skip to content

Commit

Permalink
#92: GeometryElementRenderer review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Dec 1, 2017
1 parent 0fae2ee commit 16835b7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ open WpfMath
open WpfMath.Rendering
open WpfMath.Rendering.Transformations

type GeometryRendererTests() =
type GeometryElementRendererTests() =
static do Utils.initializeFontResourceLoading()

let geometry = GeometryGroup()
let renderer = GeometryRenderer(1.0, geometry) :> IElementRenderer
let renderer = GeometryElementRenderer(geometry, 1.0) :> IElementRenderer

[<Fact>]
member __.``GeometryRenderer.RenderElement delegates to element.RenderTo``() : unit =
member __.``GeometryElementRenderer.RenderElement delegates to element.RenderTo``() : unit =
let box = Mock.Of<Box>()
renderer.RenderElement(box, 1.0, 2.0)
Mock.Verify(<@ box.RenderTo(renderer, 1.0, 2.0) @>, once)

[<Fact>]
member __.``GeometryRenderer.RenderGlyphRun adds a PathGeometry group``() : unit =
member __.``GeometryElementRenderer.RenderGlyphRun adds a PathGeometry group``() : unit =
let font = DefaultTexFont 20.0
let environment = TexEnvironment(TexStyle.Display, font, font)
let char = environment.MathFont.GetDefaultCharInfo('x', TexStyle.Display)
Expand All @@ -37,13 +37,13 @@ type GeometryRendererTests() =
Assert.IsType<PathGeometry>(Seq.exactlyOne group.Children) |> ignore

[<Fact>]
member __.``GeometryRenderer.RenderRectangle adds a RectangleGeometry``() : unit =
member __.``GeometryElementRenderer.RenderRectangle adds a RectangleGeometry``() : unit =
let rect = Rect(1.0, 2.0, 3.0, 4.0)
renderer.RenderRectangle(rect, null)

Assert.IsType<RectangleGeometry>(Seq.exactlyOne geometry.Children) |> ignore

[<Fact>]
member __.``GeometryRenderer.RenderTransformed adds a GeometryGroup``() : unit =
member __.``GeometryElementRenderer.RenderTransformed adds a GeometryGroup``() : unit =
renderer.RenderTransformed(HorizontalBox(), [| Transformation.Translate(1.0, 1.0) |], 0.0, 0.0)
Assert.IsType<GeometryGroup>(Seq.exactlyOne geometry.Children) |> ignore
2 changes: 1 addition & 1 deletion src/WpfMath.Tests/WpfMath.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<Compile Include="BoxTests.fs" />
<Compile Include="CharBoxTests.fs" />
<Compile Include="GeometryHelperTests.fs" />
<Compile Include="GeometryRendererTests.fs" />
<Compile Include="GeometryElementRendererTests.fs" />
<Compile Include="HorizontalBoxTests.fs" />
<Compile Include="HorizontalRuleTests.fs" />
<Compile Include="OverUnderBoxTests.fs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
namespace WpfMath.Rendering
{
/// <summary>A renderer that renders the elements to a provided <see cref="GeometryGroup"/> instance.</summary>
public class GeometryRenderer : IElementRenderer
public class GeometryElementRenderer : IElementRenderer
{
private readonly double _scale;
private readonly GeometryGroup _geometry;
private readonly double _scale;

public GeometryRenderer(double scale, GeometryGroup geometry)
public GeometryElementRenderer(GeometryGroup geometry, double scale)
{
_scale = scale;
_geometry = geometry;
_scale = scale;
}

public void RenderElement(Box box, double x, double y) => box.RenderTo(this, x, y);
Expand All @@ -39,7 +39,7 @@ public void RenderTransformed(Box box, Transformation[] transforms, double x, do
var group = new GeometryGroup();
var scaledTransforms = transforms.Select(t => t.Scale(_scale));
ApplyTransformations(scaledTransforms, group);
var nestedRenderer = new GeometryRenderer(_scale, group);
var nestedRenderer = new GeometryElementRenderer(group, _scale);
nestedRenderer.RenderElement(box, x, y);
_geometry.Children.Add(group);
}
Expand Down
2 changes: 1 addition & 1 deletion src/WpfMath/TexRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void RenderFormulaTo(IElementRenderer renderer, double x, double y) =>
public Geometry RenderToGeometry(double x, double y)
{
var geometry = new GeometryGroup();
var renderer = new GeometryRenderer(Scale, geometry);
var renderer = new GeometryElementRenderer(geometry, Scale);
RenderFormulaTo(renderer, x, y);
return geometry;
}
Expand Down
2 changes: 1 addition & 1 deletion src/WpfMath/WpfMath.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<Compile Include="Extensions.cs" />
<Compile Include="PredefinedColorParser.cs" />
<Compile Include="Rendering\GeometryHelper.cs" />
<Compile Include="Rendering\GeometryRenderer.cs" />
<Compile Include="Rendering\GeometryElementRenderer.cs" />
<Compile Include="Rendering\IElementRenderer.cs" />
<Compile Include="Rendering\Transformations\Transformation.cs" />
<Compile Include="Rendering\Transformations\TransformationKind.cs" />
Expand Down

0 comments on commit 16835b7

Please sign in to comment.