Skip to content

Commit 8e03dc1

Browse files
author
Dominic Beger
committed
Add missing documentation and cleanup everything
1 parent afbebd3 commit 8e03dc1

49 files changed

Lines changed: 1381 additions & 1321 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

SharpMath.3DTest/PerspectiveForm.cs

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
1-
using SharpMath.Geometry;
2-
using SharpMath.Trigonometry;
1+
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
33
using System;
44
using System.Drawing;
55
using System.Drawing.Drawing2D;
66
using System.Windows.Forms;
7+
using SharpMath.Geometry;
78

89
namespace SharpMath._3DTest
910
{
1011
public partial class PerspectiveForm : Form
1112
{
13+
private readonly Vector4[] _vertices =
14+
{
15+
new Vector4(-0.5, 0.5, 1.5, 1), new Vector4(0.5, 0.5, 1.5, 1), new Vector4(0.5, -0.5, 1.5, 1),
16+
new Vector4(-0.5, -0.5, 1.5, 1),
17+
new Vector4(-0.5, 0.5, 2.5, 1), new Vector4(0.5, 0.5, 2.5, 1), new Vector4(0.5, -0.5, 2.5, 1),
18+
new Vector4(-0.5, -0.5, 2.5, 1)
19+
};
20+
1221
private Color _color = Color.White;
13-
private Vector4[] _vertices = new Vector4[] { new Vector4(-0.5, 0.5, 1.5, 1), new Vector4(0.5, 0.5, 1.5, 1), new Vector4(0.5, -0.5, 1.5, 1), new Vector4(-0.5, -0.5, 1.5, 1),
14-
new Vector4(-0.5, 0.5, 2.5, 1), new Vector4(0.5, 0.5, 2.5, 1), new Vector4(0.5, -0.5, 2.5, 1), new Vector4(-0.5, -0.5, 2.5, 1) };
15-
private Matrix4x4 _view;
16-
private Matrix4x4 _world;
17-
private Matrix4x4 _scalation = Matrix4x4.Scalation(0.5f);
1822
private Matrix4x4 _rotationX = Matrix4x4.Identity;
1923
private Matrix4x4 _rotationY = Matrix4x4.Identity;
2024
private Matrix4x4 _rotationZ = Matrix4x4.Identity;
25+
private Matrix4x4 _scalation = Matrix4x4.Scalation(0.5f);
26+
private Matrix4x4 _view;
27+
private Matrix4x4 _world;
28+
private float angle;
29+
private float delta = 1f;
2130
//private Matrix4x4 _projection;
2231

2332
public PerspectiveForm()
@@ -45,25 +54,29 @@ private void UpdateMatrices()
4554

4655
private void perspectivePanel_Paint(object sender, PaintEventArgs e)
4756
{
48-
var transformationMatrix = Matrix4x4.Translation(0, 0, 2) * _view * _world * _rotationX * _rotationY * _rotationZ * _scalation * Matrix4x4.Translation(0, 0, -2);
49-
var projectionData = new ProjectionData(perspectivePanel.Size, 16f / 9f, (float)Math.PI / 3f, 0.1f, 100f);
57+
var transformationMatrix = Matrix4x4.Translation(0, 0, 2)*_view*_world*_rotationX*_rotationY*_rotationZ*
58+
_scalation*Matrix4x4.Translation(0, 0, -2);
59+
var projectionData = new ProjectionData(perspectivePanel.Size, 16f/9f, (float) Math.PI/3f, 0.1f, 100f);
5060

51-
Func<Vector4, Vector2> projectPerspective = (vector) =>
61+
Func<Vector4, Vector2> projectPerspective = vector =>
5262
{
53-
var perspectiveVector = vector * Matrix4x4.PerspectiveFieldOfView(projectionData);
63+
var perspectiveVector = vector*Matrix4x4.PerspectiveFieldOfView(projectionData);
5464
perspectiveVector.X /= perspectiveVector.W;
5565
perspectiveVector.Y /= perspectiveVector.W;
5666
perspectiveVector.Z /= perspectiveVector.W;
5767

58-
var deviceVector = perspectiveVector * Matrix4x4.Scalation(projectionData.CanvasSize.Width / 2.0, projectionData.CanvasSize.Height / 2.0, 1);
59-
return new Vector2(deviceVector.X + projectionData.CanvasSize.Width / 2, (projectionData.CanvasSize.Height / 2) - deviceVector.Y);
68+
var deviceVector = perspectiveVector*
69+
Matrix4x4.Scalation(projectionData.CanvasSize.Width/2.0,
70+
projectionData.CanvasSize.Height/2.0, 1);
71+
return new Vector2(deviceVector.X + projectionData.CanvasSize.Width/2,
72+
(projectionData.CanvasSize.Height/2) - deviceVector.Y);
6073
};
6174

6275
PointF[] displayCoordinates = new PointF[_vertices.Length];
6376
for (int i = 0; i < _vertices.Length; i++)
6477
{
65-
Vector2 displayVector = projectPerspective(_vertices[i] * transformationMatrix);
66-
displayCoordinates[i] = new PointF((float)displayVector.X, (float)displayVector.Y);
78+
Vector2 displayVector = projectPerspective(_vertices[i]*transformationMatrix);
79+
displayCoordinates[i] = new PointF((float) displayVector.X, (float) displayVector.Y);
6780
}
6881

6982
Graphics g = e.Graphics;
@@ -82,24 +95,22 @@ private void perspectivePanel_Paint(object sender, PaintEventArgs e)
8295

8396
private void trackBar1_Scroll(object sender, EventArgs e)
8497
{
85-
_rotationX = Matrix4x4.RotationX(Converter.DegreesToRadians(trackBar1.Value));
98+
_rotationX = Matrix4x4.RotationX(MathHelper.DegreesToRadians(trackBar1.Value));
8699
UpdateMatrices();
87100
}
88101

89102
private void trackBar2_Scroll(object sender, EventArgs e)
90103
{
91-
_rotationY = Matrix4x4.RotationY(Converter.DegreesToRadians(trackBar2.Value));
104+
_rotationY = Matrix4x4.RotationY(MathHelper.DegreesToRadians(trackBar2.Value));
92105
UpdateMatrices();
93106
}
94107

95108
private void trackBar3_Scroll(object sender, EventArgs e)
96109
{
97-
_rotationZ = Matrix4x4.RotationZ(Converter.DegreesToRadians(trackBar3.Value));
110+
_rotationZ = Matrix4x4.RotationZ(MathHelper.DegreesToRadians(trackBar3.Value));
98111
UpdateMatrices();
99112
}
100113

101-
private float delta = 1f;
102-
private float angle = 0f;
103114
private void rotationTimer_Tick(object sender, EventArgs e)
104115
{
105116
if (angle <= 0)
@@ -108,13 +119,13 @@ private void rotationTimer_Tick(object sender, EventArgs e)
108119
delta = -1f;
109120
angle += delta;
110121

111-
_rotationX = Matrix4x4.RotationX(Converter.DegreesToRadians(angle));
112-
_rotationY = Matrix4x4.RotationY(Converter.DegreesToRadians(angle));
113-
_rotationZ = Matrix4x4.RotationZ(Converter.DegreesToRadians(angle));
122+
_rotationX = Matrix4x4.RotationX(MathHelper.DegreesToRadians(angle));
123+
_rotationY = Matrix4x4.RotationY(MathHelper.DegreesToRadians(angle));
124+
_rotationZ = Matrix4x4.RotationZ(MathHelper.DegreesToRadians(angle));
114125

115-
trackBar1.Value = (int)angle;
116-
trackBar2.Value = (int)angle;
117-
trackBar3.Value = (int)angle;
126+
trackBar1.Value = (int) angle;
127+
trackBar2.Value = (int) angle;
128+
trackBar3.Value = (int) angle;
118129

119130
// Causes headaches
120131
//Random randomGen = new Random();
@@ -137,7 +148,7 @@ private void autoRotateCheckBox_CheckedChanged(object sender, EventArgs e)
137148

138149
private void scalationTrackBar_Scroll(object sender, EventArgs e)
139150
{
140-
_scalation = Matrix4x4.Scalation(scalationTrackBar.Value / 720f);
151+
_scalation = Matrix4x4.Scalation(scalationTrackBar.Value/720f);
141152
UpdateMatrices();
142153
}
143154
}

SharpMath.3DTest/PerspectivePanel.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
using System.Windows.Forms;
1+
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
3+
using System.Windows.Forms;
24

35
namespace SharpMath._3DTest
46
{
57
public class PerspectivePanel : Panel
68
{
79
public PerspectivePanel()
810
{
9-
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
11+
SetStyle(
12+
ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw |
13+
ControlStyles.SupportsTransparentBackColor, true);
1014
UpdateStyles();
1115
}
1216
}

SharpMath.3DTest/Program.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
1+
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
3+
using System;
54
using System.Windows.Forms;
65

76
namespace SharpMath._3DTest
87
{
9-
static class Program
8+
internal static class Program
109
{
1110
/// <summary>
12-
/// The main entry point for the application.
11+
/// The main entry point for the application.
1312
/// </summary>
1413
[STAThread]
15-
static void Main()
14+
private static void Main()
1615
{
1716
Application.EnableVisualStyles();
1817
Application.SetCompatibleTextRenderingDefault(false);
1918
Application.Run(new PerspectiveForm());
2019
}
2120
}
22-
}
21+
}

SharpMath.3DTest/Properties/AssemblyInfo.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
using System.Reflection;
2-
using System.Runtime.CompilerServices;
1+
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
3+
using System.Reflection;
34
using System.Runtime.InteropServices;
45

56
// General Information about an assembly is controlled through the following
67
// set of attributes. Change these attribute values to modify the information
78
// associated with an assembly.
9+
810
[assembly: AssemblyTitle("SharpMath.3DTest")]
911
[assembly: AssemblyDescription("")]
1012
[assembly: AssemblyConfiguration("")]
@@ -17,9 +19,11 @@
1719
// Setting ComVisible to false makes the types in this assembly not visible
1820
// to COM components. If you need to access a type in this assembly from
1921
// COM, set the ComVisible attribute to true on that type.
22+
2023
[assembly: ComVisible(false)]
2124

2225
// The following GUID is for the ID of the typelib if this project is exposed to COM
26+
2327
[assembly: Guid("15428131-2ac9-4af4-8966-664ff1974ce8")]
2428

2529
// Version information for an assembly consists of the following four values:
@@ -32,5 +36,6 @@
3236
// You can specify all the values or you can default the Build and Revision Numbers
3337
// by using the '*' as shown below:
3438
// [assembly: AssemblyVersion("1.0.*")]
39+
3540
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
41+
[assembly: AssemblyFileVersion("1.0.0.0")]

SharpMath.Tests/Line2DTest.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
24
using SharpMath.Geometry;
35

46
namespace SharpMath.Tests
@@ -10,12 +12,12 @@ public class Line2DTest
1012
public void CanCreateLineFromPoints()
1113
{
1214
var line = Line2D.FromPoints(new Point2D(0, 2), new Point2D(3, 1));
13-
Assert.AreEqual(-1d / 3d, line.Slope);
15+
Assert.AreEqual(-1d/3d, line.Slope);
1416
Assert.AreEqual(2, line.Offset);
1517

1618
var secondLine = Line2D.FromPoints(new Point2D(4, 5), new Point2D(1, 3));
17-
Assert.AreEqual(2d / 3d, secondLine.Slope);
18-
Assert.AreEqual(7d / 3d, secondLine.Offset);
19+
Assert.AreEqual(2d/3d, secondLine.Slope);
20+
Assert.AreEqual(7d/3d, secondLine.Offset);
1921
}
2022

2123
[TestMethod]

SharpMath.Tests/Line3DTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
24
using SharpMath.Geometry;
35

46
namespace SharpMath.Tests
@@ -32,6 +34,5 @@ public void CanDetermineIfPointIsOnLine()
3234
Assert.IsTrue(line.IsPointOnLine(new Point3D(6, 5, 5)));
3335
Assert.IsFalse(line.IsPointOnLine(new Point3D(2, 3.5, 2)));
3436
}
35-
3637
}
3738
}

SharpMath.Tests/LinearEquationTest.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
24
using SharpMath.Equations;
35
using SharpMath.Equations.Exceptions;
46

@@ -24,11 +26,11 @@ public void CanSolveSimpleLinearEquationSystem()
2426
public void CanSolveLinearEquationSystem()
2527
{
2628
// x - y + 2z = 6
27-
var firstEquation = new LinearEquation(new[] { 1.0, -1.0, 2.0 }, 6);
29+
var firstEquation = new LinearEquation(new[] {1.0, -1.0, 2.0}, 6);
2830
// 2x + 3y + 2z = 11
29-
var secondEquation = new LinearEquation(new[] { 2.0, 3.0, 2.0 }, 11);
31+
var secondEquation = new LinearEquation(new[] {2.0, 3.0, 2.0}, 11);
3032
// 3x + 2y + z = 8
31-
var thirdEquation = new LinearEquation(new[] { 3.0, 2.0, 1.0 }, 8);
33+
var thirdEquation = new LinearEquation(new[] {3.0, 2.0, 1.0}, 8);
3234

3335
var linearEquationSystem = new LinearEquationSystem(firstEquation, secondEquation, thirdEquation);
3436
double[] results = linearEquationSystem.Solve();
@@ -38,13 +40,13 @@ public void CanSolveLinearEquationSystem()
3840
}
3941

4042
[TestMethod]
41-
[ExpectedException(typeof(EquationNotSolvableException))]
43+
[ExpectedException(typeof (EquationNotSolvableException))]
4244
public void CanNotSolveLinearEquationSystemClearly()
4345
{
4446
// 0x = 0 - infinite solutions
45-
var equation = new LinearEquation(new[] { 0.0 }, 0);
47+
var equation = new LinearEquation(new[] {0.0}, 0);
4648
var results = new LinearEquationSystem(equation).Solve(); // This will throw an exception
4749
Assert.AreEqual(0, results[0]);
4850
}
4951
}
50-
}
52+
}

SharpMath.Tests/MatrixTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Diagnostics;
1+
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
3+
using System.Diagnostics;
24
using Microsoft.VisualStudio.TestTools.UnitTesting;
35
using SharpMath.Geometry;
46

SharpMath.Tests/ParserTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
24
using SharpMath.Expressions;
35

46
namespace SharpMath.Tests

SharpMath.Tests/PolygonTest.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System;
1+
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
3+
using System;
24
using Microsoft.VisualStudio.TestTools.UnitTesting;
35
using SharpMath.Geometry;
46

@@ -8,7 +10,7 @@ namespace SharpMath.Tests
810
public class PolygonTest
911
{
1012
[TestMethod]
11-
[ExpectedException(typeof(ArgumentException))]
13+
[ExpectedException(typeof (ArgumentException))]
1214
public void CanValidatePointAmount()
1315
{
1416
new Polygon(new Point2D(0, 1), new Point2D(3, 4));
@@ -21,8 +23,9 @@ public void CanCalculatePerimeter()
2123
new Polygon(new Point2D(0, 0), new Point2D(2, 0), new Point2D(2, 2), new Point2D(0, 2));
2224
Assert.AreEqual(8, square.Perimeter);
2325

24-
var polygon = new Polygon(new Point2D(-2, -2), new Point2D(2, -2), new Point2D(4, 1), new Point2D(0, 2), new Point2D(-4, 1));
25-
Assert.AreEqual(4 + 2 * Math.Sqrt(13) + 2 * Math.Sqrt(17), polygon.Perimeter);
26+
var polygon = new Polygon(new Point2D(-2, -2), new Point2D(2, -2), new Point2D(4, 1), new Point2D(0, 2),
27+
new Point2D(-4, 1));
28+
Assert.AreEqual(4 + 2*Math.Sqrt(13) + 2*Math.Sqrt(17), polygon.Perimeter);
2629
}
2730

2831
[TestMethod]
@@ -36,7 +39,8 @@ public void CanCalculateArea()
3639
new Polygon(new Point2D(0, 0), new Point2D(2, 0), new Point2D(1, 2));
3740
Assert.AreEqual(2, triangle.Area);
3841

39-
var polygon = new Polygon(new Point2D(-2, -2), new Point2D(2, -2), new Point2D(4, 1), new Point2D(0, 2), new Point2D(-4, 1));
42+
var polygon = new Polygon(new Point2D(-2, -2), new Point2D(2, -2), new Point2D(4, 1), new Point2D(0, 2),
43+
new Point2D(-4, 1));
4044
Assert.AreEqual(22, polygon.Area);
4145
}
4246
}

0 commit comments

Comments
 (0)