public RectXYWH(RectWH r, object a = null) { Width = r.Width; Height = r.Height; X = 0.0f; Y = 0.0f; Attachment = a ?? r.Attachment; }
public RectFlipXYWH(RectWH r, object a = null) { Width = r.Width; Height = r.Height; X = 0.0f; Y = 0.0f; Flipped = false; Attachment = a ?? r.Attachment; }
public static CreatedSplits InsertAndSplit(RectWH im, SpaceRect sp) { var freeW = sp.Width - im.Width; var freeH = sp.Height - im.Height; if (freeW < 0 || freeH < 0) { return(CreatedSplits.Failed); } if (freeW.Eq() && freeH.Eq()) { return(CreatedSplits.None); } if (freeW > 0.0f && freeH.Eq()) { var r = sp; r.X += im.Width; r.Width -= im.Width; return(new CreatedSplits(r)); } if (freeW.Eq() && freeH > 0) { var r = sp; r.Y += im.Height; r.Height -= im.Height; return(new CreatedSplits(r)); } if (freeW > freeH) { var bs = new SpaceRect(sp.X + im.Width, sp.Y, freeW, sp.Height); var ls = new SpaceRect(sp.X, sp.Y + im.Height, im.Width, freeH); return(new CreatedSplits(bs, ls)); } var biggersplit = new SpaceRect(sp.X, sp.Y + im.Height, sp.Width, freeH); var lessersplit = new SpaceRect(sp.X + im.Width, sp.Y, freeW, im.Height); return(new CreatedSplits(biggersplit, lessersplit)); }
public bool Insert(RectWH imagerect, out RectFlipXYWH outresult, Action <SpaceRect> reportCandidateEmptySpace = null) { for (int i = Spaces.Count - 1; i >= 0; i--) { var candidateSpace = Spaces[i]; reportCandidateEmptySpace?.Invoke(candidateSpace); RectFlipXYWH AcceptResult(CreatedSplits splits, bool flippingNecessary) { Spaces.Remove(i); for (int s = 0; s < splits.Count; s++) { Spaces.Add(splits.Spaces[s]); } var result = new RectFlipXYWH( candidateSpace.X, candidateSpace.Y, imagerect.Width, imagerect.Height, AllowFlip && flippingNecessary, imagerect.Attachment ); CurrentAABB = CurrentAABB.ExpandWith <RectWH, RectFlipXYWH>(result); return(result); } CreatedSplits TryToInsert(RectWH img) => CreatedSplits.InsertAndSplit(img, candidateSpace); if (AllowFlip) { var normal = TryToInsert(imagerect); var flipped = TryToInsert(imagerect.Flip()); if (normal && flipped) { outresult = flipped.BetterThan(normal) ? AcceptResult(flipped, true) : AcceptResult(normal, false); return(true); } if (normal) { outresult = AcceptResult(normal, false); return(true); } if (flipped) { outresult = AcceptResult(flipped, true); return(true); } } else { var normal = TryToInsert(imagerect); if (normal) { outresult = AcceptResult(normal, false); return(true); } } } outresult = new RectFlipXYWH(); return(false); }
public void Reset(RectWH r) { CurrentAABB = new RectWH(); Spaces.Reset(); Spaces.Add(new SpaceRect(r)); }
public EmptySpaces(RectWH r, int spacescap = 16384) { Spaces = new EmptySpaceList(spacescap); Reset(r); }