packer-3d 0.3.0

Packing algorithm for 3D container packing which optimizes for width, height, length, or all three.
Documentation
  • Coverage
  • 46.94%
    23 out of 49 items documented4 out of 39 items with examples
  • Size
  • Source code size: 777.54 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.9 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • R-Besson/n-dimensional-strip-packing
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • R-Besson

packer-3d

Example of what you can make. Rendered using the Bevy data-driven game engine.

Quickstart

Run this in your rust project to add packer-3d to your dependencies.

cargo add packer-3d

Documentation

Example

After adding the dependency, you can test it with this example:

use packer_3d::{box3d::Box3D, sorting::Sorting, vector3d::Vector3D, PackerInstance};

fn main() {
	let my_boxes = vec![
		Box3D::from_xyz_whl(0, 0, 0, 100, 200, 300, 1, 0),
		Box3D::from_xyz_whl(0, 0, 0, 100, 200, 300, 2, 0),
		Box3D::from_xyz_whl(0, 0, 0, 100, 200, 300, 3, 0),
	];

	let mut my_instance = PackerInstance::new(
		my_boxes.clone(),            // Our boxes
		Vector3D::new(500, 0, 500),  // Our container size
		true,                        // No rotations
		(false, true, false),        // Minimize height only
		Sorting::descending_volume,  // Our initial sorting heuristic
	);

	// for _ in 0..3 {
	//     match my_instance.pack_next() {
	//         Err(error) => println!("Error: {}", error),
	//         Ok(()) => {}
	//     }
	// }

	match my_instance.pack_all() {
		Err(errors) => println!("Errors: {:#?}", errors),
		Ok(()) => {}
	}

	println!("{:#?}", my_instance.boxes());
}

Which should output:

[
	Box3D {
		position: Vector3D {
			x: 0,
			y: 0,
			z: 0,
		},
		size: Vector3D {
			x: 300,
			y: 100,
			z: 200,
		},
		id: 1,
		origin: 0,
	},
	Box3D {
		position: Vector3D {
			x: 300,
			y: 0,
			z: 0,
		},
		size: Vector3D {
			x: 200,
			y: 100,
			z: 300,
		},
		id: 2,
		origin: 0,
	},
	Box3D {
		position: Vector3D {
			x: 0,
			y: 0,
			z: 200,
		},
		size: Vector3D {
			x: 300,
			y: 100,
			z: 200,
		},
		id: 3,
		origin: 0,
	},
]