yetzt / boxing Goto Github PK
View Code? Open in Web Editor NEWquick and dirty php implementation for a box packing problem
quick and dirty php implementation for a box packing problem
Good day to you.
I would like to use this code in my project.
Sorry for making it an issue - I failed to find a private message or email of yours.
Please tell if I can use it or what is needed to acquire a license from you to use this code.
Thank you very much.
Ilia Lev
I tried playing around with the class and noticed an error when the boxes should fit:
Notice: Undefined index: longest_side
private function _sksort($array, $subkey, $sort_descending=false, $keep_keys_in_sub=false) {
foreach ($array as $key => &$value) {
$sort = array();
foreach ($value as $index => $val) {
$sort[$index] = $val[$subkey]; // << This is the line producing the error
}
If the inner boxes do not fit everything works fine, however (function "fits()" returns "false")
Hey im trying to understand the logic and how to use this properly.
Here is the code i used for testing:
$boxing = new Boxing();
$boxing->add_outer_box(100, 100, 100);
$boxing->add_inner_box(50, 50, 50); //1/4
$boxing->add_inner_box(50, 50, 50); //1/4
if ($boxing->fits())
{
var_dump($boxing);
}
It returns a array of outer_boxes of length 6, which confuses me.
The first 2 item in the outer_boxes array are set has "Packed" true.
Can I get a return that say of item 1,2,3 goes in box 1 and item 4,5,6 goes in box 2 for example.
From: http://www.php.net/manual/en/language.types.array.php
. Floats in key are truncated to integer.
This causes problems when using floats as measurements when using this class.
I've created a patch to resolve this. It seems to work for me.
// fits exactly example
$b = new Boxing();
$b->add_outer_box(100,100,100);
$b->add_inner_box(50,50,50);
$b->add_inner_box(50,50,50);
$b->fits(); //it returns true...OK, fine..packed with 2 boxes!
// NOT fits example
$b = new Boxing();
$b->add_outer_box(100,100,100);
$b->add_inner_box(50,50,50);
$b->add_inner_box(50,50,50);
$b->add_inner_box(50,50,50);
$b->fits(); // it returns true. this should return to false.
Why return true?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.