Exemplo n.º 1
0
        public void Returns_True_If_Two_Surfaces_Are_Equals()
        {
            // Arrange
            NurbsSurface surface0 = NurbsSurfaceCollection.SurfaceFromPoints();
            NurbsSurface surface1 = NurbsSurfaceCollection.SurfaceFromPoints();

            // Assert
            surface0.Equals(surface1).Should().BeTrue();
        }
Exemplo n.º 2
0
        public void Split_Surface_Throws_An_Exception_If_Parameter_Is_Outside_The_Domain(double parameter)
        {
            // Arrange
            NurbsSurface surface = NurbsSurfaceCollection.SurfaceFromPoints();

            // Act
            Func <object> func = () => surface.SplitAt(parameter, SplitDirection.U);

            // Assert
            func.Should().Throw <ArgumentOutOfRangeException>();
        }
Exemplo n.º 3
0
        public void It_Returns_A_Point_On_Surface_At_A_Given_U_And_V_Parameter(double u, double v, double[] pt)
        {
            // Arrange
            NurbsSurface surface    = NurbsSurfaceCollection.QuadrilateralSurface();
            Point3       expectedPt = new Point3(pt[0], pt[1], pt[2]);

            // Act
            Point3 evalPt = surface.PointAt(u, v);

            // Assert
            evalPt.EpsilonEquals(expectedPt, GSharkMath.MinTolerance).Should().BeTrue();
        }
Exemplo n.º 4
0
        public void It_Returns_The_Surface_Normal_At_A_Given_U_And_V_Parameter(double u, double v, double[] pt)
        {
            // Assert
            NurbsSurface surface        = NurbsSurfaceCollection.SurfaceFromPoints();
            Vector3      expectedNormal = new Vector3(pt[0], pt[1], pt[2]);

            // Act
            Vector3 normal = surface.EvaluateAt(u, v, EvaluateSurfaceDirection.Normal);

            // Assert
            normal.EpsilonEquals(expectedNormal, GSharkMath.MinTolerance).Should().BeTrue();
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public void Returns_The_Closest_Point_On_The_Surface(double[] expectedPt, double[] testPt)
        {
            // Arrange
            NurbsSurface surface           = NurbsSurfaceCollection.SurfaceFromPoints();
            Point3       pt                = new Point3(testPt[0], testPt[1], testPt[2]);
            Point3       expectedClosestPt = new Point3(expectedPt[0], expectedPt[1], expectedPt[2]);

            // Act
            Point3 closestPt = surface.ClosestPoint(pt);

            // Assert
            closestPt.DistanceTo(expectedClosestPt).Should().BeLessThan(GSharkMath.MaxTolerance);
        }
Exemplo n.º 7
0
        public void It_Returns_The_Evaluated_Surface_At_A_Given_U_And_V_Parameter()
        {
            // Assert
            NurbsSurface surface            = NurbsSurfaceCollection.SurfaceFromPoints();
            Vector3      expectedUDirection = new Vector3(0.985802, 0.152837, 0.069541);
            Vector3      expectedVDirection = new Vector3(0.053937, 0.911792, 0.407096);

            // Act
            Vector3 uDirection = surface.EvaluateAt(0.3, 0.5, EvaluateSurfaceDirection.U);
            Vector3 vDirection = surface.EvaluateAt(0.3, 0.5, EvaluateSurfaceDirection.V);

            // Assert
            uDirection.EpsilonEquals(expectedUDirection, GSharkMath.MinTolerance).Should().BeTrue();
            vDirection.EpsilonEquals(expectedVDirection, GSharkMath.MinTolerance).Should().BeTrue();
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        public void It_Returns_The_Evaluation_Of_A_Surface_At_The_Given_Parameter()
        {
            // Arrange
            NurbsSurface surface             = NurbsSurfaceCollection.QuadrilateralSurface();
            Vector3      expectedNormal      = new Vector3(0.094255, -0.320469, 0.942557);
            Vector3      expectedDerivativeU = new Vector3(0.995037, 0.0, -0.099503);
            Vector3      expectedDerivativeV = new Vector3(0.0, 0.946772, 0.321902);

            // Act
            Vector3 evaluationNormal = surface.EvaluateAt(0.3, 0.5, EvaluateSurfaceDirection.Normal);
            Vector3 evaluationU      = surface.EvaluateAt(0.3, 0.5, EvaluateSurfaceDirection.U);
            Vector3 evaluationV      = surface.EvaluateAt(0.3, 0.5, EvaluateSurfaceDirection.V);

            // Assert
            (evaluationNormal.IsParallelTo(expectedNormal)).Should().Be(1);
            (evaluationU.IsParallelTo(expectedDerivativeU)).Should().Be(1);
            (evaluationV.IsParallelTo(expectedDerivativeV)).Should().Be(1);
        }
Exemplo n.º 11
0
        public void It_Returns_The_Surface_Split_At_The_Given_Parameter_At_Both_Direction()
        {
            // Arrange
            NurbsSurface  surface     = NurbsSurfaceCollection.SurfaceFromPoints();
            List <Point3> expectedPts = new List <Point3>
            {
                new Point3(2.714286, 3.142857, 1.4),
                new Point3(7.285714, 3.142857, 1.171429),
                new Point3(3.04878, 8.04878, 3.585366),
                new Point3(6.95122, 8.04878, 3)
            };

            // Act
            NurbsSurface[] splitSrf = surface.SplitAt(0.5, SplitDirection.Both);
            var            ptsAt    = splitSrf.Select(s => s.PointAt(0.5, 0.5));

            // Assert
            splitSrf.Length.Should().Be(4);
            _ = ptsAt.Select((pt, i) => pt.DistanceTo(expectedPts[i]).Should().BeLessThan(GSharkMath.MinTolerance));
        }
Exemplo n.º 12
0
        public void It_Refines_The_Surface_In_The_V_Direction(double val, int insertion)
        {
            // Arrange
            List <double> newKnots = new List <double>();

            for (int i = 0; i < insertion; i++)
            {
                newKnots.Add(val);
            }
            NurbsSurface surface = NurbsSurfaceCollection.Loft();

            // Act
            NurbsSurface surfaceAfterRefine = KnotVector.Refine(surface, newKnots, SurfaceDirection.V);
            Point3       p0 = surface.PointAt(0.5, 0.25);
            Point3       p1 = surfaceAfterRefine.PointAt(0.5, 0.25);

            // Assert
            (surface.KnotsV.Count + insertion).Should().Be(surfaceAfterRefine.KnotsV.Count);
            (surface.ControlPointLocations[0].Count + insertion).Should().Be(surfaceAfterRefine.ControlPointLocations[0].Count);

            (p0 == p1).Should().BeTrue();
        }
Exemplo n.º 13
0
        public void It_Returns_The_Surface_Split_At_The_Given_Parameter_At_U_Direction()
        {
            // Arrange
            NurbsSurface          surface       = NurbsSurfaceCollection.SurfaceFromPoints();
            List <List <Point3> > surfacePtsTop = new List <List <Point3> >
            {
                new List <Point3> {
                    new Point3(0.0, 0.0, 0.0), new Point3(0.0, 10.0, 4.0)
                },
                new List <Point3> {
                    new Point3(2.5, 0.0, 0.0), new Point3(3.333333, 10.0, 4.666666)
                },
                new List <Point3> {
                    new Point3(5.0, 0.0, 0.0), new Point3(5.0, 10.0, 4.333333)
                }
            };

            List <List <Point3> > surfacePtsBottom = new List <List <Point3> >
            {
                new List <Point3> {
                    new Point3(5.0, 0.0, 0.0), new Point3(5.0, 10.0, 4.333333)
                },
                new List <Point3> {
                    new Point3(7.5, 0.0, 0.0), new Point3(6.666666, 10.0, 4.0)
                },
                new List <Point3> {
                    new Point3(10.0, 0.0, 0.0), new Point3(10.0, 10.0, 2.0)
                }
            };

            List <List <double> > weightsTop = new List <List <double> >
            {
                new List <double> {
                    1, 1
                },
                new List <double> {
                    1, 1.5
                },
                new List <double> {
                    1, 1.5
                }
            };

            List <List <double> > weightsBottom = new List <List <double> >
            {
                new List <double> {
                    1, 1.5
                },
                new List <double> {
                    1, 1.5
                },
                new List <double> {
                    1, 1
                }
            };

            Point3 expectedPtTop    = new Point3(2.894737, 5.789474, 2.578947);
            Point3 expectedPtBottom = new Point3(7.105263, 5.789474, 2.157895);

            // Act
            NurbsSurface[] surfaces         = surface.SplitAt(0.5, SplitDirection.U);
            Point3         evaluatePtTop    = surfaces[0].PointAt(0.5, 0.5);
            Point3         evaluatePtBottom = surfaces[1].PointAt(0.5, 0.5);

            // Assert
            evaluatePtTop.DistanceTo(expectedPtTop).Should().BeLessThan(GSharkMath.MinTolerance);
            evaluatePtBottom.DistanceTo(expectedPtBottom).Should().BeLessThan(GSharkMath.MinTolerance);

            surfaces[0].Weights.Should().BeEquivalentTo(weightsTop);
            surfaces[1].Weights.Should().BeEquivalentTo(weightsBottom);

            _ = surfaces[0].ControlPointLocations.Select((pts, i) => pts.Select((pt, j) =>
                                                                                pt.EpsilonEquals(surfacePtsTop[i][j], GSharkMath.MinTolerance).Should().BeTrue()));
            _ = surfaces[1].ControlPointLocations.Select((pts, i) => pts.Select((pt, j) =>
                                                                                pt.EpsilonEquals(surfacePtsBottom[i][j], GSharkMath.MinTolerance).Should().BeTrue()));
        }
Exemplo n.º 14
0
        public void It_Returns_The_Surface_Split_At_The_Given_Parameter_At_V_Direction()
        {
            // Arrange
            NurbsSurface          surface        = NurbsSurfaceCollection.SurfaceFromPoints();
            List <List <Point3> > surfacePtsLeft = new List <List <Point3> >
            {
                new List <Point3> {
                    new Point3(0.0, 0.0, 0.0), new Point3(0.0, 5.0, 2.0)
                },
                new List <Point3> {
                    new Point3(5.0, 0.0, 0.0), new Point3(5.0, 6.666666, 3.333333)
                },
                new List <Point3> {
                    new Point3(10.0, 0.0, 0.0), new Point3(10.0, 5.0, 1.0)
                }
            };

            List <List <Point3> > surfacePtsRight = new List <List <Point3> >
            {
                new List <Point3> {
                    new Point3(0.0, 5.0, 2.0), new Point3(0.0, 10.0, 4.0)
                },
                new List <Point3> {
                    new Point3(5.0, 6.666666, 3.333333), new Point3(5.0, 10.0, 5.0)
                },
                new List <Point3> {
                    new Point3(10.0, 5.0, 1.0), new Point3(10.0, 10.0, 2.0)
                }
            };

            List <List <double> > weightsLeft = new List <List <double> >
            {
                new List <double> {
                    1, 1
                },
                new List <double> {
                    1, 1.5
                },
                new List <double> {
                    1, 1
                }
            };

            List <List <double> > weightsRight = new List <List <double> >
            {
                new List <double> {
                    1, 1
                },
                new List <double> {
                    1.5, 2
                },
                new List <double> {
                    1, 1
                }
            };

            Point3 expectedPtLeft  = new Point3(5.0, 3.333333, 1.444444);
            Point3 expectedPtRight = new Point3(5.0, 8.181818, 3.545455);

            // Act
            NurbsSurface[] surfaces        = surface.SplitAt(0.5, SplitDirection.V);
            Point3         evaluatePtLeft  = surfaces[0].PointAt(0.5, 0.5);
            Point3         evaluatePtRight = surfaces[1].PointAt(0.5, 0.5);

            // Assert
            evaluatePtLeft.DistanceTo(expectedPtLeft).Should().BeLessThan(GSharkMath.MinTolerance);
            evaluatePtRight.DistanceTo(expectedPtRight).Should().BeLessThan(GSharkMath.MinTolerance);

            surfaces[0].Weights.Should().BeEquivalentTo(weightsLeft);
            surfaces[1].Weights.Should().BeEquivalentTo(weightsRight);

            _ = surfaces[0].ControlPointLocations.Select((pts, i) => pts.Select((pt, j) =>
                                                                                pt.EpsilonEquals(surfacePtsLeft[i][j], GSharkMath.MinTolerance).Should().BeTrue()));
            _ = surfaces[1].ControlPointLocations.Select((pts, i) => pts.Select((pt, j) =>
                                                                                pt.EpsilonEquals(surfacePtsRight[i][j], GSharkMath.MinTolerance).Should().BeTrue()));
        }