Skip to content

Commit 8cae855

Browse files
Add Vector2D.ToPoint2D() method with unit test (#235)
* Add Vector2D.ToPoint2D() method with unit test * Improve comments --------- Co-authored-by: Michele Castellazzi <michele.castellazzi@technoprobe.com>
1 parent f607991 commit 8cae855

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/Spatial.Tests/Euclidean/Point2DTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ public void DistanceTo(string p1s, string p2s, double expected)
146146
Assert.AreEqual(expected, p2.DistanceTo(p1));
147147
}
148148

149+
[TestCase("-1 ; 2")]
150+
public void ToVectorAndBack(string ps)
151+
{
152+
var p = Point2D.Parse(ps);
153+
AssertGeometry.AreEqual(p, p.ToVector2D().ToPoint2D(), 1e-9);
154+
}
155+
149156
[TestCase("0, 0", "1, 2", "0.5, 1")]
150157
[TestCase("-1, -2", "1, 2", "0, 0")]
151158
public void MidPoint(string p1s, string p2s, string eps)

src/Spatial/Euclidean/Vector2D.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,15 @@ public Vector2D Add(Vector2D v)
475475
return new Vector2D(X + v.X, Y + v.Y);
476476
}
477477

478+
/// <summary>
479+
/// Returns a point, whose position vector is equal to the current vector
480+
/// </summary>
481+
/// <returns>A point</returns>
482+
public Point2D ToPoint2D()
483+
{
484+
return new Point2D(this.X, this.Y);
485+
}
486+
478487
/// <summary>
479488
/// Transforms a vector by multiplying it against a provided matrix
480489
/// </summary>

src/Spatial/Euclidean/Vector3D.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public Vector3D Rotate(UnitVector3D about, Angle angle)
523523
}
524524

525525
/// <summary>
526-
/// Returns a point equivalent to the vector
526+
/// Returns a point, whose position vector is equal to the current vector
527527
/// </summary>
528528
/// <returns>A point</returns>
529529
public Point3D ToPoint3D()

0 commit comments

Comments
 (0)