Add project files.
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace BoxPacker3D
|
||||
{
|
||||
public class Box
|
||||
{
|
||||
public double W { get; set; }
|
||||
public double H { get; set; }
|
||||
public double D { get; set; }
|
||||
/// <summary>Thickness of the cardboard/material wall in the same units (mm).</summary>
|
||||
public double WallThickness { get; set; }
|
||||
|
||||
public Box(double w, double h, double d, double wallThickness = 0)
|
||||
{
|
||||
W = w; H = h; D = d; WallThickness = wallThickness;
|
||||
}
|
||||
|
||||
/// <summary>Outer volume.</summary>
|
||||
public double Volume => W * H * D;
|
||||
/// <summary>Usable interior volume (after subtracting wall thickness on all 6 sides).</summary>
|
||||
public double InnerVolume
|
||||
{
|
||||
get
|
||||
{
|
||||
double iw = Math.Max(0, W - 2 * WallThickness);
|
||||
double ih = Math.Max(0, H - 2 * WallThickness);
|
||||
double id = Math.Max(0, D - 2 * WallThickness);
|
||||
return iw * ih * id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Item
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public double W { get; set; }
|
||||
public double H { get; set; }
|
||||
public double D { get; set; }
|
||||
public Color Color { get; set; }
|
||||
|
||||
public Item(string name, double w, double h, double d, Color color)
|
||||
{
|
||||
Name = name; W = w; H = h; D = d; Color = color;
|
||||
}
|
||||
|
||||
public double Volume => W * H * D;
|
||||
|
||||
public bool FitsInBox(Box box)
|
||||
{
|
||||
// Check allowed rotations (horizontal only - height preserved)
|
||||
double[] dims = { W, H, D };
|
||||
var rotations = GetRotations();
|
||||
foreach (var r in rotations)
|
||||
if (r[0] <= box.W && r[1] <= box.H && r[2] <= box.D)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public double[][] GetRotations(bool preferRotated = false)
|
||||
{
|
||||
var orig = new[] { W, H, D };
|
||||
var rot = new[] { D, H, W };
|
||||
return preferRotated
|
||||
? new double[][] { rot, orig }
|
||||
: new double[][] { orig, rot };
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemType
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public double W { get; set; }
|
||||
public double H { get; set; }
|
||||
public double D { get; set; }
|
||||
public int Count { get; set; }
|
||||
public Color Color { get; set; }
|
||||
}
|
||||
|
||||
public class PackedItem
|
||||
{
|
||||
public Item Item { get; set; }
|
||||
public double X { get; set; }
|
||||
public double Y { get; set; }
|
||||
public double Z { get; set; }
|
||||
// Actual dimensions used (after rotation)
|
||||
public double RW { get; set; }
|
||||
public double RH { get; set; }
|
||||
public double RD { get; set; }
|
||||
|
||||
public PackedItem(Item item, double x, double y, double z, double rw, double rh, double rd)
|
||||
{
|
||||
Item = item; X = x; Y = y; Z = z; RW = rw; RH = rh; RD = rd;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user