Index: branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/3D/BinPacking3D.cs
===================================================================
--- branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/3D/BinPacking3D.cs	(revision 14977)
+++ branches/BinPackingExtension/HeuristicLab.Problems.BinPacking/3.3/3D/BinPacking3D.cs	(revision 15229)
@@ -144,5 +144,4 @@
 
     public override PackingPosition FindExtremePointForItem(PackingItem item, bool rotated, bool stackingConstraints) {
-
       PackingItem newItem = new PackingItem(
         rotated ? item.Depth : item.Width,
@@ -151,15 +150,7 @@
         item.TargetBin, item.Weight, item.Material);
 
-      int epIndex = 0;
-      while (epIndex < ExtremePoints.Count && (
-        !IsPositionFeasible(newItem, ExtremePoints.ElementAt(epIndex))
-        || !IsSupportedByAtLeastOnePoint(newItem, ExtremePoints.ElementAt(epIndex))
-        || (stackingConstraints && !IsStaticStable(newItem, ExtremePoints.ElementAt(epIndex)))
-        || (stackingConstraints && !IsWeightSupported(newItem, ExtremePoints.ElementAt(epIndex)))
-      )) { epIndex++; }
-
-      if (epIndex < ExtremePoints.Count) {
-        var origPoint = ExtremePoints.ElementAt(epIndex);
-        var result = new PackingPosition(origPoint.AssignedBin, origPoint.X, origPoint.Y, origPoint.Z, rotated);
+      var ep = ExtremePoints.Where(x => IsPositionFeasible(newItem, x, stackingConstraints)).FirstOrDefault();
+      if (ep != null) {
+        var result = new PackingPosition(ep.AssignedBin, ep.X, ep.Y, ep.Z, rotated);
         return result;
       }
@@ -167,6 +158,12 @@
     }
 
-    public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated) {
-      //TODO: does not support stacking constraints yet
+    public override bool IsPositionFeasible(PackingItem item, PackingPosition position, bool stackingConstraints) {
+      var feasible = base.IsPositionFeasible(item, position, stackingConstraints);
+      return feasible
+        && IsSupportedByAtLeastOnePoint(item, position)
+        && (!stackingConstraints || (IsStaticStable(item, position) && IsWeightSupported(item, position)));
+    }
+
+    public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated, bool stackingConstraints) {
       //Starting-position at upper right corner (=left bottom point of item-rectangle is at position item.width,item.height)
       PackingPosition currentPosition = new PackingPosition(0,
@@ -175,29 +172,29 @@
         BinShape.Depth - (rotated ? item.Width : item.Depth), rotated);
       //Slide the item as far as possible to the bottom
-      while (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition))
-        || IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition))
-        || IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition))) {
+      while (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition), stackingConstraints)
+        || IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition), stackingConstraints)
+        || IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition), stackingConstraints)) {
         //Slide the item as far as possible to the left
-        while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition))
-      || IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition))) {
+        while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition), stackingConstraints)
+      || IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition), stackingConstraints)) {
           //Slide the item as far as possible to the back
-          while (IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition))) {
+          while (IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition), stackingConstraints)) {
             currentPosition = PackingPosition.MoveBack(currentPosition);
           }
-          if (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition)))
+          if (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition), stackingConstraints))
             currentPosition = PackingPosition.MoveLeft(currentPosition);
         }
-        if (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition)))
+        if (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition), stackingConstraints))
           currentPosition = PackingPosition.MoveDown(currentPosition);
       }
 
-      return IsPositionFeasible(item, currentPosition) ? currentPosition : null;
-    }
-
-    public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items) {
+      return IsPositionFeasible(item, currentPosition, stackingConstraints) ? currentPosition : null;
+    }
+
+    public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints) {
       var temp = new List<int>(sequence);
       for (int i = 0; i < temp.Count; i++) {
         var item = items[temp[i]];
-        var position = FindPositionBySliding(item, false);
+        var position = FindPositionBySliding(item, false, stackingConstraints);
         if (position != null) {
           PackItem(temp[i], item, position);
@@ -206,9 +203,9 @@
       }
     }
-    public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, Dictionary<int, bool> rotationArray) {
+    public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, Dictionary<int, bool> rotationArray, bool stackingConstraints) {
       var temp = new List<int>(sequence);
       for (int i = 0; i < temp.Count; i++) {
         var item = items[temp[i]];
-        var position = FindPositionBySliding(item, rotationArray[i]);
+        var position = FindPositionBySliding(item, rotationArray[i], stackingConstraints);
         if (position != null) {
           PackItem(temp[i], item, position);
@@ -231,13 +228,4 @@
       }
     }
-    public override bool ExtremePointBasedPacking(int itemID, IList<PackingItem> items, bool stackingConstraints) {
-      var item = items[itemID];
-      var positionFound = FindExtremePointForItem(item, false, stackingConstraints);
-      if (positionFound != null) {
-       PackItem(itemID, item, positionFound);
-       return true;
-      }
-      return false;
-    }
     public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints, Dictionary<int, bool> rotationArray) {
       var temp = new List<int>(sequence);
@@ -319,5 +307,4 @@
       return false;
     }
-
 
     protected override void InitializeOccupationLayers() {
@@ -370,9 +357,4 @@
       return;
     }
-    public int GetResidualSpace(PackingItem item, PackingPosition ep) {
-      return ((ResidualSpace[ep].Item1 - item.Width) +
-          (ResidualSpace[ep].Item2 - item.Height) +
-          (ResidualSpace[ep].Item3 - item.Depth));
-      }
-    }
   }
+}
