Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/PackingPlanVisualizations/3D/CenteredContainer.cs @ 13497

Last change on this file since 13497 was 13497, checked in by gkronber, 8 years ago

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

File size: 2.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Joseph Helm and 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
22using System;
23using System.Collections.Generic;
24using SharpDX;
25
26namespace PackingPlanVisualizations {
27
28  public class CenteredContainer {
29    public BasicCuboidShape Container { get; private set; }
30    public List<BasicCuboidShape> PackingItems { get; private set; }
31
32    private readonly float normalizingFactor;
33
34    public CenteredContainer(BasicCuboidShape container) {
35      normalizingFactor = CalculateNormalizingFactor(container);
36      Container = Normalize(container);
37      PackingItems = new List<BasicCuboidShape>();
38    }
39
40    private float CalculateNormalizingFactor(BasicCuboidShape shape) {
41      float longestEdge = Math.Max(Math.Max(shape.ShapeSize.X, shape.ShapeSize.Y), shape.ShapeSize.Z);
42      return 1 / (longestEdge / 30);
43    }
44    private BasicCuboidShape Normalize(BasicCuboidShape shape) {
45      return new BasicCuboidShape(shape.ShapeSize * normalizingFactor, shape.ShapePosition * normalizingFactor, shape.ShapeID, shape.Material);
46    }
47
48    public void AddPackingItem(Vector3 size, Vector3 position, int index, int material) {
49      var itemSize = size * normalizingFactor;
50      var itemPosition = position * normalizingFactor;
51      var actualPosition = Container.CalculatePositionRelativeToBottomLeftBackCorner(itemSize, itemPosition);
52      var itemShape = new BasicCuboidShape(itemSize, actualPosition, index, material);
53      PackingItems.Add(itemShape);
54    }
55  }
56}
Note: See TracBrowser for help on using the repository browser.