Example #1
0
        private static IBSplineSurfaceEntity ByPointsCore(ref Point[][] points, int uDegree, int vDegree)
        {
            if (uDegree < 2)
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "uDegree", "two"), "uDegree");
            if (uDegree > 10)
                throw new System.ArgumentException(string.Format(Properties.Resources.GreaterThan, "uDegree", "ten"), "uDegree");
            if (vDegree < 2)
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "vDegree", "two"), "vDegree");
            if (vDegree > 10)
                throw new System.ArgumentException(string.Format(Properties.Resources.GreaterThan, "vDegree", "ten"), "vDegree");

            IPointEntity[][] pts = points.ToPointEntityArray(true); //must be rectangular array.
            if (null == pts)
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "points"), "points");

            // making sure if # of controlVertices > degree by atleast 1
            int udiff = pts.Length - uDegree;
            if (udiff < 1)
                uDegree += udiff - 1;

            int vdiff = pts[0].Length - vDegree;
            if (vdiff < 1)
                vDegree += vdiff - 1;

            if (pts.Length < 2)
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "Number of points in U direction", "two"), "points");
            if (pts[0].Length < 2)
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "Number of points in V direction", "two"), "points");

            points = pts.ToPointArray();
            IBSplineSurfaceEntity entity = HostFactory.Factory.BSplineSurfaceByPoints(pts, uDegree, vDegree);
            if (entity == null)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "BSplineSurface.ByPoints"));
            return entity;
        }