Skip to content

Commit

Permalink
Merge pull request #368 from GSharker/dev/mibi/revolved-surface
Browse files Browse the repository at this point in the history
Revolved Surface
  • Loading branch information
sonomirco committed Sep 26, 2021
2 parents 4e0c4e6 + 54d3de2 commit 4010fdc
Show file tree
Hide file tree
Showing 9 changed files with 6,077 additions and 33 deletions.
5,764 changes: 5,764 additions & 0 deletions GeometrySharkIcons.ai

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/GShark.Test.XUnit/Data/NurbsSurfaceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static NurbsSurface QuadrilateralSurface()
Point3 p3 = new Point3(10.0, 10.0, 2.0);
Point3 p4 = new Point3(0.0, 10.0, 4.0);

NurbsSurface surface = NurbsSurface.CreateFromCorners(p1, p2, p3, p4);
NurbsSurface surface = NurbsSurface.FromCorners(p1, p2, p3, p4);
#endregion

return surface;
Expand All @@ -35,7 +35,7 @@ public static NurbsSurface SurfaceFromPoints()
new List<double>{1, 1},
};

return NurbsSurface.CreateFromPoints(2, 1, pts, weight);
return NurbsSurface.FromPoints(2, 1, pts, weight);
}

public static NurbsSurface Loft()
Expand Down Expand Up @@ -87,7 +87,7 @@ public static NurbsSurface Loft()
NurbsCurve crv2 = new NurbsCurve(pts3, 3);
List<NurbsBase> crvs = new List<NurbsBase> { ln, crv0, poly, crv1, crv2 };

return NurbsSurface.CreateLoftedSurface(crvs);
return NurbsSurface.Lofted(crvs);
}
}
}
Binary file removed src/GShark.Test.XUnit/DebugFiles/GHDebugSurface.gh
Binary file not shown.
Binary file not shown.
154 changes: 141 additions & 13 deletions src/GShark.Test.XUnit/Geometry/NurbsSurfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using GShark.Core;
using GShark.Enumerations;
using GShark.Geometry;
using GShark.Operation;
using GShark.Test.XUnit.Data;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -32,8 +31,8 @@ public void It_Returns_A_NURBS_Surface_By_Four_Points()
Point3 expectedPt = new Point3(5.0, 5.0, 1.5);

// Act
NurbsSurface surfaceCcw = NurbsSurface.CreateFromCorners(p1, p2, p3, p4);
NurbsSurface surfaceCw = NurbsSurface.CreateFromCorners(p1, p4, p3, p2);
NurbsSurface surfaceCcw = NurbsSurface.FromCorners(p1, p2, p3, p4);
NurbsSurface surfaceCw = NurbsSurface.FromCorners(p1, p4, p3, p2);
Point3 evalPtCcw = new Point3(surfaceCcw.PointAt(0.5, 0.5));
Point3 evalPtCw = new Point3(surfaceCw.PointAt(0.5, 0.5));

Expand Down Expand Up @@ -89,7 +88,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(NurbsCurveCollection.OpenCurves());
NurbsSurface surface = NurbsSurface.Lofted(NurbsBaseCollection.OpenNurbs());
Point3 evalPt = surface.PointAt(u, v);

// Assert
Expand All @@ -107,7 +106,7 @@ public void It_Returns_A_Loose_Lofted_Surface_By_Opened_Curves(double u, double
Point3 expectedPt = new Point3(pt[0], pt[1], pt[2]);

// Act
NurbsSurface surface = NurbsSurface.CreateLoftedSurface(NurbsCurveCollection.OpenCurves(), LoftType.Loose);
NurbsSurface surface = NurbsSurface.Lofted(NurbsBaseCollection.OpenNurbs(), LoftType.Loose);
Point3 evalPt = surface.PointAt(u, v);

// Assert
Expand All @@ -125,7 +124,7 @@ public void It_Returns_A_Loose_Lofted_Surface_By_Closed_Curves(double u, double
Point3 expectedPt = new Point3(pt[0], pt[1], pt[2]);

// Act
NurbsSurface surface = NurbsSurface.CreateLoftedSurface(NurbsCurveCollection.ClosedCurves(), LoftType.Loose);
NurbsSurface surface = NurbsSurface.Lofted(NurbsBaseCollection.ClosedNurbs(), LoftType.Loose);
Point3 evalPt = surface.PointAt(u, v);

// Assert
Expand All @@ -137,7 +136,7 @@ public void It_Returns_A_Loose_Lofted_Surface_By_Closed_Curves(double u, double
public void Lofted_Surface_Throws_An_Exception_If_The_Curves_Are_Null()
{
// Act
Func<NurbsSurface> func = () => NurbsSurface.CreateLoftedSurface(null);
Func<NurbsSurface> func = () => NurbsSurface.Lofted(null);

// Assert
func.Should().Throw<Exception>()
Expand All @@ -152,7 +151,7 @@ public void Lofted_Surface_Throws_An_Exception_If_There_Are_Null_Curves()
crvs.Add(null);

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

// Assert
func.Should().Throw<Exception>()
Expand All @@ -166,7 +165,7 @@ public void Lofted_Surface_Throws_An_Exception_If_Curves_Count_Are_Less_Than_Two
NurbsBase[] crvs = { NurbsCurveCollection.OpenCurves()[0] };

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

// Assert
func.Should().Throw<Exception>()
Expand All @@ -181,7 +180,7 @@ public void Lofted_Surface_Throws_An_Exception_If_The_All_Curves_Are_Not_Closed_
crvs[1] = crvs[1].Close();

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

// Assert
func.Should().Throw<Exception>()
Expand Down Expand Up @@ -222,7 +221,7 @@ public void Returns_True_If_Two_Surfaces_Are_Equals()
public void Returns_True_If_Surface_Is_Close()
{
// Act
NurbsSurface surface = NurbsSurface.CreateLoftedSurface(NurbsCurveCollection.ClosedCurves(), LoftType.Loose);
NurbsSurface surface = NurbsSurface.Lofted(NurbsBaseCollection.ClosedNurbs(), LoftType.Loose);

// Assert
surface.IsClosed(SurfaceDirection.V).Should().BeTrue();
Expand Down Expand Up @@ -258,7 +257,7 @@ public void Returns_A_Ruled_Surface_Between_Two_Nurbs_Curve(double u, double v,
NurbsCurve curveB = new NurbsCurve(ptsB, 2);

// Act
NurbsSurface ruledSurface = NurbsSurface.CreateRuledSurface(curveA, curveB);
NurbsSurface ruledSurface = NurbsSurface.Ruled(curveA, curveB);
Point3 pointAt = ruledSurface.PointAt(u, v);

// Assert
Expand Down Expand Up @@ -295,11 +294,140 @@ public void Returns_A_Ruled_Surface_Between_A_Polyline_And_A_Nurbs_Curve(double
NurbsCurve curveB = new NurbsCurve(ptsB, 2);

// Act
NurbsSurface ruledSurface = NurbsSurface.CreateRuledSurface(poly, curveB);
NurbsSurface ruledSurface = NurbsSurface.Ruled(poly, curveB);
Point3 pointAt = ruledSurface.PointAt(u, v);

// Assert
pointAt.EpsilonEquals(expectedPt, GSharkMath.MinTolerance).Should().BeTrue();
}

[Fact]
public void It_Returns_A_Revolved_Surface_From_A_Line()
{
// Arrange
Ray axis = new Ray(Point3.Origin, Vector3.ZAxis);
Line profile = new Line(new Point3(1, 0, 0), new Point3(0, 0, 1));

List<List<Point3>> expectedPts0 = new List<List<Point3>>
{
new List<Point3>
{
new Point3(1, 0, 0),
new Point3(0, 0, 1)
},
new List<Point3>
{
new Point3(1, 0.41421356237309526, 0),
new Point3(0, 0, 1)
},
new List<Point3>
{
new Point3(0.7071067811865476,0.7071067811865476,0),
new Point3(0,0,1)
}
};
List<List<Point3>> expectedPts1 = new List<List<Point3>>
{
new List<Point3>
{
new Point3(1, 0, 0),
new Point3(0, 0, 1)
},
new List<Point3>
{
new Point3(1, 1, 0),
new Point3(0, 0, 1)
},
new List<Point3>
{
new Point3(0,1,0),
new Point3(0,0,1)
},
new List<Point3>
{
new Point3(-1,1,0),
new Point3(0,0,1)
},
new List<Point3>
{
new Point3(-1,0,0),
new Point3(0,0,1)
},
new List<Point3>
{
new Point3(-1,-1,0),
new Point3(0,0,1)
},
new List<Point3>
{
new Point3(0,-1,0),
new Point3(0,0,1)
},
new List<Point3>
{
new Point3(1,-1,0),
new Point3(0,0,1)
},
new List<Point3>
{
new Point3(1, 0, 0),
new Point3(0, 0, 1)
}
};

// Act
NurbsSurface revolvedSurface0 = NurbsSurface.Revolved(profile, axis, Math.PI * 0.25);
NurbsSurface revolvedSurface1 = NurbsSurface.Revolved(profile, axis, 2 * Math.PI);

// Assert
revolvedSurface0.ControlPointLocations
.Zip(expectedPts0, (pt0, pt1) => pt0.SequenceEqual(pt1))
.All(res => res)
.Should().BeTrue();

revolvedSurface1.ControlPointLocations
.Zip(expectedPts1, (pt0, pt1) => pt0.SequenceEqual(pt1))
.All(res => res)
.Should().BeTrue();
}

[Fact]
public void It_Returns_A_Revolved_Surface_From_An_Arc()
{
// Arrange
Ray axis = new Ray(Point3.Origin, Vector3.ZAxis);
Arc profile = new Arc(Plane.PlaneZX, 1, new Interval(0, Math.PI * 0.5));

List<List<Point3>> expectedPts = new List<List<Point3>>
{
new List<Point3>
{
new Point3(0, 0, 1),
new Point3(1, 0, 1),
new Point3(1, 0, 0)
},
new List<Point3>
{
new Point3(0, 0, 1),
new Point3(1, 0.41421356237309526, 1),
new Point3(1, 0.41421356237309526, 0)
},
new List<Point3>
{
new Point3(0,0,1),
new Point3(0.7071067811865476,0.7071067811865476,1),
new Point3(0.7071067811865476,0.7071067811865476,0)
}
};

// Act
NurbsSurface revolvedSurface = NurbsSurface.Revolved(profile, axis, Math.PI * 0.25);

// Assert
revolvedSurface.ControlPointLocations
.Zip(expectedPts, (pt0, pt1) => pt0.SequenceEqual(pt1))
.All(res => res)
.Should().BeTrue();
}
}
}
27 changes: 27 additions & 0 deletions src/GShark.Test.XUnit/VerbTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using verb.core;
using verb.eval;
using verb.geom;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -468,5 +469,31 @@ public void ElevateDegree()
_testOutput.WriteLine($"{elevatePoly.controlPoints[i]}");
}
}

[Fact]
public void RevolvedSurface()
{
var axis = new Array<double>(new double[] { 0, 0, 1 });
var pt = new Array<double>(new double[] { 0, 0, 1 });
var xaxis = new Array<double>(new double[] { 1, 0, 0 });
var center = new Array<double>(new double[] { 0, 0, 0 });

var arc = new Arc(center, axis, xaxis, 1, 0.0, Math.PI);

Array<object> pts = new Array<object>();

pts.push(new Array<double>(new double[] { 1, 0, 0, 1 }));
pts.push(new Array<double>(new double[] { 0, 0, 1, 1 }));
Array<double> knots = new Array<double>(new double[] { 0.0, 0.0, 1.0, 1.0 });
var profile = new verb.core.NurbsCurveData(1, knots, pts);

var comps = verb.eval.Make.revolvedSurface(arc._data, center, axis, 0.25 * Math.PI);

for (int i = 0; i < comps.controlPoints.length; i++)
{
var h = verb.eval.Eval.dehomogenize1d((Array<object>) comps.controlPoints.__a[i]);
_testOutput.WriteLine($"{h}");
}
}
}
}
Loading

0 comments on commit 4010fdc

Please sign in to comment.