Skip to content

Commit

Permalink
Merge pull request #250 from GSharker/dev/mibi/fix-isClose
Browse files Browse the repository at this point in the history
Fixed problem for isClosed.
  • Loading branch information
sonomirco authored Aug 19, 2021
2 parents 8b7a97d + 6a0094b commit 67c83c5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/GShark.Test.XUnit/Geometry/NurbsCurveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void It_Returns_True_If_A_NurbsCurve_Is_Closed()
{
// Assert
NurbsCurveCollection.NurbsCurveWithStartingAndEndPointOverlapping().IsClosed().Should().BeTrue();
NurbsCurveCollection.PeriodicClosedNurbsCurve().IsClosed().Should().BeTrue();
}

[Fact]
Expand Down
21 changes: 5 additions & 16 deletions src/GShark.Test.XUnit/Geometry/NurbsSurfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void It_Returns_A_Normal_Lofted_Surface_By_Opened_Curves(double u, double
Point3 expectedPt = new Point3(pt[0], pt[1], pt[2]);

// Act
NurbsSurface surface = NurbsSurface.CreateLoftedSurface(crvs, 3, LoftType.Normal);
NurbsSurface surface = NurbsSurface.CreateLoftedSurface(crvs);
Point4 evalPt = Evaluation.SurfacePointAt(surface, u, v);

// Assert
Expand Down Expand Up @@ -120,11 +120,8 @@ public void It_Returns_A_Loose_Lofted_Surface_By_Opened_Curves(double u, double
[Fact]
public void Lofted_Surface_Throws_An_Exception_If_The_Curves_Are_Null()
{
// Arange
List<NurbsCurve> curves = null;

// Act
Func<NurbsSurface> func = () => NurbsSurface.CreateLoftedSurface(curves);
Func<NurbsSurface> func = () => NurbsSurface.CreateLoftedSurface(null);

// Assert
func.Should().Throw<Exception>()
Expand Down Expand Up @@ -153,7 +150,7 @@ public void Lofted_Surface_Throws_An_Exception_If_There_Are_Null_Curves()
crvs.Add(null);

// Act
Func<NurbsSurface> func = () => NurbsSurface.CreateLoftedSurface(crvs, 3, LoftType.Loose);
Func<NurbsSurface> func = () => NurbsSurface.CreateLoftedSurface(crvs);

// Assert
func.Should().Throw<Exception>()
Expand All @@ -164,16 +161,10 @@ public void Lofted_Surface_Throws_An_Exception_If_There_Are_Null_Curves()
public void Lofted_Surface_Throws_An_Exception_If_Curves_Count_Are_Less_Than_Two()
{
// Arrange
List<Point3> pts1 = new List<Point3> { new Point3(-20.0, 0.0, 0.0),
new Point3(0.0, 0.0, 10.0),
new Point3(10.0, 0.0, 0.0) };

NurbsCurve crv = new NurbsCurve(pts1, 2);

List<NurbsCurve> crvs = new List<NurbsCurve>() { crv };
NurbsCurve[] crvs = { NurbsCurveCollection.OpenCurves()[0] };

// Act
Func<NurbsSurface> func = () => NurbsSurface.CreateLoftedSurface(crvs, 0);
Func<NurbsSurface> func = () => NurbsSurface.CreateLoftedSurface(crvs);

// Assert
func.Should().Throw<Exception>()
Expand All @@ -191,8 +182,6 @@ public void Lofted_Surface_Throws_An_Exception_If_The_All_Curves_Are_Not_Closed_
Func<NurbsSurface> func = () => NurbsSurface.CreateLoftedSurface(crvs);

// Assert
crvs[0].IsClosed().Should().BeFalse();
crvs[1].IsPeriodic().Should().BeTrue();
func.Should().Throw<Exception>()
.WithMessage("Loft only works if all curves are open, or all curves are closed.");
}
Expand Down
4 changes: 3 additions & 1 deletion src/GShark/Geometry/NurbsCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ public BoundingBox BoundingBox
/// <returns>True if the curve is closed.</returns>
public bool IsClosed()
{
return !(LocationPoints[0].DistanceTo(LocationPoints[LocationPoints.Count - 1]) > 0);
Point3 pt0 = Evaluation.CurvePointAt(this,Domain.T0);
Point3 pt1 = Evaluation.CurvePointAt(this, Domain.T1);
return pt0.EpsilonEquals(pt1, GSharkMath.Epsilon);
}

/// <summary>
Expand Down
17 changes: 8 additions & 9 deletions src/GShark/Geometry/NurbsSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,28 +156,27 @@ public static NurbsSurface CreateFromPoints(int degreeU, int degreeV, List<List<
/// <summary>
/// Constructs a NURBS surface from a set of NURBS curves.<br/>
/// </summary>
/// <param name="crvs">Set of a minimum of two curves to create the surface.</param>
/// <param name="curves">Set of a minimum of two curves to create the surface.</param>
/// <param name="degreeV">Degree of surface in V direction.</param>
/// <param name="loftType">Enum to choose the type of loft generation.</param>
/// <returns>A NURBS surface.</returns>
public static NurbsSurface CreateLoftedSurface(List<NurbsCurve> curves, int degreeV = 3, LoftType loftType = LoftType.Normal)
public static NurbsSurface CreateLoftedSurface(IList<NurbsCurve> curves, int degreeV = 3, LoftType loftType = LoftType.Normal)
{
if (curves == null)
throw new ArgumentException("An invalid number of curves to perform the loft.");

if (curves.Count < 2)
throw new ArgumentException("An invalid number of curves to perform the loft.");

if (degreeV > curves.Count - 1)
throw new ArgumentException("The degreeV of the surface cannot be greater than the number of curves minus one.");

if (curves.Any(x => x == null))
throw new ArgumentException("The input set contains null curves.");

if(curves.Count < 2)
throw new ArgumentException("An invalid number of curves to perform the loft.");

//Replace IsPerdiodic() with IsClosed() when the issue is solved
bool isClosed = curves[0].IsPeriodic();
foreach (NurbsCurve c in curves)
if (isClosed != c.IsPeriodic())
bool isClosed = curves[0].IsClosed();
foreach (NurbsCurve c in curves.Skip(1))
if (isClosed != c.IsClosed())
throw new ArgumentException("Loft only works if all curves are open, or all curves are closed.");

int degreeU = curves[0].Degree;
Expand Down

0 comments on commit 67c83c5

Please sign in to comment.