public void writeWithGuideBack(CPNSideEdge guide, int N, float step, OutputMesh mesh,
                                       CPNGuideEvaluator evaluator)
        {
            this.step = step;
            requestSize(N + 1);

            //We should have only one thickness on multisided edge, you know?
            this.thickness = 1;

            for (int i = 0; i <= N; i++)
            {
                //This is the eval-back
                evaluator.EvalAt(1.0f - i * step, guide);
                Vector3 dev = evaluator.EvalDev(guide);
                vertices[i] = evaluator.EvalVertex(guide);
                if (i == 0)
                {
                    devFirst = dev;
                }
                if (i == N)
                {
                    devLast = dev;
                }
                evaluator.EvalAt(i * step + DELTA, guide);
                verticesDplus[i] = evaluator.EvalVertex(guide);
                evaluator.EvalAt(i * step - DELTA, guide);
                verticesDminus[i] = evaluator.EvalVertex(guide);
                normals[i]        = evaluator.EvalNormal(guide, dev).normalized;
                uvs[i]            = evaluator.EvalUV(guide);
                for (int k = 0; k < countP; k++)
                {
                    properties[k][i] = evaluator.EvalProperty(guide, k);
                }
            }
        }
        private Vector3 evalVertex(CPNSideEdge sidedEdgeA,
                                   CPNSideEdge sidedEdgeB, float U, float V)
        {
            //int backBIndex = bufferPrev.N - Bindex;

            evaluator.EvalAt(0, sidedEdgeA);
            Vector3 v0  = evaluator.EvalVertex(sidedEdgeA);
            Vector3 dA0 = evaluator.EvalDev(sidedEdgeA);

            evaluator.EvalAt(U, sidedEdgeA);
            Vector3 vA = evaluator.EvalVertex(sidedEdgeA);
            Vector3 nA = evaluator.EvalNormal(sidedEdgeA);

            evaluator.EvalAt(1 - V, sidedEdgeB);
            Vector3 vB = evaluator.EvalVertex(sidedEdgeB);
            Vector3 nB = evaluator.EvalNormal(sidedEdgeB);

            evaluator.EvalAt(1, sidedEdgeB);
            Vector3 dB0 = -evaluator.EvalDev(sidedEdgeB);

            float   kA    = -Vector3.Dot(dB0, nA);
            Vector3 part1 = vA + /*sidedEdgeA.guide[0].thickness **/ ((vB - v0) + kA * V * nA);

            float   kB    = -Vector3.Dot(dA0, nB);
            Vector3 part2 = vB + /*sidedEdgeB.guide[0].thickness * */ ((vA - v0) + kB * U * nB);

            float U2 = U * U;
            float V2 = V * V;

            return((part1 * U2 + part2 * V2) / (U2 + V2));
        }
        public Vector3 evalVertex(int sIndex, CPNSideEdge sidedEdge, float t)
        {
            int backSIndex = prev.N - sIndex;

            evaluator.EvalAt(t, sidedEdge);
            Vector3 A = evaluator.EvalVertex(sidedEdge);
            Vector3 B = prev.vertices[backSIndex];
            Vector3 C = next.vertices[sIndex];

            Vector3 A0 = buffer.vertices[0];
            Vector3 AN = buffer.vertices[buffer.N];

            float sB = 1 - prev.ts[backSIndex];
            float sC = prev.ts[sIndex];
            float s  = (1 - t) * sB + t * sC;

            float size = (1 - s) * (1 - s) * (1 - s) /* * s0[==1] */ +
                         (s1 * (1 - s) * (1 - s) + s2 * s * (1 - s) + s3 * s * s) * s;

            if (!CPNCornerSet.applySecondOrderControl)
            {
                size = 1;
            }

            Vector3 firstOrder = GetFirstOrder(t);

            Vector3 At = (1 - t) * A0 + t * AN;
            //Vector3 PA = A - At;
            Vector3 PA  = (A - At) * size;
            Vector3 PBC = (1 - t) * B + t * C;


            //if (CPNCornerSet.applySecondOrderControl)
            //{
            return(PA + PBC + firstOrder * (1 - s) * (1 - s) * s /** (1 - s * s)+
                                                                  * ((1 - t) * B + t * C ) * (s * s)*/);
            //}
            //else
            //{
            //   return PA+PBC;
            //}
        }
        private float approximateGuideSize(CPNGuide guide)
        {
            CPNGuideEvaluator evaluator = new CPNGuideEvaluator();
            int     STEPS    = 8;
            float   step     = 1.0f / STEPS;
            Vector3 preV     = guide.vBuffer[0];
            float   distance = 0;

            for (int i = 1; i <= STEPS; i++)
            {
                evaluator.EvalAt(i * step, guide);
                Vector3 V = evaluator.EvalVertex(guide);
                distance += Vector3.Distance(V, preV);
                preV      = V;
            }
            if (distance == 0)
            {
                distance = 0.001f;
            }
            return(distance);
        }