Skip to content

Commit 847cdaf

Browse files
committed
Revert "Feat: Line2D.DistanceTo(point)"
This reverts commit 0a2521d.
1 parent f3e4731 commit 847cdaf

2 files changed

Lines changed: 6 additions & 86 deletions

File tree

src/Spatial.Tests/Euclidean/Line2DTests.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -210,30 +210,5 @@ public void ToStringCheck()
210210

211211
Assert.AreEqual("StartPoint: (0,\u00A00), EndPoint: (1,\u00A01)", check);
212212
}
213-
214-
[TestCase("0,0", "1,0", "0,1",-1)]
215-
[TestCase("0,0", "1,0", "0,2", -2)]
216-
[TestCase("0,0", "0,1", "2,0", +2)]
217-
public void SignedDistanceTo(string sp1, string sp2, string sp, double expectedDistance)
218-
{
219-
var line = Line2D.Parse(sp1, sp2);
220-
var point = Point2D.Parse(sp);
221-
222-
var actual = line.SignedDistanceTo(point);
223-
Assert.That(actual, Is.EqualTo(expectedDistance));
224-
}
225-
226-
227-
[TestCase("0,0", "1,0", "0,1", 1)]
228-
[TestCase("0,0", "1,0", "0,2", 2)]
229-
[TestCase("0,0", "0,1", "2,0", 2)]
230-
public void DistanceTo(string sp1, string sp2, string sp, double expectedDistance)
231-
{
232-
var line = Line2D.Parse(sp1, sp2);
233-
var point = Point2D.Parse(sp);
234-
235-
var actual = line.DistanceTo(point);
236-
Assert.That(actual, Is.EqualTo(expectedDistance));
237-
}
238213
}
239214
}

src/Spatial/Euclidean/Line2D.cs

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using MathNet.Numerics;
2-
using MathNet.Spatial.Internals;
3-
using MathNet.Spatial.Units;
4-
using System;
1+
using System;
52
using System.Diagnostics.Contracts;
6-
using System.Xml;
7-
using System.Xml.Linq;
83
using System.Xml.Schema;
4+
using System.Xml;
95
using System.Xml.Serialization;
6+
using MathNet.Numerics;
7+
using MathNet.Spatial.Internals;
8+
using MathNet.Spatial.Units;
9+
using System.Xml.Linq;
1010

1111
namespace MathNet.Spatial.Euclidean
1212
{
@@ -27,21 +27,6 @@ public struct Line2D : IEquatable<Line2D>, IXmlSerializable
2727
/// </summary>
2828
public Point2D EndPoint { get; private set; }
2929

30-
/// <summary>
31-
/// The parameter `a` in the line equation: ax + by + c = 0
32-
/// </summary>
33-
public double A { get; private set; }
34-
35-
/// <summary>
36-
/// The parameter `b` in the line equation: ax + by + c = 0
37-
/// </summary>
38-
public double B { get; private set; }
39-
40-
/// <summary>
41-
/// The parameter `c` in the line equation: ax + by + c = 0
42-
/// </summary>
43-
public double C { get; private set; }
44-
4530
/// <summary>
4631
/// Initializes a new instance of the <see cref="Line2D"/> struct.
4732
/// Throws an ArgumentException if the <paramref name="startPoint"/> is equal to the <paramref name="endPoint"/>.
@@ -55,27 +40,8 @@ public Line2D(Point2D startPoint, Point2D endPoint)
5540
throw new ArgumentException("The Line2D starting and ending points cannot be identical");
5641
}
5742

58-
//substitution
59-
//points
6043
StartPoint = startPoint;
6144
EndPoint = endPoint;
62-
63-
//doubles
64-
var x1 = startPoint.X;
65-
var x2 = endPoint.X;
66-
var y1 = startPoint.Y;
67-
var y2 = endPoint.Y;
68-
69-
//computation
70-
var a = y2 - y1;
71-
var b = x1 - x2;
72-
var c = (x2 - x1) * y1 - (y2 - y1) * x1;
73-
74-
//normalize
75-
var length = Math.Sqrt(a * a + b * b);
76-
A = a / length;
77-
B = b / length;
78-
C = c / length;
7945
}
8046

8147
/// <summary>
@@ -328,26 +294,5 @@ void IXmlSerializable.WriteXml(XmlWriter writer)
328294
writer.WriteElement("StartPoint", StartPoint);
329295
writer.WriteElement("EndPoint", EndPoint);
330296
}
331-
332-
/// <summary>
333-
/// Compute the signed distance from this `line` to the given point `p`. If the sign of the distance is positive, the normal vector from the line is in the same side to the point.
334-
/// </summary>
335-
/// <param name="p"></param>
336-
/// <returns></returns>
337-
public double SignedDistanceTo(Point2D p)
338-
{
339-
var result = A * p.X + B * p.Y + C;
340-
return result;
341-
}
342-
343-
/// <summary>
344-
/// Compute the absolute distance from this `line` to the given point `p`.
345-
/// </summary>
346-
/// <param name="p"></param>
347-
/// <returns></returns>
348-
public double DistanceTo(Point2D p)
349-
{
350-
return Math.Abs(SignedDistanceTo(p));
351-
}
352297
}
353298
}

0 commit comments

Comments
 (0)