public PixelFarm.Drawing.RectangleF GetBounds() { if (_hasBounds) { return(_bounds); } else { //calculate here RectBoundsAccum boundsAccum = new RectBoundsAccum(); boundsAccum.Init(); //Must for (int i = 0; i < coordXYs.Length;) { boundsAccum.Update(coordXYs[i], coordXYs[i + 1]); i += 2; } _hasBounds = true; return(boundsAccum.ToRectF()); } }
public FigureContainer Build(PixelFarm.Drawing.VertexStore vxs) { //vxs must be flatten vxs. #if DEBUG double prevX = 0; double prevY = 0; #endif double prevMoveToX = 0; double prevMoveToY = 0; _xylist.Clear(); _figs.Clear(); //TODO: reivew here //about how to reuse this list //result... RectBoundsAccum rectBoundsAccum = new RectBoundsAccum(); rectBoundsAccum.Init(); int index = 0; VertexCmd cmd; while ((cmd = vxs.GetVertex(index++, out double x, out double y)) != VertexCmd.NoMore) { switch (cmd) { case VertexCmd.MoveTo: #if DEBUG prevX = x; prevY = y; #endif prevMoveToX = x; prevMoveToY = y; _xylist.Add((float)x); _xylist.Add((float)y); rectBoundsAccum.Update(x, y); break; case VertexCmd.LineTo: _xylist.Add((float)x); _xylist.Add((float)y); #if DEBUG prevX = x; prevY = y; #endif rectBoundsAccum.Update(x, y); break; case VertexCmd.Close: { //don't add //_xylist.Add((float)prevMoveToX); //_xylist.Add((float)prevMoveToY); #if DEBUG prevX = prevMoveToX; prevY = prevMoveToY; #endif //----------- Figure newfig = new Figure(_xylist.ToArray(), rectBoundsAccum.ToRectF()); newfig.IsClosedFigure = true; _figs.Add(newfig); //----------- _xylist.Clear(); //clear temp list rectBoundsAccum.Init(); } break; case VertexCmd.NoMore: goto EXIT_LOOP; default: throw new System.NotSupportedException(); } } EXIT_LOOP: if (_figs.Count == 0) { Figure newfig = new Figure(_xylist.ToArray(), rectBoundsAccum.ToRectF()); newfig.IsClosedFigure = false; return(new FigureContainer(newfig)); } // if (_xylist.Count > 1) { #if DEBUG prevX = prevMoveToX; prevY = prevMoveToY; #endif // Figure newfig = new Figure(_xylist.ToArray(), rectBoundsAccum.ToRectF()); 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)); } }