Ignore:
Timestamp:
01/12/16 10:42:58 (5 years ago)
Author:
gkronber
Message:

#1966: fixed various problems: bugs in cloning, bugs in persistence, method names, various minor improvements of source code for readability.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/RectangularPackingShape.cs

    r13032 r13497  
    3333  public abstract class RectangularPackingShape : PackingShape<TwoDimensionalPacking>, IRegularPackingShape, IComparable<RectangularPackingShape> {
    3434    #region Properties
    35     /// <summary>
    36     /// Describes the size on the Y-axis
    37     /// </summary>
    3835    [Storable]
    3936    public int Height { get; set; }
    40     /// <summary>
    41     /// Describes the size on the X-axis
    42     /// </summary> 
     37
    4338    [Storable]
    4439    public int Width { get; set; }
     
    6055    private bool Encloses(TwoDimensionalPacking checkedPosition, RectangularPackingShape checkedShape) {
    6156      return Encloses(new RectangleDiagonal(this), new RectangleDiagonal(checkedPosition, checkedShape));
    62     }       
     57    }
    6358    private bool Encloses(RectangleDiagonal r1, RectangleDiagonal r2) {
    64       return  ( r1.x1 <= r2.x1 &&
     59      return (r1.x1 <= r2.x1 &&
    6560                r1.x2 >= r2.x2 &&
    6661                r1.y1 <= r2.y1 &&
     
    7166      return Overlaps(myPosition, checkedPosition, (RectangularPackingShape)checkedShape);
    7267    }
    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));
    7570    }
    7671    private bool Overlaps(RectangleDiagonal r1, RectangleDiagonal r2) {
     
    9085    #endregion
    9186
    92     public RectangularPackingShape(int width, int height) : base () {
     87    protected RectangularPackingShape() : base() { }
     88    protected RectangularPackingShape(int width, int height)
     89      : base() {
    9390      this.Height = height;
    9491      this.Width = width;
     
    10198      this.Height = measures[1];
    10299    }
    103     public override int[] ToArray() {
    104       return new int[] { Width, Height };
    105     }
     100
    106101
    107102    [StorableConstructor]
     
    112107      this.Height = original.Height;
    113108    }
    114     public RectangularPackingShape() : base() {}
    115109
    116110    public override string ToString() {
     
    124118      if (result == 0) {
    125119        result = this.Width.CompareTo(other.Width);
    126         if (result == 0) 
     120        if (result == 0)
    127121          result = this.Height.CompareTo(other.Height);
    128122      }
     
    131125
    132126    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");
    136130    }
    137131
    138132    #endregion
     133
     134    public override int[] ToArray() {
     135      return new int[] { Width, Height };
     136    }
    139137
    140138    private struct RectangleDiagonal {
Note: See TracChangeset for help on using the changeset viewer.