- Timestamp:
- 01/12/16 10:42:58 (8 years ago)
- Location:
- branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/CuboidPackingShape.cs
r13461 r13497 21 21 22 22 using System; 23 using System.Diagnostics; 23 24 using HeuristicLab.Problems.BinPacking.Interfaces; 24 25 using HeuristicLab.Core; … … 148 149 149 150 public int CompareTo(object obj) { 150 if (obj.GetType() == this.GetType())151 return this.CompareTo((CuboidPackingShape)obj);152 else return 0;151 var other = (CuboidPackingShape)obj; 152 if (other != null) return CompareTo(other); 153 else throw new ArgumentException(string.Format("Cannot compare with object {0}", obj), "obj"); 153 154 } 154 155 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/PackingShape.cs
r13461 r13497 30 30 [Item("PackingShape", "Represents an abstract shape to describe the measures and the positioning of objects related to bin-packing problems.")] 31 31 [StorableClass] 32 public abstract class PackingShape< D> : Item, IPackingShape33 where D: class, IPackingDimensions {32 public abstract class PackingShape<T> : Item, IPackingShape 33 where T : class, IPackingDimensions { 34 34 public static Type PositionType { 35 get { return typeof( D); }35 get { return typeof(T); } 36 36 } 37 37 38 public abstract bool EnclosesPoint( D myPosition, DcheckedPoint);39 public abstract bool Encloses( D checkedPosition, PackingShape<D> checkedShape);40 public abstract bool Overlaps( D myPosition, D checkedPosition, PackingShape<D> checkedShape);38 public abstract bool EnclosesPoint(T myPosition, T checkedPoint); 39 public abstract bool Encloses(T checkedPosition, PackingShape<T> checkedShape); 40 public abstract bool Overlaps(T myPosition, T checkedPosition, PackingShape<T> checkedShape); 41 41 public abstract void InitializeFromMeasures(int[] measures); 42 42 public abstract int[] ToArray(); 43 43 public abstract int MultipliedMeasures { get; } 44 public abstract DOrigin { get; }44 public abstract T Origin { get; } 45 45 46 46 protected PackingShape(int[] measures) { … … 53 53 [StorableConstructor] 54 54 protected PackingShape(bool deserializing) : base(deserializing) { } 55 protected PackingShape(PackingShape< D> original, Cloner cloner)55 protected PackingShape(PackingShape<T> original, Cloner cloner) 56 56 : base(original, cloner) { 57 57 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/RectangularPackingShape.cs
r13032 r13497 33 33 public abstract class RectangularPackingShape : PackingShape<TwoDimensionalPacking>, IRegularPackingShape, IComparable<RectangularPackingShape> { 34 34 #region Properties 35 /// <summary>36 /// Describes the size on the Y-axis37 /// </summary>38 35 [Storable] 39 36 public int Height { get; set; } 40 /// <summary> 41 /// Describes the size on the X-axis 42 /// </summary> 37 43 38 [Storable] 44 39 public int Width { get; set; } … … 60 55 private bool Encloses(TwoDimensionalPacking checkedPosition, RectangularPackingShape checkedShape) { 61 56 return Encloses(new RectangleDiagonal(this), new RectangleDiagonal(checkedPosition, checkedShape)); 62 } 57 } 63 58 private bool Encloses(RectangleDiagonal r1, RectangleDiagonal r2) { 64 return (r1.x1 <= r2.x1 &&59 return (r1.x1 <= r2.x1 && 65 60 r1.x2 >= r2.x2 && 66 61 r1.y1 <= r2.y1 && … … 71 66 return Overlaps(myPosition, checkedPosition, (RectangularPackingShape)checkedShape); 72 67 } 73 private bool Overlaps(TwoDimensionalPacking myPosition, TwoDimensionalPacking checkedPosition, RectangularPackingShape checkedShape) { 74 return Overlaps(new RectangleDiagonal (myPosition, this),new RectangleDiagonal(checkedPosition, checkedShape));68 private bool Overlaps(TwoDimensionalPacking myPosition, TwoDimensionalPacking checkedPosition, RectangularPackingShape checkedShape) { 69 return Overlaps(new RectangleDiagonal(myPosition, this), new RectangleDiagonal(checkedPosition, checkedShape)); 75 70 } 76 71 private bool Overlaps(RectangleDiagonal r1, RectangleDiagonal r2) { … … 90 85 #endregion 91 86 92 public RectangularPackingShape(int width, int height) : base () { 87 protected RectangularPackingShape() : base() { } 88 protected RectangularPackingShape(int width, int height) 89 : base() { 93 90 this.Height = height; 94 91 this.Width = width; … … 101 98 this.Height = measures[1]; 102 99 } 103 public override int[] ToArray() { 104 return new int[] { Width, Height }; 105 } 100 106 101 107 102 [StorableConstructor] … … 112 107 this.Height = original.Height; 113 108 } 114 public RectangularPackingShape() : base() {}115 109 116 110 public override string ToString() { … … 124 118 if (result == 0) { 125 119 result = this.Width.CompareTo(other.Width); 126 if (result == 0) 120 if (result == 0) 127 121 result = this.Height.CompareTo(other.Height); 128 122 } … … 131 125 132 126 public int CompareTo(object obj) { 133 if (obj.GetType().Equals(this.GetType()))134 return this.CompareTo((RectangularPackingShape)obj);135 else return 0;127 var other = obj as RectangularPackingShape; 128 if (other != null) return CompareTo(other); 129 else throw new ArgumentException(string.Format("Cannot compare to object {0}", obj), "obj"); 136 130 } 137 131 138 132 #endregion 133 134 public override int[] ToArray() { 135 return new int[] { Width, Height }; 136 } 139 137 140 138 private struct RectangleDiagonal {
Note: See TracChangeset
for help on using the changeset viewer.