private void DrawSpansBetweenEdges(Edge e1, Edge e2)
        {
            // calculate difference between the y coordinates
            // of the first edge and return if 0
            float e1ydiff = (float)(e1.Y2 - e1.Y1);
            if(e1ydiff == 0.0f)
                return;

            // calculate difference between the y coordinates
            // of the second edge and return if 0
            float e2ydiff = (float)(e2.Y2 - e2.Y1);
            if(e2ydiff == 0.0f)
                return;

            // calculate differences between the x coordinates
            // and colors of the points of the edges
            float e1xdiff = (float)(e1.X2 - e1.X1);
            float e2xdiff = (float)(e2.X2 - e2.X1);
            MyColor e1colordiff = e1.Color2 - e1.Color1;
            MyColor e2colordiff = e2.Color2 - e2.Color1;

            // calculate factors to use for interpolation
            // with the edges and the step values to increase
            // them by after drawing each span
            float factor1 = (float)(e2.Y1 - e1.Y1) / e1ydiff;
            float factorStep1 = 1.0f / e1ydiff;
            float factor2 = 0.0f;
            float factorStep2 = 1.0f / e2ydiff;

            // loop through the lines between the edges and draw spans
            for(int y = e2.Y1; y < e2.Y2; y++)
            {
                // create and draw span
                Span span = new Span(e1.Color1 + (e1colordiff * factor1),
                                      e1.X1 + (int)(e1xdiff * factor1),
                                      e2.Color1 + (e2colordiff * factor2),
                                      e2.X1 + (int)(e2xdiff * factor2)
                                      );

                DrawSpan(span, y);

                // increase factors
                factor1 += factorStep1;
                factor2 += factorStep2;
            }
        }
        private void RemoveSpansBetweenEdges(Edge e1, Edge e2)
        {
            float e1ydiff = (float)(e1.Y2 - e1.Y1);
            if (e1ydiff == 0.0f)
                return;

            float e2ydiff = (float)(e2.Y2 - e2.Y1);
            if (e2ydiff == 0.0f)
                return;

            float e1xdiff = (float)(e1.X2 - e1.X1);
            float e2xdiff = (float)(e2.X2 - e2.X1);

            float factor1 = (float)(e2.Y1 - e1.Y1) / e1ydiff;
            float factorStep1 = 1.0f / e1ydiff;
            float factor2 = 0.0f;
            float factorStep2 = 1.0f / e2ydiff;

            // loop through the lines between the edges and draw spans
            for (int y = e2.Y1; y < e2.Y2; y++)
            {
                // create and draw span
                Span span = new Span(e1.X1 + (int)(e1xdiff * factor1),
                                      e2.X1 + (int)(e2xdiff * factor2)
                                      );

                RemoveSpan(span, y);

                // increase factors
                factor1 += factorStep1;
                factor2 += factorStep2;
            }
        }
        private void DrawSpan(Span span, int y)
        {
            int xdiff = span.X2 - span.X1;
            if (xdiff == 0)
                return;

            MyColor colordiff = span.Color2 - span.Color1;

            float factor = 0.0f;
            float factorStep = 1.0f / (float)xdiff;

            // draw each pixel in the span
            for (int x = span.X1; x < span.X2; x++)
            {
                SetPixel(x, y, span.Color1 + (colordiff * factor));
                factor += factorStep;
            }
        }
        private void RemoveSpan(Span span, int y)
        {
            int xdiff = span.X2 - span.X1;
            if (xdiff == 0)
                return;
            float factor = 0.0f;
            float factorStep = 1.0f / (float)xdiff;

            // draw each pixel in the span
            for (int x = span.X1; x < span.X2; x++)
            {
                Cl3DModel model = Map[x, y].GetManagedModel();

                model.RemovePointFromModel(Map[x, y]);
                Map[x, y] = null;

                factor += factorStep;
            }
        }