Esempio n. 1
0
        /// <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.</param>
        public Spline(List <SplineVertex> controlPoints, double[] knots, short degree)
            : base(EntityType.Spline, DxfObjectCode.Spline)
        {
            if (degree < 1)
            {
                throw new ArgumentException("The degree of the spline must be equal or greater than one.");
            }
            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.Length != controlPoints.Count + degree + 1)
            {
                throw new ArgumentException("The number of knots must be equals to the number of control points + spline degree + 1.");
            }

            this.controlPoints = controlPoints;
            this.knots         = knots;
            this.degree        = degree;
            this.isPeriodic    = this.PeriodicTest(controlPoints, degree);
            if (this.isPeriodic)
            {
                this.isClosed = true;
                this.flags    = SplineTypeFlags.Closed | SplineTypeFlags.Periodic | SplineTypeFlags.Rational;
            }
            else
            {
                this.isClosed = controlPoints[0].Location.Equals(controlPoints[controlPoints.Count - 1].Location);
                this.flags    = this.isClosed ? SplineTypeFlags.Closed | SplineTypeFlags.Rational : SplineTypeFlags.Rational;
            }
        }
Esempio n. 2
0
        /// <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("degree", degree, "The spline degree valid values range from 1 to 10."));
            }
            if (controlPoints == null)
            {
                throw new ArgumentNullException("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.degree     = degree;
            this.isPeriodic = periodic;
            if (this.isPeriodic)
            {
                this.isClosed = true;
                this.flags    = SplineTypeFlags.Closed | SplineTypeFlags.Periodic | SplineTypeFlags.Rational;
            }
            else
            {
                this.isClosed = controlPoints[0].Location.Equals(controlPoints[controlPoints.Count - 1].Location);
                this.flags    = this.isClosed ? SplineTypeFlags.Closed | SplineTypeFlags.Rational : SplineTypeFlags.Rational;
            }

            this.Create(controlPoints);
        }
Esempio n. 3
0
        /// <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>
        public Spline(List<SplineVertex> controlPoints, double[] knots, short degree)
            : base(EntityType.Spline, DxfObjectCode.Spline)
        {
            if (degree < 1 || degree > 10)
                throw (new ArgumentOutOfRangeException("degree", degree, "The spline degree valid values range from 1 to 10."));
            if (controlPoints == null)
                throw new ArgumentNullException("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.");
            if (knots == null)
                throw new ArgumentNullException("knots", "The Spline knots list cannot be null.");
            if (knots.Length != controlPoints.Count + degree + 1)
                throw new ArgumentException("The number of knots must be equals to the number of control points + spline degree + 1.");

            this.controlPoints = controlPoints;
            this.knots = knots;
            this.degree = degree;
            this.isPeriodic = this.PeriodicTest(controlPoints, degree);
            if (this.isPeriodic)
            {
                this.isClosed = true;
                this.flags = SplineTypeFlags.Closed | SplineTypeFlags.Periodic | SplineTypeFlags.Rational;
            }
            else
            {
                this.isClosed = controlPoints[0].Location.Equals(controlPoints[controlPoints.Count - 1].Location);
                this.flags = this.isClosed ? SplineTypeFlags.Closed | SplineTypeFlags.Rational : SplineTypeFlags.Rational;
            }
        }
Esempio n. 4
0
        /// <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;
        }
Esempio n. 5
0
        /// <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;
        }
Esempio n. 6
0
        /// <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;
            }
        }
Esempio n. 7
0
 /// <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;
 }
Esempio n. 8
0
        /// <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), "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.");
            if (knots == null)
                throw new ArgumentNullException(nameof(knots), "The Spline knots list cannot be null.");
            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;
            }
        }