Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2817:

  • Changed the calculation algorithm for creating extreme points by using line based projection
  • Changed the calculation of the residual spaces for line based projection
File size: 3.3 KB
RevLine 
[15454]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace HeuristicLab.Problems.BinPacking3D.Geometry {
[15488]8  public class Vector3D {
[15454]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    }
[15488]25
26    public PackingPosition ToPackingPosition(int assignedBin) {
27      return new PackingPosition(assignedBin, X, Y, Z);
28    }
29
[15454]30    public static Vector3D AlongX(Vector3D pos, PackingItem item) {
31      return new Vector3D(
32        pos.X + item.Width,
33        pos.Y,
34        pos.Z
35      );
36    }
37    public static Vector3D AlongY(Vector3D pos, PackingItem item) {
38      return new Vector3D(
39        pos.X,
40        pos.Y + item.Height,
41        pos.Z
42      );
43    }
44    public static Vector3D AlongZ(Vector3D pos, PackingItem item) {
45      return new Vector3D(
46        pos.X,
47        pos.Y,
48        pos.Z + item.Depth
49      );
50    }
51    public static Vector3D AlongX(PackingPosition pos, PackingItem item) {
52      return new Vector3D(
53        pos.X + item.Width,
54        pos.Y,
55        pos.Z
56      );
57    }
58    public static Vector3D AlongY(PackingPosition pos, PackingItem item) {
59      return new Vector3D(
60        pos.X,
61        pos.Y + item.Height,
62        pos.Z
63      );
64    }
65    public static Vector3D AlongZ(PackingPosition pos, PackingItem item) {
66      return new Vector3D(
67        pos.X,
68        pos.Y,
69        pos.Z + item.Depth
70      );
71    }
72
73    public Vector3D Cross(Vector3D b) {
74      return new Vector3D(
75        Y * b.Z - Z * b.Y,
76        -X * b.Z + Z * b.X,
77        X * b.Y - Y * b.X
78      );
79    }
80
[15520]81    public bool IsInside(PackingPosition pos, ResidualSpace rs) {
82      return X >= pos.X && X < pos.X + rs.Width
83        && Y >= pos.Y && Y < pos.Y + rs.Height
84        && Z >= pos.Z && Z < pos.Z + rs.Depth;
[15454]85    }
86
87    public static int operator *(Vector3D a, Vector3D b) {
88      return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
89    }
90    public static Vector3D operator *(int a, Vector3D b) {
91      return new Vector3D(a * b.X, a * b.Y, a * b.Z);
92    }
[15488]93
94    public static Vector3D operator *(double a, Vector3D b) {
95      return new Vector3D((int)(a * b.X), (int)(a * b.Y), (int)(a * b.Z));
96    }
97
[15454]98    public static Vector3D operator *(Vector3D a, int b) {
99      return new Vector3D(a.X * b, a.Y * b, a.Z * b);
100    }
[15488]101
102    public static Vector3D operator *(Vector3D a, double b) {
103      return new Vector3D((int)(b * a.X), (int)(b * a.Y), (int)(b * a.Z));
104    }
105
[15454]106    public static Vector3D operator +(Vector3D a, Vector3D b) {
107      return new Vector3D(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
108    }
109    public static Vector3D operator -(Vector3D a, Vector3D b) {
110      return new Vector3D(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
111    }
112
113    public override bool Equals(object obj) {
114      var packPos = obj as PackingPosition;
115      if (packPos != null) {
116        return X == packPos.X && Y == packPos.Y && Z == packPos.Z;
117      }
118      var vec = obj as Vector3D;
119      if (vec != null) {
120        return X == vec.X && Y == vec.Y && Z == vec.Z;
121      }
122      return false;
123    }
124  }
125}
Note: See TracBrowser for help on using the repository browser.