Skip to content

Commit a7f7174

Browse files
author
LoneWandererProductions
committed
Fix up LightVector a bit.
1 parent 94115fc commit a7f7174

9 files changed

Lines changed: 243 additions & 117 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: CommonLibraryGuiTests
4-
* FILE: CommonLibraryGuiTests/AuroraTests.cs
4+
* FILE: AuroraTests.cs
55
* PURPOSE: Tests the Aurorae Display
66
* PROGRAMER: Peter Geinitz (Wayfarer)
77
*/
@@ -22,7 +22,7 @@ namespace CommonLibraryGuiTests
2222
/// <summary>
2323
/// Some Basic tests for the Aurora Engine and the image Combining
2424
/// </summary>
25-
public sealed class Solaris
25+
public sealed class AuroraTests
2626
{
2727
/// <summary>
2828
/// The codebase

CommonLibraryGuiTests/BitmapComparisonTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: CommonLibraryGuiTests
4-
* FILE: CommonLibraryGuiTests/BitmapRenderingTests.cs
4+
* FILE: BitmapRenderingTests.cs
55
* PURPOSE: Mostly Performance tests for our Wpf BitmapImage Viewer
66
* PROGRAMER: Peter Geinitz (Wayfarer)
77
*/

CommonLibraryGuiTests/CommonCtrl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: CommonLibraryGuiTests
4-
* FILE: CommonLibraryGuiTests/CommonCtrl.cs
4+
* FILE: CommonCtrl.cs
55
* PURPOSE: Tests for CommonCtrl some Controls, not all yet
66
* PROGRAMER: Peter Geinitz (Wayfarer)
77
*/

CommonLibraryGuiTests/CommonDialogs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: CommonLibraryGuiTests
4-
* FILE: CommonLibraryGuiTests/CommonDialogs.cs
4+
* FILE: CommonDialogs.cs
55
* PURPOSE: Tests for CommonCtrl some Controls, not all yet
66
* PROGRAMER: Peter Geinitz (Wayfarer)
77
*/
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* COPYRIGHT: See COPYING in the top level directory
3+
* PROJECT: CommonLibraryGuiTests
4+
* FILE: WpfVectorRendererTests.cs
5+
* PURPOSE: Basic tests for the WpfVectorRenderer, especially to catch the "Double Offset" bug where the line's internal coordinates are incorrectly offset by the StartCoordinates.
6+
* PROGRAMER: Peter Geinitz (Wayfarer)
7+
*/
8+
9+
10+
using System.Collections.Generic;
11+
using System.Windows;
12+
using System.Windows.Controls;
13+
using System.Windows.Shapes;
14+
using NUnit.Framework;
15+
using System.Threading;
16+
using System.Linq;
17+
using LightVector;
18+
19+
namespace CommonLibraryGuiTests
20+
{
21+
/// <summary>
22+
/// Simple tests for the WpfVectorRenderer, especially to catch the "Double Offset" bug where the line's internal coordinates are incorrectly offset by the StartCoordinates.
23+
/// </summary>
24+
[TestFixture]
25+
[Apartment(ApartmentState.STA)]
26+
public class WpfVectorRendererTests
27+
{
28+
/// <summary>
29+
/// Renders to container verify normalization.
30+
/// </summary>
31+
[Test]
32+
public void RenderToContainer_VerifyNormalization()
33+
{
34+
// Arrange
35+
var startPoint = new Point(50, 50);
36+
var line = new LineObject { Direction = new System.Numerics.Vector2(10, 10), Thickness = 2 };
37+
var saveObj = new SaveObject { Graphic = line, Type = GraphicTypes.Line, StartCoordinates = startPoint };
38+
39+
var renderer = new WpfVectorRenderer(new List<SaveObject> { saveObj });
40+
41+
// Act
42+
var canvas = (Canvas)renderer.RenderToContainer();
43+
var renderedLine = canvas.Children.OfType<Line>().First();
44+
45+
// Assert
46+
// Because of normalization, the line is shifted.
47+
// It should now be at 'padding' (Thickness / 2)
48+
Assert.That(Canvas.GetLeft(renderedLine), Is.EqualTo(1.0d), "Line should be shifted to the edge of the canvas.");
49+
Assert.That(renderedLine.X1, Is.EqualTo(0), "Internal offset must remain 0.");
50+
}
51+
52+
/// <summary>
53+
/// Renders to image verify dimensions match bounds.
54+
/// </summary>
55+
[Test]
56+
public void RenderToImage_VerifyDimensionsMatchBounds()
57+
{
58+
// Arrange
59+
var circle = new CircleObject { Radius = 100, Thickness = 10 };
60+
var saveObj = new SaveObject
61+
{
62+
Graphic = circle,
63+
Type = GraphicTypes.Circle,
64+
StartCoordinates = new Point(0, 0),
65+
Layer = 0
66+
};
67+
68+
var renderer = new WpfVectorRenderer(new List<SaveObject> { saveObj });
69+
70+
// Act
71+
var image = renderer.RenderToImage();
72+
73+
// Assert
74+
// Circle radius 100 + thickness 10 = total diameter 210.
75+
// Our GetGraphicBounds should account for this.
76+
Assert.That(image.Width, Is.GreaterThanOrEqualTo(200), "Image must be wide enough for the diameter.");
77+
}
78+
}
79+
}

LightVector/BezierCurve.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: LightVector
44
* FILE: LightVector/BezierCurve.cs
5-
* PURPOSE: Hold the CurvBecier e Object
5+
* PURPOSE: Hold the Curve Bezier Object
66
* PROGRAMER: Peter Geinitz (Wayfarer)
77
* SOURCES: https://docs.microsoft.com/de-de/dotnet/api/system.drawing.graphics.drawcurve?view=netframework-4.8
88
*/

LightVector/GraphicLine.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.

LightVector/GraphicObject.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// ReSharper disable UnusedMember.Global
1313

1414
using System.Collections.Generic;
15+
using System.Windows.Ink;
1516
using System.Windows.Media;
1617
using System.Xml.Serialization;
1718

@@ -26,6 +27,16 @@ namespace LightVector
2627
[System.Serializable]
2728
public abstract class GraphicObject
2829
{
30+
/// <summary>
31+
/// The fill
32+
/// </summary>
33+
private SolidColorBrush _fill;
34+
35+
/// <summary>
36+
/// The stroke
37+
/// </summary>
38+
private SolidColorBrush _stroke = Brushes.Black;
39+
2940
/// <summary>
3041
/// Optional
3142
/// </summary>
@@ -36,7 +47,15 @@ public abstract class GraphicObject
3647
/// Optional
3748
/// </summary>
3849
[XmlIgnore]
39-
public SolidColorBrush Stroke { get; set; } = Brushes.Black;
50+
public SolidColorBrush Stroke
51+
{
52+
get => _stroke;
53+
set
54+
{
55+
_stroke = value;
56+
if (_stroke?.CanFreeze == true) _stroke.Freeze();
57+
}
58+
}
4059

4160
/// <summary>
4261
/// Workaround for XML serialization of Stroke
@@ -53,7 +72,15 @@ public string StrokeColor
5372
/// If filled we will get filled curves
5473
/// </summary>
5574
[XmlIgnore]
56-
public SolidColorBrush Fill { get; set; }
75+
public SolidColorBrush Fill
76+
{
77+
get => _fill;
78+
set
79+
{
80+
_fill = value;
81+
if (_fill?.CanFreeze == true) _fill.Freeze();
82+
}
83+
}
5784

5885
/// <summary>
5986
/// Workaround for XML serialization of Fill

0 commit comments

Comments
 (0)