Esempio n. 1
0
        public void It_Returns_The_Point_On_The_Circle_At_The_Give_Length(double length, double[] pts)
        {
            // Arrange
            Point3 expectedPt = new Point3(pts[0], pts[1], pts[2]);

            // Act
            double normalizeLength = GSharkMath.RemapValue(length, new Interval(0.0, _circle2D.Length), new Interval(0.0, 1.0));
            Point3 pt = _circle2D.PointAtLength(length);
            Point3 ptNormalizedLength = _circle2D.PointAtNormalizedLength(normalizeLength);

            // Assert
            pt.EpsilonEquals(expectedPt, GSharkMath.MaxTolerance).Should().BeTrue();
            pt.EpsilonEquals(ptNormalizedLength, GSharkMath.MaxTolerance).Should().BeTrue();
        }
Esempio n. 2
0
        public void Returns_A_Ruled_Surface_Between_A_Polyline_And_A_Nurbs_Curve(double u, double v, double[] pt)
        {
            // Arrange
            Point3        expectedPt = new Point3(pt[0], pt[1], pt[2]);
            List <Point3> ptsA       = new List <Point3>
            {
                new Point3(0, 0, 0),
                new Point3(0, 0, 5),
                new Point3(5, 0, 5),
                new Point3(5, 0, 0),
                new Point3(10, 0, 0)
            };

            List <Point3> ptsB = new List <Point3>
            {
                new Point3(0, 10, 0),
                new Point3(0, 10, 5),
                new Point3(5, 10, 5),
                new Point3(5, 10, 0),
                new Point3(10, 10, 0)
            };

            PolyLine   poly   = new PolyLine(ptsA);
            NurbsCurve curveB = new NurbsCurve(ptsB, 2);

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

            // Assert
            pointAt.EpsilonEquals(expectedPt, GSharkMath.MinTolerance).Should().BeTrue();
        }
Esempio n. 3
0
        public void It_Returns_The_Point_On_The_Circle_At_The_Give_Parameter(double t, double[] pts)
        {
            // Arrange
            Point3 expectedPt = new Point3(pts[0], pts[1], pts[2]);

            // Act
            Point3 pt = _circle2D.PointAt(t);

            // Assert
            pt.EpsilonEquals(expectedPt, GSharkMath.MaxTolerance).Should().BeTrue();
        }
Esempio n. 4
0
        public void It_Returns_The_Evaluated_Point_At_The_Given_Parameter(double t, double[] ptExpected)
        {
            //Arrange
            var expectedPt = new Point3(ptExpected[0], ptExpected[1], ptExpected[2]);

            // Act
            Point3 ptEvaluated = _exampleLine.PointAt(t);

            // Assert
            ptEvaluated.EpsilonEquals(expectedPt, GSharkMath.Epsilon).Should().BeTrue();
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
        public void It_Returns_The_ClosestPoint()
        {
            // Arrange
            Point3 pt         = new Point3(5, 8, 0);
            Point3 expectedPt = new Point3(8.692308, 5.538462, 0);

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

            // Assert
            closestPt.EpsilonEquals(expectedPt, 1e-6).Should().BeTrue();
        }
Esempio n. 7
0
        public void It_Returns_The_Closest_Point_On_A_Circle(double[] ptToTest, double[] result)
        {
            // Arrange
            Point3 testPt     = new Point3(ptToTest[0], ptToTest[1], ptToTest[2]);
            Point3 expectedPt = new Point3(result[0], result[1], result[2]);

            // Act
            Circle circle = _circle3D;
            Point3 pt     = circle.ClosestPoint(testPt);

            // Assert
            pt.EpsilonEquals(expectedPt, GSharkMath.MaxTolerance).Should().BeTrue();
        }
Esempio n. 8
0
        public void It_Returns_A_Normal_Lofted_Surface_By_Opened_Curves(double u, double v, double[] pt)
        {
            // Arrange
            Point3 expectedPt = new Point3(pt[0], pt[1], pt[2]);

            // Act
            NurbsSurface surface = NurbsSurface.FromLoft(NurbsCurveCollection.OpenCurves());
            Point3       evalPt  = surface.PointAt(u, v);

            // Assert
            surface.Should().NotBeNull();
            evalPt.EpsilonEquals(expectedPt, GSharkMath.MinTolerance).Should().BeTrue();
        }
Esempio n. 9
0
        public void It_Returns_The_Closest_Point_And_Parameter(double[] ptToCheck, double[] ptExpected, double tValExpected)
        {
            // Arrange
            NurbsBase curve      = NurbsCurveCollection.PlanarCurveDegreeThree();
            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();
        }
Esempio n. 10
0
        public void It_Returns_The_Centroid_By_Vertices()
        {
            // Arrange
            Polygon poly2D = new Polygon(Planar2D);
            Polygon poly3D = new Polygon(Planar3D);

            Point3 centroid2DExpected = new Point3(3.5, 5.5, 0.0);
            Point3 centroid3DExpected = new Point3(86.266409, 29.701102, -0.227864);

            // Act
            Point3 poly2DCentroid = poly2D.CentroidByVertices;
            Point3 poly3DCentroid = poly3D.CentroidByVertices;

            // Assert
            poly2DCentroid.Equals(centroid2DExpected).Should().BeTrue();
            poly3DCentroid.EpsilonEquals(centroid3DExpected, GSharkMath.MaxTolerance).Should().BeTrue();
        }
Esempio n. 11
0
        public void It_Returns_A_NURBS_Surface_By_Four_Points()
        {
            // Arrange
            Point3 p1 = new Point3(0.0, 0.0, 0.0);
            Point3 p2 = new Point3(10.0, 0.0, 0.0);
            Point3 p3 = new Point3(10.0, 10.0, 2.0);
            Point3 p4 = new Point3(0.0, 10.0, 4.0);

            Point3 expectedPt = new Point3(5.0, 5.0, 1.5);

            // Act
            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));

            // Assert
            surfaceCcw.Should().NotBeNull();
            surfaceCcw.ControlPointLocations.Count.Should().Be(2);
            surfaceCcw.ControlPointLocations[0].Count.Should().Be(2);
            surfaceCcw.ControlPointLocations[0][1].Equals(p4).Should().BeTrue();
            (evalPtCcw.EpsilonEquals(expectedPt, GSharkMath.MinTolerance) && evalPtCw.EpsilonEquals(expectedPt, GSharkMath.MinTolerance)).Should().BeTrue();
        }