Skip to content

Commit 5f43063

Browse files
author
Dominic Beger
committed
Merge pull request #1 from stefan-baumann/master
Some improvements
2 parents 3d7aaeb + ac3c27c commit 5f43063

File tree

17 files changed

+326
-134
lines changed

17 files changed

+326
-134
lines changed

SharpMath/Equations/Exceptions/EquationNotSolvableException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
// Improvements: Stefan Baumann 2016
23

34
using System;
45

56
namespace SharpMath.Equations.Exceptions
67
{
8+
/// <summary>
9+
/// The exception that is thrown when an equation is not solvable.
10+
/// </summary>
11+
/// <seealso cref="System.Exception" />
712
public class EquationNotSolvableException : Exception
813
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="EquationNotSolvableException"/> class.
16+
/// </summary>
17+
/// <param name="message">The message that describes the error.</param>
918
public EquationNotSolvableException(string message) : base(message)
1019
{
1120
}

SharpMath/Expressions/Exceptions/ParserException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
// Improvements: Stefan Baumann 2016
23

34
using System;
45

56
namespace SharpMath.Expressions.Exceptions
67
{
8+
/// <summary>
9+
/// The exception that is thrown when the parser encountered an invalid token.
10+
/// </summary>
11+
/// <seealso cref="System.Exception" />
712
public class ParserException : Exception
813
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="ParserException"/> class.
16+
/// </summary>
17+
/// <param name="message">The message that describes the error.</param>
918
public ParserException(string message)
1019
: base(message)
1120
{

SharpMath/FloatingNumber.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
// Improvements: Stefan Baumann 2016
23

34
using System;
45

@@ -32,8 +33,8 @@ public static bool AreApproximatelyEqual(float firstNumber, float secondNumber)
3233
/// <param name="epsilon">The epsilon value that represents the tolerance.</param>
3334
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
3435
public static bool AreApproximatelyEqual(float firstNumber, float secondNumber, double epsilon)
35-
=> Math.Abs(firstNumber - secondNumber) <= Epsilon;
36-
36+
=> Math.Abs(firstNumber - secondNumber) <= epsilon;
37+
3738
/// <summary>
3839
/// Determines whether two floating numbers are approximately equal to each other using the <see cref="Epsilon" />
3940
/// value.
@@ -52,6 +53,6 @@ public static bool AreApproximatelyEqual(double firstNumber, double secondNumber
5253
/// <param name="epsilon">The epsilon value that represents the tolerance.</param>
5354
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
5455
public static bool AreApproximatelyEqual(double firstNumber, double secondNumber, double epsilon)
55-
=> Math.Abs(firstNumber - secondNumber) <= Epsilon;
56+
=> Math.Abs(firstNumber - secondNumber) <= epsilon;
5657
}
5758
}

SharpMath/FloatingNumberExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
// Improvements: Stefan Baumann 2016
23

34
namespace SharpMath
45
{
@@ -14,7 +15,7 @@ public static class FloatingNumberExtensions
1415
/// <param name="number">The current <see cref="float" />.</param>
1516
/// <param name="other">The other <see cref="float" />.</param>
1617
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
17-
public static bool AreApproximatelyEqual(this float number, float other)
18+
public static bool IsApproximatelyEqualTo(this float number, float other)
1819
=> FloatingNumber.AreApproximatelyEqual(number, other);
1920

2021
/// <summary>
@@ -24,7 +25,7 @@ public static bool AreApproximatelyEqual(this float number, float other)
2425
/// <param name="other">The other <see cref="float" />.</param>
2526
/// <param name="epsilon">The epsilon value that represents the tolerance.</param>
2627
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
27-
public static bool AreApproximatelyEqual(this float number, float other, double epsilon)
28+
public static bool IsApproximatelyEqualTo(this float number, float other, double epsilon)
2829
=> FloatingNumber.AreApproximatelyEqual(number, other, epsilon);
2930

3031
/// <summary>
@@ -34,7 +35,7 @@ public static bool AreApproximatelyEqual(this float number, float other, double
3435
/// <param name="number">The current <see cref="float" />.</param>
3536
/// <param name="other">The other <see cref="float" />.</param>
3637
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
37-
public static bool AreApproximatelyEqual(double number, double other)
38+
public static bool IsApproximatelyEqualTo(this double number, double other)
3839
=> FloatingNumber.AreApproximatelyEqual(number, other);
3940

4041
/// <summary>
@@ -44,7 +45,7 @@ public static bool AreApproximatelyEqual(double number, double other)
4445
/// <param name="other">The other <see cref="float" />.</param>
4546
/// <param name="epsilon">The epsilon value that represents the tolerance.</param>
4647
/// <returns>Returns <c>true</c>, if they are approximately equal, otherwise <c>false</c>.</returns>
47-
public static bool AreApproximatelyEqual(double number, double other, double epsilon)
48+
public static bool IsApproximatelyEqualTo(this double number, double other, double epsilon)
4849
=> FloatingNumber.AreApproximatelyEqual(number, other, epsilon);
4950
}
5051
}

SharpMath/Geometry/Exceptions/DimensionException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
// Improvements: Stefan Baumann 2016
23

34
using System;
45

56
namespace SharpMath.Geometry.Exceptions
67
{
8+
/// <summary>
9+
/// The exception that is thrown when the dimension count of two vectors is different.
10+
/// </summary>
11+
/// <seealso cref="System.Exception" />
712
public class DimensionException : Exception
813
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="DimensionException"/> class.
16+
/// </summary>
17+
/// <param name="message">The message that describes the error.</param>
918
public DimensionException(string message)
1019
: base(message)
1120
{

SharpMath/Geometry/Line2D.cs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
// Improvements: Stefan Baumann 2016
23

34
using System;
45

@@ -7,7 +8,7 @@ namespace SharpMath.Geometry
78
/// <summary>
89
/// Represents a line in a 2-dimensional room.
910
/// </summary>
10-
public class Line2D
11+
public class Line2D : IEquatable<Line2D>
1112
{
1213
/// <summary>
1314
/// Initializes a new instance of the <see cref="Line2D" /> class.
@@ -158,5 +159,77 @@ public Point2D GetPoint(double x)
158159
{
159160
return new Point2D(x, Slope*x + Offset);
160161
}
162+
163+
/// <summary>
164+
/// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
165+
/// </summary>
166+
/// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
167+
/// <returns>
168+
/// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
169+
/// </returns>
170+
public override bool Equals(object obj)
171+
{
172+
return obj == null ? this == null : obj is Line2D && ((Line2D)obj).Offset == Offset && ((Line2D)obj).Slope == Slope;
173+
}
174+
175+
/// <summary>
176+
/// Determines whether the specified <see cref="Line2D" /> is equal to this instance.
177+
/// </summary>
178+
/// <param name="other">The <see cref="Line2D" /> to compare with this instance.</param>
179+
/// <returns>
180+
/// <c>true</c> if the specified <see cref="Line2D" /> is equal to this instance; otherwise, <c>false</c>.
181+
/// </returns>
182+
public bool Equals(Line2D other)
183+
{
184+
return other == null ? this == null : other.Offset == Offset && other.Slope == Slope;
185+
}
186+
187+
/// <summary>
188+
/// Returns a hash code for this instance.
189+
/// </summary>
190+
/// <returns>
191+
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
192+
/// </returns>
193+
public override int GetHashCode()
194+
{
195+
return Offset.GetHashCode() ^ Slope.GetHashCode();
196+
}
197+
198+
/// <summary>
199+
/// Returns a <see cref="System.String" /> that represents this instance.
200+
/// </summary>
201+
/// <returns>
202+
/// A <see cref="System.String" /> that represents this instance.
203+
/// </returns>
204+
public override string ToString()
205+
{
206+
return string.Format("Line2D [Offset={0}; Slope={1}]", Offset, Slope);
207+
}
208+
209+
/// <summary>
210+
/// Determines whether the two specified <see cref="Line2D" /> instances are equal to each other.
211+
/// </summary>
212+
/// <param name="left">The first <see cref="Line2D" />.</param>
213+
/// <param name="right">The <see cref="Line2D" /> to compare with the other <see cref="Line2D" />.</param>
214+
/// <returns>
215+
/// <c>true</c> if the two specified <see cref="Line2D" /> are equal to each other; otherwise, <c>false</c>.
216+
/// </returns>
217+
public static bool operator ==(Line2D left, Line2D right)
218+
{
219+
return left.Equals(right);
220+
}
221+
222+
/// <summary>
223+
/// Determines whether the two specified <see cref="Line2D" /> instances are not equal to each other.
224+
/// </summary>
225+
/// <param name="left">The first <see cref="Line2D" />.</param>
226+
/// <param name="right">The <see cref="Line2D" /> to compare with the other <see cref="Line2D" />.</param>
227+
/// <returns>
228+
/// <c>true</c> if the two specified <see cref="Line2D" /> are not equal to each other; otherwise, <c>false</c>.
229+
/// </returns>
230+
public static bool operator !=(Line2D left, Line2D right)
231+
{
232+
return !left.Equals(right);
233+
}
161234
}
162235
}

SharpMath/Geometry/Line3D.cs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
// Improvements: Stefan Baumann 2016
23

34
using System;
45

@@ -7,7 +8,7 @@ namespace SharpMath.Geometry
78
/// <summary>
89
/// Represents a 3D-line.
910
/// </summary>
10-
public class Line3D
11+
public class Line3D : IEquatable<Line3D>
1112
{
1213
private Vector3 _direction;
1314

@@ -81,5 +82,77 @@ public bool IsPointOnLine(Point3D point)
8182

8283
return true;
8384
}
85+
86+
/// <summary>
87+
/// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
88+
/// </summary>
89+
/// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
90+
/// <returns>
91+
/// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
92+
/// </returns>
93+
public override bool Equals(object obj)
94+
{
95+
return obj == null ? this == null : obj is Line3D && ((Line3D)obj).Direction == Direction && ((Line3D)obj).Point == Point;
96+
}
97+
98+
/// <summary>
99+
/// Determines whether the specified <see cref="Line3D" /> is equal to this instance.
100+
/// </summary>
101+
/// <param name="other">The <see cref="Line3D" /> to compare with this instance.</param>
102+
/// <returns>
103+
/// <c>true</c> if the specified <see cref="Line3D" /> is equal to this instance; otherwise, <c>false</c>.
104+
/// </returns>
105+
public bool Equals(Line3D other)
106+
{
107+
return other == null ? this == null : other.Direction == Direction && other.Point == Point;
108+
}
109+
110+
/// <summary>
111+
/// Returns a hash code for this instance.
112+
/// </summary>
113+
/// <returns>
114+
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
115+
/// </returns>
116+
public override int GetHashCode()
117+
{
118+
return Direction.GetHashCode() ^ Point.GetHashCode();
119+
}
120+
121+
/// <summary>
122+
/// Returns a <see cref="System.String" /> that represents this instance.
123+
/// </summary>
124+
/// <returns>
125+
/// A <see cref="System.String" /> that represents this instance.
126+
/// </returns>
127+
public override string ToString()
128+
{
129+
return string.Format("Line3D [Direction={0}; Point={1}]", Direction, Point);
130+
}
131+
132+
/// <summary>
133+
/// Determines whether the two specified <see cref="Line3D" /> instances are equal to each other.
134+
/// </summary>
135+
/// <param name="left">The first <see cref="Line3D" />.</param>
136+
/// <param name="right">The <see cref="Line3D" /> to compare with the other <see cref="Line3D" />.</param>
137+
/// <returns>
138+
/// <c>true</c> if the two specified <see cref="Line3D" /> are equal to each other; otherwise, <c>false</c>.
139+
/// </returns>
140+
public static bool operator ==(Line3D left, Line3D right)
141+
{
142+
return left.Equals(right);
143+
}
144+
145+
/// <summary>
146+
/// Determines whether the two specified <see cref="Line3D" /> instances are not equal to each other.
147+
/// </summary>
148+
/// <param name="left">The first <see cref="Line3D" />.</param>
149+
/// <param name="right">The <see cref="Line3D" /> to compare with the other <see cref="Line3D" />.</param>
150+
/// <returns>
151+
/// <c>true</c> if the two specified <see cref="Line3D" /> are not equal to each other; otherwise, <c>false</c>.
152+
/// </returns>
153+
public static bool operator !=(Line3D left, Line3D right)
154+
{
155+
return !left.Equals(right);
156+
}
84157
}
85158
}

SharpMath/Geometry/Point.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
// Improvements: Stefan Baumann 2016
23

34
using System;
45
using System.Collections;
@@ -97,7 +98,11 @@ public Vector PositionVector
9798
/// </returns>
9899
public IEnumerator<double> GetEnumerator()
99100
{
100-
return new PointEnumerator(this);
101+
for (int i = 0; i < this.Dimension; i++)
102+
{
103+
yield return this[(uint)i];
104+
}
105+
yield break;
101106
}
102107

103108
/// <summary>
@@ -108,7 +113,11 @@ public IEnumerator<double> GetEnumerator()
108113
/// </returns>
109114
IEnumerator IEnumerable.GetEnumerator()
110115
{
111-
return new PointEnumerator(this);
116+
for (int i = 0; i < this.Dimension; i++)
117+
{
118+
yield return this[(uint)i];
119+
}
120+
yield break;
112121
}
113122

114123
public bool Equals(Point other)

SharpMath/Geometry/PointEnumerator.cs

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

0 commit comments

Comments
 (0)