示例#1
0
        private static IBSplineCurveEntity ByPointsCore(ref DSPoint[] points, DSVector startTangent, DSVector endTangent, bool makePeriodic)
        {
            IPointEntity[] hosts = points.ConvertAll(DSGeometryExtension.ToEntity <DSPoint, IPointEntity>);
            if (hosts == null || hosts.Length < 2)
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "points"), "points");
            }
            if (hosts.AreCoincident())
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.PointsCoincident, "points"), "points"); //Can't create BSpline curve with all coincident points.
            }
            IBSplineCurveEntity ent = null;

            if (null != startTangent && null != endTangent)
            {
                ent = HostFactory.Factory.BSplineByPoints(hosts, startTangent.IVector, endTangent.IVector);
            }
            else
            {
                ent = HostFactory.Factory.BSplineByPoints(hosts, makePeriodic);
            }
            if (ent == null)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "DSBSplineCurve.ByPoints"));
            }
            points = hosts.ToArray <DSPoint, IPointEntity>(false);
            return(ent);
        }
 public void WriteObject(IBSplineCurveEntity entity)
 {
     IPointEntity[] points = entity.GetControlVertices();
     WriteEntity <IPointEntity>("ControlVertices", points);
     WriteInteger("Degree", entity.GetDegree());
     WriteBoolean("IsPeriodic", entity.GetIsPeriodic());
 }
        public IBSplineCurveEntity ReadBSplineCurve()
        {
            Object data     = GetData("ControlVertices");
            Array  vertices = data as Array;

            if (null == vertices)
            {
                throw new DataMisalignedException(string.Format("Invalid data : {0} for parameter {1}", data, "ControlVertices"));
            }

            GeometryDataSerializer stream = new GeometryDataSerializer(vertices);
            List <IPointEntity>    points = new List <IPointEntity>();

            foreach (var item in stream)
            {
                points.Add(stream.ReadPoint());
            }

            int  degree   = ReadInteger("Degree");
            bool periodic = ReadBoolean("IsPeriodic");

            IBSplineCurveEntity entity = HostFactory.Factory.BSplineByControlVertices(points.ToArray(), degree, periodic);

            points.ForEach(GeometryExtension.DisposeObject);
            return(entity);
        }
        public string WriteEntity(IBSplineCurveEntity bspline, string paramName = null)
        {
            if (string.IsNullOrEmpty(paramName))
            {
                paramName = string.Format("__bspline_{0}", ++id);
            }

            IPointEntity[] points = bspline.GetControlVertices();
            string         cp     = WriteEntities(points);

            mExpression.AppendFormat("{0} = BSplineCurve.ByControlVertices({1}, {2}, {3});", paramName, cp, bspline.GetDegree(), bspline.GetIsPeriodic());
            mExpression.AppendLine();
            return(paramName);
        }
示例#5
0
 private DSBSplineCurve(IBSplineCurveEntity host, bool persist = false)
     : base(host, persist)
 {
     InitializeGuaranteedProperties();
 }
示例#6
0
 private DSBSplineCurve(IBSplineCurveEntity host, bool persist = false)
     : base(host, persist)
 {
     InitializeGuaranteedProperties();
 }