https://github.com/simulation-tree/bin-packer
Packing squares into bigger squares
https://github.com/simulation-tree/bin-packer
bin-packing csharp dotnet
Last synced: 5 months ago
JSON representation
Packing squares into bigger squares
- Host: GitHub
- URL: https://github.com/simulation-tree/bin-packer
- Owner: simulation-tree
- Created: 2024-07-26T07:29:09.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-09-24T03:03:17.000Z (9 months ago)
- Last Synced: 2025-09-24T05:21:19.692Z (9 months ago)
- Topics: bin-packing, csharp, dotnet
- Language: C#
- Homepage:
- Size: 48.8 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bin Packing
Provides a bin packing solving algorithm through the [rectpack2D](https://github.com/simulation-tree/rectpack2D) project.
### Using
There two main methods to the packer, one requires you to know the size ahead of time,
the other finds it for you:
```cs
RecursivePacker packer = new();
Span sizes = stackalloc Vector2[5];
sizes[0] = new Vector2(32, 32);
sizes[1] = new Vector2(32, 32);
sizes[2] = new Vector2(32, 32);
sizes[3] = new Vector2(32, 16);
sizes[4] = new Vector2(32, 16);
Span positions = stackalloc Vector2[5];
//if you know the max size ahead of time:
if (packer.TryPack(sizes, positions, new Vector2(64, 64), padding))
{
//success
}
else
{
Assert.Fail("Failed to pack the boxes into the given size");
}
//let the packer find the smallest size:
Vector2 maxSize = packer.Pack(sizes, positions, padding);
Assert.That(maxSize, Is.EqualTo(new Vector2(64, 64)));
```