[15617] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[15454] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using System.Threading.Tasks;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Problems.BinPacking3D.Geometry {
|
---|
[15488] | 29 | public class Vector3D {
|
---|
[15454] | 30 |
|
---|
| 31 | public int X { get; set; }
|
---|
| 32 | public int Y { get; set; }
|
---|
| 33 | public int Z { get; set; }
|
---|
| 34 |
|
---|
[15554] | 35 | public Vector3D() {
|
---|
| 36 | X = 0;
|
---|
| 37 | Y = 0;
|
---|
| 38 | Z = 0;
|
---|
| 39 | }
|
---|
[15454] | 40 | public Vector3D(int x, int y, int z) {
|
---|
| 41 | X = x;
|
---|
| 42 | Y = y;
|
---|
| 43 | Z = z;
|
---|
| 44 | }
|
---|
| 45 | public Vector3D(PackingPosition pos) {
|
---|
| 46 | X = pos.X;
|
---|
| 47 | Y = pos.Y;
|
---|
| 48 | Z = pos.Z;
|
---|
| 49 | }
|
---|
[15488] | 50 |
|
---|
| 51 | public PackingPosition ToPackingPosition(int assignedBin) {
|
---|
| 52 | return new PackingPosition(assignedBin, X, Y, Z);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[15454] | 55 | public static Vector3D AlongX(Vector3D pos, PackingItem item) {
|
---|
| 56 | return new Vector3D(
|
---|
| 57 | pos.X + item.Width,
|
---|
| 58 | pos.Y,
|
---|
| 59 | pos.Z
|
---|
| 60 | );
|
---|
| 61 | }
|
---|
| 62 | public static Vector3D AlongY(Vector3D pos, PackingItem item) {
|
---|
| 63 | return new Vector3D(
|
---|
| 64 | pos.X,
|
---|
| 65 | pos.Y + item.Height,
|
---|
| 66 | pos.Z
|
---|
| 67 | );
|
---|
| 68 | }
|
---|
| 69 | public static Vector3D AlongZ(Vector3D pos, PackingItem item) {
|
---|
| 70 | return new Vector3D(
|
---|
| 71 | pos.X,
|
---|
| 72 | pos.Y,
|
---|
| 73 | pos.Z + item.Depth
|
---|
| 74 | );
|
---|
| 75 | }
|
---|
| 76 | public static Vector3D AlongX(PackingPosition pos, PackingItem item) {
|
---|
| 77 | return new Vector3D(
|
---|
| 78 | pos.X + item.Width,
|
---|
| 79 | pos.Y,
|
---|
| 80 | pos.Z
|
---|
| 81 | );
|
---|
| 82 | }
|
---|
| 83 | public static Vector3D AlongY(PackingPosition pos, PackingItem item) {
|
---|
| 84 | return new Vector3D(
|
---|
| 85 | pos.X,
|
---|
| 86 | pos.Y + item.Height,
|
---|
| 87 | pos.Z
|
---|
| 88 | );
|
---|
| 89 | }
|
---|
| 90 | public static Vector3D AlongZ(PackingPosition pos, PackingItem item) {
|
---|
| 91 | return new Vector3D(
|
---|
| 92 | pos.X,
|
---|
| 93 | pos.Y,
|
---|
| 94 | pos.Z + item.Depth
|
---|
| 95 | );
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | public Vector3D Cross(Vector3D b) {
|
---|
| 99 | return new Vector3D(
|
---|
| 100 | Y * b.Z - Z * b.Y,
|
---|
| 101 | -X * b.Z + Z * b.X,
|
---|
| 102 | X * b.Y - Y * b.X
|
---|
| 103 | );
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[15520] | 106 | public bool IsInside(PackingPosition pos, ResidualSpace rs) {
|
---|
| 107 | return X >= pos.X && X < pos.X + rs.Width
|
---|
| 108 | && Y >= pos.Y && Y < pos.Y + rs.Height
|
---|
| 109 | && Z >= pos.Z && Z < pos.Z + rs.Depth;
|
---|
[15454] | 110 | }
|
---|
| 111 |
|
---|
[15554] | 112 | public bool IsInside(PackingPosition pos, IEnumerable<ResidualSpace> rs) {
|
---|
| 113 | return rs.Any(x => IsInside(pos, x));
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[15454] | 116 | public static int operator *(Vector3D a, Vector3D b) {
|
---|
| 117 | return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
|
---|
| 118 | }
|
---|
| 119 | public static Vector3D operator *(int a, Vector3D b) {
|
---|
| 120 | return new Vector3D(a * b.X, a * b.Y, a * b.Z);
|
---|
| 121 | }
|
---|
[15488] | 122 |
|
---|
| 123 | public static Vector3D operator *(double a, Vector3D b) {
|
---|
| 124 | return new Vector3D((int)(a * b.X), (int)(a * b.Y), (int)(a * b.Z));
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[15454] | 127 | public static Vector3D operator *(Vector3D a, int b) {
|
---|
| 128 | return new Vector3D(a.X * b, a.Y * b, a.Z * b);
|
---|
| 129 | }
|
---|
[15488] | 130 |
|
---|
| 131 | public static Vector3D operator *(Vector3D a, double b) {
|
---|
| 132 | return new Vector3D((int)(b * a.X), (int)(b * a.Y), (int)(b * a.Z));
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[15454] | 135 | public static Vector3D operator +(Vector3D a, Vector3D b) {
|
---|
| 136 | return new Vector3D(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
|
---|
| 137 | }
|
---|
| 138 | public static Vector3D operator -(Vector3D a, Vector3D b) {
|
---|
| 139 | return new Vector3D(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | public override bool Equals(object obj) {
|
---|
| 143 | var packPos = obj as PackingPosition;
|
---|
| 144 | if (packPos != null) {
|
---|
| 145 | return X == packPos.X && Y == packPos.Y && Z == packPos.Z;
|
---|
| 146 | }
|
---|
| 147 | var vec = obj as Vector3D;
|
---|
| 148 | if (vec != null) {
|
---|
| 149 | return X == vec.X && Y == vec.Y && Z == vec.Z;
|
---|
| 150 | }
|
---|
| 151 | return false;
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 | }
|
---|