snapping code: from separate checks to 1 formula
1) Do not hard-code the distance that will define 'near', but rather make it a variable/parameter.
2) Split the solution : 1) do we 'approximatively' overlap ? and 2) are we on the left or right, and are we up or down ?
3) Use as much 'standard' code as you can : here 'update' will define a BBox based on a list of points, 'expand' and 'overlaps' will do what-you-guess.

var nearDistance = 5;
var newBox new BoundingBox();
var boxSize = null;

for (var i = 0; i &lt; elements.length; i++) {
            var thisElement = elements[i];

            // newBox is now the BBox of thisElement
            newBox.update(thisElement);

            // do we approximatively overlap ?
            newBox.expand(nearDistance);    
            var overlaps = newBox.overlaps(box);    
            if (!overlaps) continue;

            // are we on the left/right, up/down ??

            newBox.expand(-nearDistance);
            boxSize = box.size() ;  

            var newXPosition = -1, newZPosition = -1;

            if ( newBox.min.x - box.max.x &gt; -boxSize.x / 2) {    
                // left
                newXPosition = newBox.min.x - ((box.max.x - box.min.x) / 2) - 0.5;
            } else {
                // right
               newXPosition = newBox.max.x + ((box.max.x - box.min.x) / 2) + 0.6;
            }

            if (newBox.min.z - box.max.z &gt; -boxSize.z / 2 ) {    
                // up
                newZPosition = newBox.min.z - ((box.max.z - box.min.z) / 2) - 0.5;    
            } else {
                // down
                newZPosition= newBox.max.x + ((box.max.x - box.min.x) / 2) + 0.6;
            }                        

            //adjust position
            activeElement.position.x = newXPosition ;
            activeElement.position.z = newZPosition;

            box.update(activeElement);

            activeElement.snapped.push( /* thisElement was snapped */);
            debug.snapped = true;
            }    
}