//--------------------------------------------------------------------
        public bool SweepScanline(IScanline sl)
        {
#if use_timers
            SweepSacanLine.Start();
#endif
            for (; ;)
            {
                if (m_scan_y > m_outline.MaxY())
                {
#if use_timers
                    SweepSacanLine.Stop();
#endif
                    return(false);
                }

                sl.ResetSpans();
                uint scan_y_uint = 0;                 // it is going to Get initialize to 0 anyway so make it Clear.
                if (m_scan_y > 0)
                {
                    scan_y_uint = (uint)m_scan_y;
                }
                uint num_cells = m_outline.ScanlineNumCells(scan_y_uint);
                AntiAliasingCell[] cells;
                uint Offset;
                m_outline.ScanlineCells(scan_y_uint, out cells, out Offset);
                int cover = 0;

                while (num_cells != 0)
                {
                    AntiAliasingCell cur_cell = cells[Offset];
                    int  x    = cur_cell.x;
                    int  area = cur_cell.area;
                    uint alpha;

                    cover += cur_cell.cover;

                    //accumulate all cells with the same X
                    while (--num_cells != 0)
                    {
                        Offset++;
                        cur_cell = cells[Offset];
                        if (cur_cell.x != x)
                        {
                            break;
                        }

                        area  += cur_cell.area;
                        cover += cur_cell.cover;
                    }

                    if (area != 0)
                    {
                        alpha = CalculateAlpha((cover << ((int)poly_subpixel_scale_e.Shift + 1)) - area);
                        if (alpha != 0)
                        {
                            sl.AddCell(x, alpha);
                        }
                        x++;
                    }

                    if ((num_cells != 0) && (cur_cell.x > x))
                    {
                        alpha = CalculateAlpha(cover << ((int)poly_subpixel_scale_e.Shift + 1));
                        if (alpha != 0)
                        {
                            sl.AddSpan(x, (cur_cell.x - x), alpha);
                        }
                    }
                }

                if (sl.NumberOfSpans != 0)
                {
                    break;
                }
                ++m_scan_y;
            }

            sl.Finalize(m_scan_y);
            ++m_scan_y;
#if use_timers
            SweepSacanLine.Stop();
#endif
            return(true);
        }
        ///<summary>
        ///</summary>
        ///<returns></returns>
        ///<exception cref="NotImplementedException"></exception>
        public uint SweepStyles()
        {
            for (; ;)
            {
                if (_scanY > _rasterizer.MaxY())
                {
                    return(0);
                }
                int numCells = (int)_rasterizer.ScanlineNumCells((uint)_scanY);
                AntiAliasingCell[] cells;
                uint cellOffset;
                _rasterizer.ScanlineCells((uint)_scanY, out cells, out cellOffset);
                uint numStyles   = (uint)(_maxStyle - _minStyle + 2);
                int  styleOffset = 0;

                _cells.Allocate((uint)numCells * 2, 256);                 // Each cell can have two Styles
                _activeStyleTable.Capacity(numStyles, 64);
                _activeStyleMask.Allocate((numStyles + 7) >> 3, 8);
                _activeStyleMask.Zero();

                if (numCells > 0)
                {
                    // Pre-Add zero (for no-fill Style, that is, -1).
                    // We need that to ensure that the "-1 Style" would go first.
                    _activeStyleMask.Array[0] |= 1;
                    _activeStyleTable.Add(0);
                    _activeStyles.Array[styleOffset].StartCell = 0;
                    _activeStyles.Array[styleOffset].NumCells  = 0;
                    _activeStyles.Array[styleOffset].LastX     = -0x7FFFFFFF;

                    _scanlineStart  = cells[0].x;
                    _scanlineLength = (uint)(cells[numCells - 1].x - _scanlineStart + 1);
                    int curCellOffset;
                    while (numCells-- != 0)
                    {
                        curCellOffset = (int)cellOffset++;
                        AddStyle(cells[curCellOffset].left);
                        AddStyle(cells[curCellOffset].right);
                    }

                    // Convert the Y-histogram into the array of starting indexes
                    uint        i             = 0u;
                    uint        startCell     = 0;
                    StyleInfo[] stylesArray   = _activeStyles.Array;
                    int         indexToModify = (int)_activeStyleTable[i];
                    for (i = 0; i < _activeStyleTable.Size(); i++)
                    {
                        uint v = stylesArray[indexToModify].StartCell;
                        stylesArray[indexToModify].StartCell = startCell;
                        startCell += v;
                    }

                    numCells = (int)_rasterizer.ScanlineNumCells((uint)_scanY);
                    _rasterizer.ScanlineCells((uint)_scanY, out cells, out cellOffset);

                    while (numCells-- > 0)
                    {
                        curCellOffset = (int)cellOffset;
                        uint styleId = (uint)((cells[curCellOffset].left < 0) ? 0 :
                                              cells[curCellOffset].left - _minStyle + 1);

                        styleOffset = (int)styleId;
                        if (cells[curCellOffset].x == stylesArray[styleOffset].LastX)
                        {
                            cellOffset = stylesArray[styleOffset].StartCell + stylesArray[styleOffset].NumCells - 1;
                            unchecked
                            {
                                cells[cellOffset].area  += cells[curCellOffset].area;
                                cells[cellOffset].cover += cells[curCellOffset].cover;
                            }
                        }
                        else
                        {
                            cellOffset                     = stylesArray[styleOffset].StartCell + stylesArray[styleOffset].NumCells;
                            cells[cellOffset].x            = cells[curCellOffset].x;
                            cells[cellOffset].area         = cells[curCellOffset].area;
                            cells[cellOffset].cover        = cells[curCellOffset].cover;
                            stylesArray[styleOffset].LastX = cells[curCellOffset].x;
                            stylesArray[styleOffset].NumCells++;
                        }

                        styleId = (uint)((cells[curCellOffset].right < 0) ? 0 :
                                         cells[curCellOffset].right - _minStyle + 1);

                        styleOffset = (int)styleId;
                        if (cells[curCellOffset].x == stylesArray[styleOffset].LastX)
                        {
                            cellOffset = stylesArray[styleOffset].StartCell + stylesArray[styleOffset].NumCells - 1;
                            unchecked
                            {
                                cells[cellOffset].area  -= cells[curCellOffset].area;
                                cells[cellOffset].cover -= cells[curCellOffset].cover;
                            }
                        }
                        else
                        {
                            cellOffset                     = stylesArray[styleOffset].StartCell + stylesArray[styleOffset].NumCells;
                            cells[cellOffset].x            = cells[curCellOffset].x;
                            cells[cellOffset].area         = -cells[curCellOffset].area;
                            cells[cellOffset].cover        = -cells[curCellOffset].cover;
                            stylesArray[styleOffset].LastX = cells[curCellOffset].x;
                            stylesArray[styleOffset].NumCells++;
                        }
                    }
                }
                if (_activeStyleTable.Size() > 1)
                {
                    break;
                }
                ++_scanY;
            }
            ++_scanY;

            if (_layerOrder != ELayerOrder.LayerUnsorted)
            {
                VectorPOD_RangeAdaptor ra = new VectorPOD_RangeAdaptor(_activeStyleTable, 1, _activeStyleTable.Size() - 1);
                if (_layerOrder == ELayerOrder.LayerDirect)
                {
                    QuickSortRangeAdaptorUint mQSorter = new QuickSortRangeAdaptorUint();
                    mQSorter.Sort(ra);
                    //quick_sort(ra, uint_greater);
                }
                else
                {
                    throw new NotImplementedException();
                    //QuickSortRangeAdaptorUint m_QSorter = new QuickSortRangeAdaptorUint();
                    //m_QSorter.Sort(ra);
                    //quick_sort(ra, uint_less);
                }
            }

            return(_activeStyleTable.Size() - 1);
        }