protected NurbsBase(int degree, KnotVector knots, List <Point4> controlPoints) { if (controlPoints is null) { throw new ArgumentNullException(nameof(controlPoints)); } if (knots is null) { throw new ArgumentNullException(nameof(knots)); } if (degree < 1) { throw new ArgumentException("Degree must be greater than 1!"); } if (knots.Count != controlPoints.Count + degree + 1) { throw new ArgumentException("Number of controlPoints + degree + 1 must equal knots length!"); } if (!knots.IsValid(degree, controlPoints.Count)) { throw new ArgumentException("Invalid knot format! Should begin with degree + 1 repeats and end with degree + 1 repeats!"); } Weights = Point4.GetWeights(controlPoints); Degree = degree; Knots = knots; ControlPointLocations = Point4.PointDehomogenizer1d(controlPoints); ControlPoints = controlPoints; }
[InlineData(new double[] { -0.666, -0.333, 0, 0.333, 0.666, 1, 1.333, 1.666 }, 2, 5, true)] // Periodic public void It_Checks_If_The_Knots_Are_Valid(double[] knots, int degree, int ctrlPts, bool expectedResult) { // Act KnotVector knot = new KnotVector(knots); // Assert knot.IsValid(degree, ctrlPts).Should().Be(expectedResult); }
/// <summary> /// Internal constructor used to validate the NURBS surface. /// </summary> /// <param name="degreeU">The degree in the U direction.</param> /// <param name="degreeV">The degree in the V direction.</param> /// <param name="knotsU">The knotVector in the U direction.</param> /// <param name="knotsV">The knotVector in the V direction.</param> /// <param name="controlPts">Two dimensional array of points.</param> internal NurbsSurface(int degreeU, int degreeV, KnotVector knotsU, KnotVector knotsV, List <List <Point4> > controlPts) { if (controlPts == null) { throw new ArgumentNullException("Control points array connot be null!"); } if (degreeU < 1) { throw new ArgumentException("DegreeU must be greater than 1!"); } if (degreeV < 1) { throw new ArgumentException("DegreeV must be greater than 1!"); } if (knotsU == null) { throw new ArgumentNullException("KnotU cannot be null!"); } if (knotsV == null) { throw new ArgumentNullException("KnotV cannot be null!"); } if (knotsU.Count != controlPts.Count() + degreeU + 1) { throw new ArgumentException("Points count + degreeU + 1 must equal knotsU count!"); } if (knotsV.Count != controlPts.First().Count() + degreeV + 1) { throw new ArgumentException("Points count + degreeV + 1 must equal knotsV count!"); } if (!knotsU.IsValid(degreeU, controlPts.Count())) { throw new ArgumentException("Invalid knotsU!"); } if (!knotsV.IsValid(degreeV, controlPts.First().Count())) { throw new ArgumentException("Invalid knotsV!"); } DegreeU = degreeU; DegreeV = degreeV; KnotsU = (Math.Abs(knotsU.GetDomain(degreeU).Length - 1.0) > GSharkMath.Epsilon) ? knotsU.Normalize() : knotsU; KnotsV = (Math.Abs(knotsV.GetDomain(degreeV).Length - 1.0) > GSharkMath.Epsilon) ? knotsV.Normalize() : knotsV; Weights = Point4.GetWeights2d(controlPts); ControlPointLocations = Point4.PointDehomogenizer2d(controlPts); ControlPoints = controlPts; DomainU = new Interval(KnotsU.First(), KnotsU.Last()); DomainV = new Interval(KnotsV.First(), KnotsV.Last()); }