Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Geometry/Vector3D.cs @ 15454

Last change on this file since 15454 was 15454, checked in by rhanghof, 6 years ago

#2817

  • Extreme point bin packing does not need the occupation layer anymore
  • Changes at the fitting algorithm. Now they are packing the items as in the paper of S. Martello, D. Pisinger, D. Vigo described
File size: 2.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace HeuristicLab.Problems.BinPacking3D.Geometry {
8  internal class Vector3D {
9
10    public int X { get; set; }
11    public int Y { get; set; }
12    public int Z { get; set; }
13
14    public Vector3D() { }
15    public Vector3D(int x, int y, int z) {
16      X = x;
17      Y = y;
18      Z = z;
19    }
20    public Vector3D(PackingPosition pos) {
21      X = pos.X;
22      Y = pos.Y;
23      Z = pos.Z;
24    }
25    public static Vector3D AlongX(Vector3D pos, PackingItem item) {
26      return new Vector3D(
27        pos.X + item.Width,
28        pos.Y,
29        pos.Z
30      );
31    }
32    public static Vector3D AlongY(Vector3D pos, PackingItem item) {
33      return new Vector3D(
34        pos.X,
35        pos.Y + item.Height,
36        pos.Z
37      );
38    }
39    public static Vector3D AlongZ(Vector3D pos, PackingItem item) {
40      return new Vector3D(
41        pos.X,
42        pos.Y,
43        pos.Z + item.Depth
44      );
45    }
46    public static Vector3D AlongX(PackingPosition pos, PackingItem item) {
47      return new Vector3D(
48        pos.X + item.Width,
49        pos.Y,
50        pos.Z
51      );
52    }
53    public static Vector3D AlongY(PackingPosition pos, PackingItem item) {
54      return new Vector3D(
55        pos.X,
56        pos.Y + item.Height,
57        pos.Z
58      );
59    }
60    public static Vector3D AlongZ(PackingPosition pos, PackingItem item) {
61      return new Vector3D(
62        pos.X,
63        pos.Y,
64        pos.Z + item.Depth
65      );
66    }
67
68    public Vector3D Cross(Vector3D b) {
69      return new Vector3D(
70        Y * b.Z - Z * b.Y,
71        -X * b.Z + Z * b.X,
72        X * b.Y - Y * b.X
73      );
74    }
75
76    public bool IsInside(PackingPosition pos, Tuple<int, int, int> rs) {
77      return X >= pos.X && X < pos.X + rs.Item1
78        && Y >= pos.Y && Y < pos.Y + rs.Item2
79        && Z >= pos.Z && Z < pos.Z + rs.Item3;
80    }
81
82    public static int operator *(Vector3D a, Vector3D b) {
83      return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
84    }
85    public static Vector3D operator *(int a, Vector3D b) {
86      return new Vector3D(a * b.X, a * b.Y, a * b.Z);
87    }
88    public static Vector3D operator *(Vector3D a, int b) {
89      return new Vector3D(a.X * b, a.Y * b, a.Z * b);
90    }
91    public static Vector3D operator +(Vector3D a, Vector3D b) {
92      return new Vector3D(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
93    }
94    public static Vector3D operator -(Vector3D a, Vector3D b) {
95      return new Vector3D(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
96    }
97
98    public override bool Equals(object obj) {
99      var packPos = obj as PackingPosition;
100      if (packPos != null) {
101        return X == packPos.X && Y == packPos.Y && Z == packPos.Z;
102      }
103      var vec = obj as Vector3D;
104      if (vec != null) {
105        return X == vec.X && Y == vec.Y && Z == vec.Z;
106      }
107      return false;
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.