Skip to content

Commit

Permalink
Merge pull request #406 from chuongmep/checkisonline
Browse files Browse the repository at this point in the history
Add method point is on line
  • Loading branch information
sonomirco authored Feb 4, 2023
2 parents 3c1addd + c266b11 commit f01109a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/GShark.Test.XUnit/Geometry/Point3Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentAssertions;
using System.Security.Cryptography.X509Certificates;
using FluentAssertions;
using GShark.Geometry;
using haxe.ds;
using Xunit;
Expand Down Expand Up @@ -58,6 +59,25 @@ public void It_Checks_If_A_Point_Lies_On_A_Plane()
pt.IsOnPlane(plane, 0.001).Should().BeTrue();
}

[Fact]
public void It_Check_Point_Is_On_Line()
{
//Arrange
Point3 p1 = new Point3(0, 5, 0);
Point3 p2 = new Point3(0, 20, 0);
Point3 p3 = new Point3(0, 0, 0);
Line line1 = new Line(new Point3(0,0,0), new Point3(0,10,0));
// Act
bool isOnLine = p2.IsOnLine(line1);
bool isOnLine1 = p1.IsOnLine(line1);
bool isOnLine2 = p3.IsOnLine(line1);
// Assert
Assert.False(isOnLine);
Assert.True(isOnLine1);
Assert.True(isOnLine2);

}

[Fact]
public void It_Returns_The_Linear_Interpolation_Between_Two_Points()
{
Expand Down
11 changes: 11 additions & 0 deletions src/GShark/Geometry/Point3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,17 @@ public bool IsOnPlane(Plane plane, double tolerance = GSharkMath.MaxTolerance)
{
return Math.Abs(Vector3.DotProduct(this - plane.Origin, plane.ZAxis)) < tolerance;
}

/// <summary>
/// Test whether a point lies on a line.
/// </summary>
/// <param name="line">The line to test against.</param>
/// <param name="tolerance">Default is use 1e-6</param>
/// <returns>Returns true if point is on plane.</returns>
public bool IsOnLine(Line line, double tolerance = GSharkMath.MaxTolerance)
{
return line.ClosestPoint(this).DistanceTo(this) < tolerance;
}

/// <summary>
/// Tests whether a point is inside, outside, or coincident with a polygon.
Expand Down

0 comments on commit f01109a

Please sign in to comment.