Skip to content

Commit

Permalink
Merge pull request #357 from GSharker/dev/mibi/creation-analyze-names…
Browse files Browse the repository at this point in the history
…pace

Created namespace Analyze
  • Loading branch information
sonomirco committed Sep 10, 2021
2 parents 0c34597 + 1b12f96 commit 4ae7c57
Show file tree
Hide file tree
Showing 14 changed files with 814 additions and 785 deletions.
123 changes: 123 additions & 0 deletions src/GShark.Test.XUnit/Analyze/CurveTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using FluentAssertions;
using GShark.Core;
using GShark.Geometry;
using GShark.Test.XUnit.Data;
using System.Collections.Generic;
using Xunit;
using Xunit.Abstractions;

namespace GShark.Test.XUnit.Analyze
{
public class CurveTests
{
private readonly ITestOutputHelper _testOutput;

public CurveTests(ITestOutputHelper testOutput)
{
_testOutput = testOutput;
}

[Fact]
public void It_Returns_The_Approximated_Length_Of_A_Bezier()
{
// Arrange
int degree = 3;
List<Point3> pts = new List<Point3>
{
new Point3(0, 0, 0),
new Point3(0.5, 0, 0),
new Point3(2.5, 0, 0),
new Point3(3, 0, 0)
};

NurbsCurve curve = new NurbsCurve(pts, degree);
double expectedLength = 3.0;

// Act
double curveLength = curve.Length;

// Assert
curveLength.Should().BeApproximately(expectedLength, GSharkMath.MaxTolerance);
}

[Fact]
public void It_Returns_Parameter_At_The_Given_Length_Of_A_Bezier()
{
// Arrange
NurbsBase curve = NurbsBaseCollection.NurbsPlanarExample();
double[] tValuesExpected = new[] { 0, 0.122941, 0.265156, 0.420293, 0.579707, 0.734844, 0.877059, 1 };

int steps = 7;
double length = curve.Length / steps;
double sumLengths = 0.0;

for (int i = 0; i < steps + 1; i++)
{
// Act
double t = curve.ParameterAtLength(sumLengths);
double segmentLength = curve.LengthAt(t);

// Assert
t.Should().BeApproximately(tValuesExpected[i], GSharkMath.MaxTolerance);
segmentLength.Should().BeApproximately(sumLengths, GSharkMath.MaxTolerance);

sumLengths += length;
}
}

[Fact]
public void It_Returns_The_Length_Of_The_Curve()
{
// Arrange
NurbsBase curve = NurbsBaseCollection.NurbsPlanarExample();
double expectedLength = 50.334675;

// Act
double crvLength = curve.Length;

// Assert
crvLength.Should().BeApproximately(expectedLength, GSharkMath.MinTolerance);
}

[Theory]
[InlineData(new double[] { 5, 7, 0 }, new double[] { 5.982099, 5.950299, 0 }, 0.021824)]
[InlineData(new double[] { 12, 10, 0 }, new double[] { 11.781824, 10.364244, 0 }, 0.150707)]
[InlineData(new double[] { 21, 17, 0 }, new double[] { 21.5726, 14.101932, 0 }, 0.36828)]
[InlineData(new double[] { 32, 15, 0 }, new double[] { 31.906562, 14.36387, 0 }, 0.597924)]
[InlineData(new double[] { 41, 8, 0 }, new double[] { 42.554645, 10.750437, 0 }, 0.834548)]
[InlineData(new double[] { 50, 5, 0 }, new double[] { 50, 5, 0 }, 1.0)]
public void It_Returns_The_Closest_Point_And_Parameter(double[] ptToCheck, double[] ptExpected, double tValExpected)
{
// Arrange
NurbsBase curve = NurbsBaseCollection.NurbsPlanarExample();
Point3 testPt = new Point3(ptToCheck[0], ptToCheck[1], ptToCheck[2]);
Point3 expectedPt = new Point3(ptExpected[0], ptExpected[1], ptExpected[2]);

// Act
Point3 pt = curve.ClosestPoint(testPt);
double parameter = curve.ClosestParameter(testPt);

// Assert
parameter.Should().BeApproximately(tValExpected, GSharkMath.MaxTolerance);
pt.EpsilonEquals(expectedPt, GSharkMath.MaxTolerance).Should().BeTrue();
}

[Theory]
[InlineData(0, 0)]
[InlineData(15, 0.278127)]
[InlineData(33, 0.672164)]
[InlineData(46, 0.928308)]
[InlineData(50.334675, 1)]
public void It_Returns_Parameter_At_The_Given_Length(double segmentLength, double tValueExpected)
{
// Arrange
NurbsBase curve = NurbsBaseCollection.NurbsPlanarExample();

// Act
double parameter = curve.ParameterAtLength(segmentLength);

// Assert
parameter.Should().BeApproximately(tValueExpected, GSharkMath.MinTolerance);
}
}
}
71 changes: 71 additions & 0 deletions src/GShark.Test.XUnit/Analyze/SurfaceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using FluentAssertions;
using GShark.Core;
using GShark.Enumerations;
using GShark.Geometry;
using GShark.Test.XUnit.Data;
using Xunit;
using Xunit.Abstractions;

namespace GShark.Test.XUnit.Analyze
{
public class SurfaceTests
{
private readonly ITestOutputHelper _testOutput;

public SurfaceTests(ITestOutputHelper testOutput)
{
_testOutput = testOutput;
}

[Theory]
[InlineData(0.204157623157292, 0.716170472509343, new double[] { 2.5, 7, 5 })]
[InlineData(0.237211551442712, 0.154628316784507, new double[] { 2.5, 1.5, 2 })]
[InlineData(0.910119163727208, 0.229417610613794, new double[] { 9, 2.5, 1 })]
[InlineData(0.50870054333679, 0.360138133269618, new double[] { 5, 5, 1 })]
public void It_Returns_Parameter_U_V_Of_A_Closest_Point(double u, double v, double[] testPt)
{
// Arrange
NurbsSurface surface = NurbsSurfaceCollection.SurfaceFromPoints();
Point3 pt = new Point3(testPt[0], testPt[1], testPt[2]);
(double u, double v) expectedUV = (u, v);

// Act
var closestParameter = surface.ClosestParameter(pt);

// Assert
(closestParameter.U - expectedUV.u).Should().BeLessThan(GSharkMath.MaxTolerance);
(closestParameter.V - expectedUV.v).Should().BeLessThan(GSharkMath.MaxTolerance);
}

[Fact]
public void Returns_The_Surface_Isocurve_At_U_Direction()
{
// Arrange
NurbsSurface surface = NurbsSurfaceCollection.SurfaceFromPoints();
Point3 expectedPt = new Point3(3.591549, 10, 4.464789);

// Act
NurbsBase Isocurve = surface.IsoCurve(0.3, SurfaceDirection.U);

// Assert
Isocurve.ControlPointLocations[1].DistanceTo(expectedPt).Should().BeLessThan(GSharkMath.MinTolerance);
}

[Fact]
public void Returns_The_Surface_Isocurve_At_V_Direction()
{
// Arrange
NurbsSurface surface = NurbsSurfaceCollection.SurfaceFromPoints();
Point3 expectedPt = new Point3(5, 4.615385, 2.307692);
Point3 expectedPtAt = new Point3(5, 3.913043, 1.695652);

// Act
NurbsBase Isocurve = surface.IsoCurve(0.3, SurfaceDirection.V);
Point3 ptAt = Isocurve.PointAt(0.5);

// Assert
Isocurve.ControlPointLocations[1].DistanceTo(expectedPt).Should().BeLessThan(GSharkMath.MinTolerance);
ptAt.DistanceTo(expectedPtAt).Should().BeLessThan(GSharkMath.MinTolerance);
}
}
}
2 changes: 1 addition & 1 deletion src/GShark.Test.XUnit/Core/TrigonometryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void It_Returns_The_Closest_Point_On_A_Segment(double[] ptToCheck, double
Point3 pt1 = new Point3(10, 10, 0);

// Act
(double tValue, Point3 pt) closestPt = Analyze.ClosestPointToSegment(testPt, pt0, pt1, 0, 1);
(double tValue, Point3 pt) closestPt = Trigonometry.ClosestPointToSegment(testPt, pt0, pt1, 0, 1);

// Assert
closestPt.tValue.Should().BeApproximately(tValExpected, GSharkMath.MaxTolerance);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using FluentAssertions;
using GShark.Core;
using GShark.Geometry;
using GShark.Operation;
using System.Collections.Generic;
using GShark.Intersection;
using System.Collections.Generic;
using Xunit;
using Xunit.Abstractions;

namespace GShark.Test.XUnit.Operation
namespace GShark.Test.XUnit.Intersection
{
public class IntersectionTests
{
Expand Down
176 changes: 0 additions & 176 deletions src/GShark.Test.XUnit/Operation/AnalyzeTests.cs

This file was deleted.

Loading

0 comments on commit 4ae7c57

Please sign in to comment.