public void Evaluate(int SpreadMax)
        {
            if (FRectangle.IsChanged || FMaxBins.IsChanged || FDiscardBelow.IsChanged || FBox.IsChanged)
            {
                var binlist    = new List <RectBin>();
                var rectlistin = new RectXywhFlipped[FRectangle.SliceCount];
                for (int i = 0; i < FRectangle.SliceCount; i++)
                {
                    rectlistin[i] = new RectXywhFlipped
                    {
                        FWidth  = FRectangle[i].x,
                        FHeight = FRectangle[i].y,
                        ID      = i,
                        Left    = 0, Top = 0, Flipped = false
                    };
                }
                FSuccess[0] = RectPackHelper.Pack(rectlistin, FBox[0], FDiscardBelow[0], binlist, FMaxBins[0]);

                FPacked.SliceCount  = binlist.Count;
                FID.SliceCount      = binlist.Count;
                FDim.SliceCount     = binlist.Count;
                FFlipped.SliceCount = binlist.Count;

                for (int i = 0; i < binlist.Count; i++)
                {
                    FPacked[i].SliceCount  = binlist[i].Rects.Count;
                    FID[i].SliceCount      = binlist[i].Rects.Count;
                    FFlipped[i].SliceCount = binlist[i].Rects.Count;
                    FDim[i] = binlist[i].Size;

                    for (int j = 0; j < FPacked[i].SliceCount; j++)
                    {
                        var rect = binlist[i].Rects[j];
                        FPacked[i][j]  = new Vector4D(rect.Left, rect.Top, rect.Width(), rect.Height());
                        FFlipped[i][j] = rect.Flipped;
                        FID[i][j]      = rect.ID;
                    }
                }
            }
        }
Beispiel #2
0
        public void Evaluate(int SpreadMax)
        {
            FOut.Stream.IsChanged = false;
            if (
                SpreadUtils.AnyChanged(FRectangle, FMaxBins, FDiscardBelow, FBox, FAllowRot) ||
                _pgready && _typeChanged
                )
            {
                FOut.Stream.IsChanged = true;

                int sprmax = Math.Max(FRectangle.SliceCount, FBox.SliceCount);

                if (FRectangle.SliceCount == 0 || FBox.SliceCount == 0)
                {
                    sprmax = 0;
                }

                FOut.SliceCount = FDim.SliceCount = FSuccess.SliceCount = sprmax;
                if (sprmax == 0)
                {
                    return;
                }

                for (int bi = 0; bi < sprmax; bi++)
                {
                    var binlist    = new List <RectBin>();
                    var rectlistin = new RectXywhFlipped[FRectangle[bi].SliceCount];

                    for (int i = 0; i < FRectangle[bi].SliceCount; i++)
                    {
                        object attachment = null;

                        if (_pgready)
                        {
                            attachment = _attachment.GetSlice <ISpread>(bi, null)?[i];
                        }

                        rectlistin[i] = new RectXywhFlipped
                        {
                            Attachment = attachment,
                            FWidth     = FRectangle[bi][i].x,
                            FHeight    = FRectangle[bi][i].y,
                            ID         = i,
                            Left       = 0,
                            Top        = 0,
                            Flipped    = false
                        };
                    }
                    FSuccess[bi] = RectPackHelper.Pack(rectlistin, FBox[bi].x, FBox[bi].y, FDiscardBelow[0], binlist, FMaxBins[0], FAllowRot[0]);

                    FOut[bi].SliceCount = FDim[bi].SliceCount = binlist.Count;

                    for (int i = 0; i < binlist.Count; i++)
                    {
                        FOut[bi][i] = binlist[i];
                        FDim[bi][i] = binlist[i].Size;
                    }
                }
            }
            if (_typeChanged)
            {
                _typeChanged = false;
            }
        }
Beispiel #3
0
        public RectNode Insert(RectXywhFlipped rin, bool allowflip)
        {
            if (C[0] == null)
            {
                C[0] = new RectPNode();
            }
            if (C[1] == null)
            {
                C[1] = new RectPNode();
            }
            if ((C[0].PNode != null) && C[0].Fill)
            {
                var newn = C[0].PNode.Insert(rin, allowflip);
                return(newn ?? C[1].PNode.Insert(rin, allowflip));
            }
            if (Id)
            {
                return(null);
            }
            var fit = rin.Fits(Rectangle, allowflip);

            switch (fit)
            {
            case 0:
                return(null);

            case 1:
                rin.Flipped = false;
                break;

            case 2:
                rin.Flipped = true;
                break;

            case 3:
                Id          = true;
                rin.Flipped = false;
                return(this);

            case 4:
                Id          = true;
                rin.Flipped = true;
                return(this);
            }

            var iw = rin.Flipped ? rin.Height : rin.Width;
            var ih = rin.Flipped ? rin.Width : rin.Height;

            if (Rectangle.Width - iw > Rectangle.Height - ih)
            {
                C[0].Set(Rectangle.Left, Rectangle.Top, Rectangle.Left + iw, Rectangle.Bottom);
                C[1].Set(Rectangle.Left + iw, Rectangle.Top, Rectangle.Right, Rectangle.Bottom);
            }
            else
            {
                C[0].Set(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Top + ih);
                C[1].Set(Rectangle.Left, Rectangle.Top + ih, Rectangle.Right, Rectangle.Bottom);
            }

            return(C[0].PNode.Insert(rin, allowflip));
        }