/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="fitPoints">Spline fit points.</param> /// <remarks>Spline entities created with a list of fit points cannot be used as a boundary path in a hatch.</remarks> public Spline(List <Vector3> fitPoints) : base(EntityType.Spline, DxfObjectCode.Spline) { this.degree = 3; this.isPeriodic = false; this.controlPoints = new List <SplineVertex>(); this.knots = new List <double>(); this.fitPoints = fitPoints; this.creationMethod = SplineCreationMethod.FitPoints; this.isClosed = fitPoints[0].Equals(fitPoints[fitPoints.Count - 1]); this.flags = this.isClosed ? SplineTypeFlags.Closed | SplineTypeFlags.Rational : SplineTypeFlags.Rational; }
/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="fitPoints">Spline fit points.</param> /// <remarks>Spline entities created with a list of fit points cannot be used as a boundary path in a hatch.</remarks> public Spline(List<Vector3> fitPoints) : base(EntityType.Spline, DxfObjectCode.Spline) { this.degree = 3; this.isPeriodic = false; this.controlPoints = new List<SplineVertex>(); this.knots = new List<double>(); this.fitPoints = fitPoints; this.creationMethod = SplineCreationMethod.FitPoints; this.isClosed = fitPoints[0].Equals(fitPoints[fitPoints.Count - 1]); this.flags = this.isClosed ? SplineTypeFlags.Closed | SplineTypeFlags.Rational : SplineTypeFlags.Rational; }
/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="controlPoints">Spline control points.</param> /// <param name="knots">Spline knot vector.</param> /// <param name="degree">Degree of the spline curve. Valid values are 1 (linear), degree 2 (quadratic), degree 3 (cubic), and so on up to degree 10.</param> /// <param name="fitPoints">Spine fit points.</param> /// <param name="method">Spline creation method.</param> /// <param name="isPeriodic">Sets if the spline as periodic closed (default false).</param> internal Spline(List <SplineVertex> controlPoints, List <double> knots, short degree, List <Vector3> fitPoints, SplineCreationMethod method, bool isPeriodic) : base(EntityType.Spline, DxfObjectCode.Spline) { if (degree < 1 || degree > 10) { throw new ArgumentOutOfRangeException(nameof(degree), degree, "The spline degree valid values range from 1 to 10."); } if (controlPoints == null) { throw new ArgumentNullException(nameof(controlPoints)); } if (controlPoints.Count < 2) { throw new ArgumentException("The number of control points must be equal or greater than 2."); } if (controlPoints.Count < degree + 1) { throw new ArgumentException("The number of control points must be equal or greater than the spline degree + 1."); } if (knots == null) { throw new ArgumentNullException(nameof(knots)); } if (knots.Count != controlPoints.Count + degree + 1) { throw new ArgumentException("The number of knots must be equals to the number of control points + spline degree + 1."); } this.fitPoints = fitPoints; this.controlPoints = controlPoints; this.knots = knots; this.degree = degree; this.creationMethod = method; this.isPeriodic = isPeriodic; if (this.isPeriodic) { this.isClosed = true; this.flags = SplineTypeFlags.Closed | SplineTypeFlags.Periodic | SplineTypeFlags.Rational; } else { this.isClosed = controlPoints[0].Position.Equals(controlPoints[controlPoints.Count - 1].Position); this.flags = this.isClosed ? SplineTypeFlags.Closed | SplineTypeFlags.Rational : SplineTypeFlags.Rational; } }
/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="controlPoints">Spline control points.</param> /// <param name="weights">Spline control weights. If null the weights vector will be automatically initialized with 1.0.</param> /// <param name="degree">Degree of the spline curve. Valid values are 1 (linear), degree 2 (quadratic), degree 3 (cubic), and so on up to degree 10.</param> /// <param name="closedPeriodic">Sets if the spline as periodic closed (default false).</param> public Spline(IEnumerable <Vector3> controlPoints, IEnumerable <double> weights, short degree, bool closedPeriodic) : base(EntityType.Spline, DxfObjectCode.Spline) { // spline degree if (degree < 1 || degree > 10) { throw new ArgumentOutOfRangeException(nameof(degree), degree, "The spline degree valid values range from 1 to 10."); } this.degree = degree; // control points if (controlPoints == null) { throw new ArgumentNullException(nameof(controlPoints)); } // create control points this.controlPoints = controlPoints.ToArray(); if (this.controlPoints.Length < 2) { throw new ArgumentException("The number of control points must be equal or greater than 2."); } if (this.controlPoints.Length < degree + 1) { throw new ArgumentException("The number of control points must be equal or greater than the spline degree + 1."); } // create weights if (weights == null) { this.weights = new double[this.controlPoints.Length]; for (int i = 0; i < this.controlPoints.Length; i++) { this.weights[i] = 1.0; } } else { this.weights = weights.ToArray(); if (this.weights.Length != this.controlPoints.Length) { throw new ArgumentException("The number of control points must be the same as the number of weights.", nameof(weights)); } } this.isClosedPeriodic = closedPeriodic; this.creationMethod = SplineCreationMethod.ControlPoints; this.fitPoints = new Vector3[0]; this.knots = CreateKnotVector(this.controlPoints.Length, this.degree, this.isClosedPeriodic); }
/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="fitPoints">Spline fit points.</param> /// <remarks>Spline entities created with a list of fit points cannot be used as a boundary path in a hatch.</remarks> public Spline(IEnumerable<Vector3> fitPoints) : base(EntityType.Spline, DxfObjectCode.Spline) { this.degree = 3; this.isPeriodic = false; this.controlPoints = new List<SplineVertex>(); this.knots = new List<double>(); if (fitPoints == null) throw new ArgumentNullException(nameof(fitPoints)); this.fitPoints = new List<Vector3>(fitPoints); this.creationMethod = SplineCreationMethod.FitPoints; this.isClosed = this.fitPoints[0].Equals(this.fitPoints[this.fitPoints.Count - 1]); this.flags = this.isClosed ? SplinetypeFlags.Closed | SplinetypeFlags.Rational : SplinetypeFlags.Rational; }
/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="controlPoints">Spline control points.</param> /// <param name="degree">Degree of the spline curve. Valid values are 1 (linear), degree 2 (quadratic), degree 3 (cubic), and so on up to degree 10.</param> /// <param name="closedPeriodic">Sets if the spline as periodic closed (default false).</param> public Spline(IEnumerable <SplineVertex> controlPoints, short degree, bool closedPeriodic) : base(EntityType.Spline, DxfObjectCode.Spline) { // spline degree if (degree < 1 || degree > 10) { throw new ArgumentOutOfRangeException(nameof(degree), degree, "The spline degree valid values range from 1 to 10."); } this.degree = degree; // control points if (controlPoints == null) { throw new ArgumentNullException(nameof(controlPoints)); } // create control points this.controlPoints = new List <SplineVertex>(controlPoints); if (this.controlPoints.Count < 2) { throw new ArgumentException("The number of control points must be equal or greater than 2."); } if (this.controlPoints.Count < degree + 1) { throw new ArgumentException("The number of control points must be equal or greater than the spline degree + 1."); } this.isClosedPeriodic = closedPeriodic; //// for periodic splines //if (this.isPeriodic) //{ // this.isClosed = true; // int replicate = this.degree; // for (int i = 0; i < replicate; i++) // { // this.controlPoints.Add(ctrl[ctrl.Length - replicate + i]); // } //} //this.controlPoints.AddRange(ctrl); this.creationMethod = SplineCreationMethod.ControlPoints; this.fitPoints = new List <Vector3>(); this.knots = CreateKnotVector(this.controlPoints.Count, this.degree, this.isClosedPeriodic); }
/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="fitPoints">Spline fit points.</param> /// <remarks>Spline entities created with a list of fit points cannot be used as a boundary path in a hatch.</remarks> public Spline(IEnumerable <Vector3> fitPoints) : base(EntityType.Spline, DxfObjectCode.Spline) { this.degree = 3; this.isPeriodic = false; this.controlPoints = new List <SplineVertex>(); this.knots = new List <double>(); if (fitPoints == null) { throw new ArgumentNullException(nameof(fitPoints)); } this.fitPoints = new List <Vector3>(fitPoints); this.creationMethod = SplineCreationMethod.FitPoints; this.isClosed = this.fitPoints[0].Equals(this.fitPoints[this.fitPoints.Count - 1]); this.flags = this.isClosed ? SplinetypeFlags.Closed | SplinetypeFlags.Rational : SplinetypeFlags.Rational; }
private Spline(IEnumerable <BezierCurve> curves, short degree) : base(EntityType.Spline, DxfObjectCode.Spline) { this.degree = degree; this.isClosedPeriodic = false; this.fitPoints = new List <Vector3>(); // control points and fit points this.controlPoints = new List <SplineVertex>(); foreach (BezierCurve curve in curves) { foreach (Vector3 point in curve.ControlPoints) { this.controlPoints.Add(new SplineVertex(point)); } } this.creationMethod = SplineCreationMethod.ControlPoints; this.knots = ÇreateBezierKnotVector(this.controlPoints.Count, this.degree); }
/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="controlPoints">Spline control points.</param> /// <param name="degree">Degree of the spline curve. Valid values are 1 (linear), degree 2 (quadratic), degree 3 (cubic), and so on up to degree 10.</param> /// <param name="periodic">Sets if the spline as periodic closed (default false).</param> public Spline(List <SplineVertex> controlPoints, short degree, bool periodic = false) : base(EntityType.Spline, DxfObjectCode.Spline) { if (degree < 1 || degree > 10) { throw new ArgumentOutOfRangeException(nameof(degree), degree, "The spline degree valid values range from 1 to 10."); } if (controlPoints == null) { throw new ArgumentNullException(nameof(controlPoints), "The Spline control points list cannot be null."); } if (controlPoints.Count < 2) { throw new ArgumentException("The number of control points must be equal or greater than 2."); } if (controlPoints.Count < degree + 1) { throw new ArgumentException("The number of control points must be equal or greater than the spline degree + 1."); } this.fitPoints = new List <Vector3>(); this.degree = degree; this.creationMethod = SplineCreationMethod.ControlPoints; this.isPeriodic = periodic; if (this.isPeriodic) { this.isClosed = true; this.flags = SplineTypeFlags.Closed | SplineTypeFlags.Periodic | SplineTypeFlags.Rational; } else { this.isClosed = controlPoints[0].Position.Equals(controlPoints[controlPoints.Count - 1].Position); this.flags = this.isClosed ? SplineTypeFlags.Closed | SplineTypeFlags.Rational : SplineTypeFlags.Rational; } this.Create(controlPoints); }
private Spline(IEnumerable <BezierCurve> curves, short degree) : base(EntityType.Spline, DxfObjectCode.Spline) { // control points and fit points List <Vector3> ctrList = new List <Vector3>(); List <double> wList = new List <double>(); foreach (BezierCurve curve in curves) { foreach (Vector3 point in curve.ControlPoints) { ctrList.Add(point); wList.Add(1.0); } } this.controlPoints = ctrList.ToArray(); this.weights = wList.ToArray(); this.degree = degree; this.isClosedPeriodic = false; this.fitPoints = new Vector3[0]; this.creationMethod = SplineCreationMethod.ControlPoints; this.knots = ÇreateBezierKnotVector(this.controlPoints.Length, this.degree); }
/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="controlPoints">Spline control points.</param> /// <param name="knots">Spline knot vector.</param> /// <param name="degree">Degree of the spline curve. Valid values are 1 (linear), degree 2 (quadratic), degree 3 (cubic), and so on up to degree 10.</param> internal Spline(List<SplineVertex> controlPoints, List<double> knots, short degree, List<Vector3> fitPoints, SplineCreationMethod method, bool isPeriodic) : base(EntityType.Spline, DxfObjectCode.Spline) { if (degree < 1 || degree > 10) throw new ArgumentOutOfRangeException(nameof(degree), degree, "The spline degree valid values range from 1 to 10."); if (controlPoints == null) throw new ArgumentNullException(nameof(controlPoints)); if (controlPoints.Count < 2) throw new ArgumentException("The number of control points must be equal or greater than 2."); if (controlPoints.Count < degree + 1) throw new ArgumentException("The number of control points must be equal or greater than the spline degree + 1."); if (knots == null) throw new ArgumentNullException(nameof(knots)); if (knots.Count != controlPoints.Count + degree + 1) throw new ArgumentException("The number of knots must be equals to the number of control points + spline degree + 1."); this.fitPoints = fitPoints; this.controlPoints = controlPoints; this.knots = knots; this.degree = degree; this.creationMethod = method; this.isPeriodic = isPeriodic; if (this.isPeriodic) { this.isClosed = true; this.flags = SplinetypeFlags.Closed | SplinetypeFlags.Periodic | SplinetypeFlags.Rational; } else { this.isClosed = controlPoints[0].Position.Equals(controlPoints[controlPoints.Count - 1].Position); this.flags = this.isClosed ? SplinetypeFlags.Closed | SplinetypeFlags.Rational : SplinetypeFlags.Rational; } }
/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="fitPoints">Spline fit points.</param> /// <remarks> /// The resulting spline curve will be created from a list of cubic bezier curves that passes through the specified fit points. /// </remarks> public Spline(IEnumerable <Vector3> fitPoints) : this(BezierCurveCubic.CreateFromFitPoints(fitPoints)) { this.creationMethod = SplineCreationMethod.FitPoints; this.fitPoints = new List <Vector3>(fitPoints); }
/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="controlPoints">Spline control points.</param> /// <param name="knots">Spline knot vector.</param> /// <param name="degree">Degree of the spline curve. Valid values are 1 (linear), degree 2 (quadratic), degree 3 (cubic), and so on up to degree 10.</param> /// <param name="fitPoints">Spine fit points.</param> /// <param name="method">Spline creation method.</param> /// <param name="closedPeriodic">Sets if the spline as periodic closed (default false).</param> internal Spline(IEnumerable <SplineVertex> controlPoints, IEnumerable <double> knots, short degree, IEnumerable <Vector3> fitPoints, SplineCreationMethod method, bool closedPeriodic) : base(EntityType.Spline, DxfObjectCode.Spline) { // spline degree if (degree < 1 || degree > 10) { throw new ArgumentOutOfRangeException(nameof(degree), degree, "The spline degree valid values range from 1 to 10."); } this.degree = degree; // control points if (controlPoints == null) { if (method == SplineCreationMethod.ControlPoints) { throw new ArgumentNullException(nameof(controlPoints), "Cannot create a spline without control points if its creation method is with control points."); } this.controlPoints = new List <SplineVertex>(); } else { this.controlPoints = new List <SplineVertex>(controlPoints); if (this.controlPoints.Count < 2) { throw new ArgumentOutOfRangeException(nameof(controlPoints), this.controlPoints.Count, "The number of control points must be equal or greater than 2."); } if (this.controlPoints.Count < degree + 1) { throw new ArgumentOutOfRangeException(nameof(controlPoints), this.controlPoints.Count, "The number of control points must be equal or greater than the spline degree + 1."); } // knots if (knots == null) { throw new ArgumentNullException(nameof(knots)); } this.knots = knots.ToArray(); int numKnots; if (closedPeriodic) { numKnots = this.controlPoints.Count + 2 * degree + 1; } else { numKnots = this.controlPoints.Count + degree + 1; } if (this.knots.Length != numKnots) { throw new ArgumentException("Invalid number of knots."); } //if (this.knots.Length != this.controlPoints.Count + degree + 1) //{ // throw new ArgumentException("The number of knots must be equals to the number of control points + spline degree + 1."); //} } // fit points if (fitPoints == null) { if (method == SplineCreationMethod.FitPoints) { throw new ArgumentNullException(nameof(fitPoints), "Cannot create a spline without fit points if its creation method is with fit points."); } this.fitPoints = new List <Vector3>(); } else { this.fitPoints = new List <Vector3>(fitPoints); } this.creationMethod = method; this.isClosedPeriodic = closedPeriodic; }
/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="controlPoints">Spline control points.</param> /// <param name="weights">Spline control weights. If null the weights vector will be automatically initialized with 1.0.</param> /// <param name="knots">Spline knot vector.</param> /// <param name="degree">Degree of the spline curve. Valid values are 1 (linear), degree 2 (quadratic), degree 3 (cubic), and so on up to degree 10.</param> /// <param name="fitPoints">Spine fit points.</param> /// <param name="method">Spline creation method.</param> /// <param name="closedPeriodic">Sets if the spline as periodic closed (default false).</param> internal Spline(IEnumerable <Vector3> controlPoints, IEnumerable <double> weights, IEnumerable <double> knots, short degree, IEnumerable <Vector3> fitPoints, SplineCreationMethod method, bool closedPeriodic) : base(EntityType.Spline, DxfObjectCode.Spline) { // spline degree if (degree < 1 || degree > 10) { throw new ArgumentOutOfRangeException(nameof(degree), degree, "The spline degree valid values range from 1 to 10."); } this.degree = degree; // control points if (controlPoints == null) { if (method == SplineCreationMethod.ControlPoints) { throw new ArgumentNullException(nameof(controlPoints), "Cannot create a spline without control points if its creation method is with control points."); } this.controlPoints = new Vector3[0]; } else { this.controlPoints = controlPoints.ToArray(); int numControlPoints = this.controlPoints.Length; if (numControlPoints < 2) { throw new ArgumentOutOfRangeException(nameof(controlPoints), numControlPoints, "The number of control points must be equal or greater than 2."); } if (numControlPoints < degree + 1) { throw new ArgumentOutOfRangeException(nameof(controlPoints), numControlPoints, "The number of control points must be equal or greater than the spline degree + 1."); } // create weights if (weights == null) { this.weights = new double[numControlPoints]; for (int i = 0; i < numControlPoints; i++) { this.weights[i] = 1.0; } } else { this.weights = weights.ToArray(); int numWeights = this.weights.Length; if (numWeights != numControlPoints) { throw new ArgumentException("The number of control points must be the same as the number of weights.", nameof(weights)); } } // knots if (knots == null) { throw new ArgumentNullException(nameof(knots)); } this.knots = knots.ToArray(); int numKnots; if (closedPeriodic) { numKnots = numControlPoints + 2 * degree + 1; } else { numKnots = numControlPoints + degree + 1; } if (this.knots.Length != numKnots) { throw new ArgumentException("Invalid number of knots."); } } // fit points if (fitPoints == null) { if (method == SplineCreationMethod.FitPoints) { throw new ArgumentNullException(nameof(fitPoints), "Cannot create a spline without fit points if its creation method is with fit points."); } this.fitPoints = new Vector3[0]; } else { this.fitPoints = fitPoints.ToArray(); } this.creationMethod = method; this.isClosedPeriodic = closedPeriodic; }
/// <summary> /// Initializes a new instance of the <c>Spline</c> class. /// </summary> /// <param name="controlPoints">Spline control points.</param> /// <param name="degree">Degree of the spline curve. Valid values are 1 (linear), degree 2 (quadratic), degree 3 (cubic), and so on up to degree 10.</param> /// <param name="periodic">Sets if the spline as periodic closed (default false).</param> public Spline(List<SplineVertex> controlPoints, short degree, bool periodic = false) : base(EntityType.Spline, DxfObjectCode.Spline) { if (degree < 1 || degree > 10) throw new ArgumentOutOfRangeException(nameof(degree), degree, "The spline degree valid values range from 1 to 10."); if (controlPoints == null) throw new ArgumentNullException(nameof(controlPoints), "The Spline control points list cannot be null."); if (controlPoints.Count < 2) throw new ArgumentException("The number of control points must be equal or greater than 2."); if (controlPoints.Count < degree + 1) throw new ArgumentException("The number of control points must be equal or greater than the spline degree + 1."); this.fitPoints = new List<Vector3>(); this.degree = degree; this.creationMethod = SplineCreationMethod.ControlPoints; this.isPeriodic = periodic; if (this.isPeriodic) { this.isClosed = true; this.flags = SplineTypeFlags.Closed | SplineTypeFlags.Periodic | SplineTypeFlags.Rational; } else { this.isClosed = controlPoints[0].Position.Equals(controlPoints[controlPoints.Count - 1].Position); this.flags = this.isClosed ? SplineTypeFlags.Closed | SplineTypeFlags.Rational : SplineTypeFlags.Rational; } this.Create(controlPoints); }