public int Compare(DimHolder x, DimHolder y) { int result; //Uncomment this to resort original functionality //if (x.Item.Weight + Weight > DimensionalWeight) { result = -(ItemsPackedQty[x.Item.Id].CompareTo(ItemsPackedQty[y.Item.Id])); if (result != 0) { return(result); } } result = -((x.Item.Weight + Weight - DimensionalWeight).CompareTo((y.Item.Weight + Weight - DimensionalWeight))); if (result != 0) { return(result); } result = (x.Dims.Y - Thickness).CompareTo(y.Dims.Y - Thickness); if (result != 0) { return(result); } result = (Gap.X - x.Dims.X).CompareTo(Gap.X - y.Dims.X); if (result != 0) { return(result); } result = Math.Abs(GapZStart - x.Dims.Z).CompareTo(Math.Abs(GapZStart - y.Dims.Z)); if (result != 0) { return(result); } return(0); }
public int Compare(DimHolder x, DimHolder y) { int result; if (x.Item.Weight + Weight > DimensionalWeight) { result = -(ItemsPackedQty[x.Item.Id].CompareTo(ItemsPackedQty[y.Item.Id])); if (result != 0) { return(result); } } result = -((x.Item.Weight + Weight - DimensionalWeight).CompareTo((y.Item.Weight + Weight - DimensionalWeight))); if (result != 0) { return(result); } result = (Thickness - x.Dims.Y).CompareTo(Thickness - y.Dims.Y); if (result != 0) { return(result); } result = (Gap.X - x.Dims.X).CompareTo(Gap.X - y.Dims.X); if (result != 0) { return(result); } result = Math.Abs(GapZStart - x.Dims.Z).CompareTo(Math.Abs(GapZStart - y.Dims.Z)); if (result != 0) { return(result); } return(0); }
private Item FindBox(Vector3 gap, double gapZStart, DimHolder[] items) { Item boxi = null; Item bboxi = null; var candidatesThatFit = new DimHolder[items.Length]; { var newSize = 0; foreach (var x in items) { if (x.Item.Quantity > 0 && x.Dims.Fits(gap) && x.Dims.Y <= Thickness) { candidatesThatFit[newSize++] = x; } } Array.Resize(ref candidatesThatFit, newSize); } if (candidatesThatFit.Length > 0) { var candidatesThatFitComparer = new Helper.CandidatesThatFitComparer(); candidatesThatFitComparer.Gap = gap; candidatesThatFitComparer.Thickness = Thickness; candidatesThatFitComparer.GapZStart = gapZStart; candidatesThatFitComparer.ItemsPackedQty = ItemsPackedQty; candidatesThatFitComparer.Weight = Weight; candidatesThatFitComparer.DimensionalWeight = DimensionalWeight; Array.Sort(candidatesThatFit, candidatesThatFitComparer); var best = candidatesThatFit[0]; boxi = best.Item; _box = best.Dims; } else { var candidatesThatDoNotFit = new DimHolder[items.Length]; var newSize = 0; foreach (var x in items) { if (x.Item.Quantity > 0 && x.Dims.Fits(gap) && !(x.Dims.Y <= Thickness)) { candidatesThatDoNotFit[newSize++] = x; } } Array.Resize(ref candidatesThatDoNotFit, newSize); if (candidatesThatDoNotFit.Length > 0) { var candidatesThatDoNotFitComparer = new Helper.CandidatesThatDoNotFitComparer(); candidatesThatDoNotFitComparer.Gap = gap; candidatesThatDoNotFitComparer.Thickness = Thickness; candidatesThatDoNotFitComparer.GapZStart = gapZStart; candidatesThatDoNotFitComparer.ItemsPackedQty = ItemsPackedQty; candidatesThatDoNotFitComparer.Weight = Weight; candidatesThatDoNotFitComparer.DimensionalWeight = DimensionalWeight; Array.Sort(candidatesThatDoNotFit, candidatesThatDoNotFitComparer); var best = candidatesThatDoNotFit[0]; bboxi = best.Item; _bbox = best.Dims; } } return(CheckFound(boxi, bboxi)); }