Example #1
0
        public static List <Poly2Tri.Polygon> GetTrianglulatedArea(this MultiFigures figures, bool yAxisPointDown)
        {
            List <Poly2Tri.Polygon> output = new List <Poly2Tri.Polygon>();

            GetTrianglulatedArea(figures, yAxisPointDown, output);
            return(output);
        }
Example #2
0
        public void PreparePolygons(MultiFigures figures, List <Poly2Tri.Polygon> outputPolygons)
        {
            using (ReusableCoordList.Borrow(out ReusableCoordList reuseableList))
            {
                Figure[] figs = figures._figures;
                for (int i = 0; i < figs.Length; ++i)
                {
                    Figure  fig       = figs[i];
                    float[] figCoords = fig.coordXYs;

                    float prevX = float.MaxValue;
                    float prevY = float.MinValue;

                    int startAt = reuseableList._coordXYs.Count;
                    for (int n = 0; n < figCoords.Length;)
                    {
                        float x = figCoords[n];
                        float y = figCoords[n + 1];
                        reuseableList._coordXYs.Append(prevX = x);
                        reuseableList._coordXYs.Append(prevY = y);
                        n += 2;
                    }


                    if (reuseableList._coordXYs[startAt] == prevX && reuseableList._coordXYs[startAt + 1] == prevY)
                    {
                        reuseableList._coordXYs.RemoveLast();
                        reuseableList._coordXYs.RemoveLast();
                    }

                    reuseableList._contourEndPoints.Append(reuseableList._coordXYs.Count - 1); //glyph convention
                }
                PreparePolygons(reuseableList._coordXYs.ToArray(), reuseableList._contourEndPoints.ToArray(), outputPolygons);
            }
        }
Example #3
0
 public static void GetTrianglulatedArea(this MultiFigures figures, bool yAxisPointDown, List <Poly2Tri.Polygon> output)
 {
     using (Poly2TriTool.Borrow(out Poly2TriTool poly2Tri))
     {
         poly2Tri.YAxisPointDown = yAxisPointDown;
         poly2Tri.PreparePolygons(figures, output);
         poly2Tri.Triangulate(output);
         figures.Poly2TriPolygons = output;
     }
 }
Example #4
0
 public FigureContainer(MultiFigures multiFig)
 {
     _figure   = null;
     _multiFig = multiFig;
 }
Example #5
0
 public FigureContainer(Figure fig)
 {
     _figure   = fig;
     _multiFig = null;
 }
Example #6
0
        public FigureContainer Build(PixelFarm.Drawing.VertexStore vxs)
        {
            //vxs must be flatten vxs.

            double prevX       = 0;
            double prevY       = 0;
            double prevMoveToX = 0;
            double prevMoveToY = 0;

            _xylist.Clear();
            _figs.Clear();
            //TODO: reivew here
            //about how to reuse this list
            //result...


            int       index = 0;
            VertexCmd cmd;

            double x, y;

            while ((cmd = vxs.GetVertex(index++, out x, out y)) != VertexCmd.NoMore)
            {
                switch (cmd)
                {
                case PixelFarm.CpuBlit.VertexCmd.MoveTo:

                    prevMoveToX = prevX = x;
                    prevMoveToY = prevY = y;
                    _xylist.Add((float)x);
                    _xylist.Add((float)y);
                    break;

                case PixelFarm.CpuBlit.VertexCmd.LineTo:
                    _xylist.Add((float)x);
                    _xylist.Add((float)y);
                    prevX = x;
                    prevY = y;
                    break;

                case PixelFarm.CpuBlit.VertexCmd.Close:
                {
                    //don't add
                    //_xylist.Add((float)prevMoveToX);
                    //_xylist.Add((float)prevMoveToY);

                    prevX = prevMoveToX;
                    prevY = prevMoveToY;
                    //-----------
                    Figure newfig = new Figure(_xylist.ToArray());
                    newfig.IsClosedFigure = true;

                    _figs.Add(newfig);
                    //-----------
                    _xylist.Clear();         //clear temp list
                }
                break;

                case PixelFarm.CpuBlit.VertexCmd.NoMore:
                    goto EXIT_LOOP;

                default:
                    throw new System.NotSupportedException();
                }
            }
EXIT_LOOP:

            if (_figs.Count == 0)
            {
                Figure newfig = new Figure(_xylist.ToArray());
                newfig.IsClosedFigure = false;
                return(new FigureContainer(newfig));
            }
            //
            if (_xylist.Count > 1)
            {
                prevX = prevMoveToX;
                prevY = prevMoveToY;
                //
                Figure newfig = new Figure(_xylist.ToArray());
                newfig.IsClosedFigure = true; //?
                _figs.Add(newfig);
            }

            if (_figs.Count == 1)
            {
                Figure fig = _figs[0];
                _figs.Clear();
                return(new FigureContainer(fig));
            }
            else
            {
                MultiFigures multiFig = new MultiFigures(_figs.ToArray());
                _figs.Clear();
                return(new FigureContainer(multiFig));
            }
        }