Rule-based scene creation

Please have a look at this web workshop

Transformation of the objects in the scene is essentially determined by the following default code for each Object or Group.

var cobj = scene.getObjectByName(pair[0]);
var pobj = scene.getObjectByName(pair[1]);
var s = size(cobj);    //Box3 data
var thisX = s[0][0];
lastX = i>0? lastX +thisX/2 : 0;
cobj.position.x = lastX;
s = size(cobj);    //Box3 data
lastX = s[1][0][1];

var ps = size(pobj);    //Box3 data

var adjY = cobj.type === "Group"? 0 : ps[0][1]/2-s[0][1]/2;
cobj.position.y = -adjY;

var adjZ = -ps[0][2]/2 + s[0][2]/2;
cobj.position.z = adjZ;

Basically it packs Objects and Groups along the X-axis and aligns them to bottommost of Y, and topmost of Z axis. There are sets of optional criteria (margins, rotations etc) before this code both to set up and (next step) to modify transformations.

If members see there is anything fundamentally wrong with this approach and help rectify it, I can avoid multiple questions; e.g. why are some of the objects in the website scene not properly spaced and aligned.