function [P_MIN, P_MAX, SIZ] = geom_bounds_and_size (GOBJ)
%
% [P_MIN, P_MAX, SIZ] = geom_bounds_and_size (GOBJ)
% Calculates the bounds and extent of input geomtry object, GOBJ, and
% returns:
%
% 1) Points P_MIN & P_MAX, the coordinates of diagonally oposite vertexes
% of a rectangular block which wholly contains all objects in GOBJ and
%
% 2) SIZ, the x, y, and z, lengths of the box bounded by P_MIN & P_MAX.
% Method:
% The components of P_MIN are the minimum of all objects' bbox (1:) and
% the components of P_MAX are the maximum of all objects' bbox (2:).
% The measure of each "dimension" of the block (xLength, yLength, zLength)
% is the difference between the x, y, and z components of P_MAX and P_MIN
% and is returned in array SIZ.
% Initialize P_MIN and P_MAX to max/min flag values so first objects
% encountered will be assigned to each.
P_MIN = [ realmax realmax realmax];
P_MAX = [ realmin realmin realmin];
% for convienence and readability, assign min and max row (array index)
% to self documenting variable names.
bbox_min_row = 1;
bbox_max_row = 2;
% loop over each objects{} entry and gather/accumulate in P_MIN and P_MAX
% the min/max values that define the bounding box (bbox) for each object
% in the geometry struct making use of the 'min' 'max' ability to compare
% x, y, and z enries at the same time.
for i=1:1:length (GOBJ.objects)
P_MIN = min (P_MIN, GOBJ.objects{i}.bbox(bbox_min_row,:));
P_MAX = max (P_MAX, GOBJ.objects{i}.bbox(bbox_max_row,:));
end
% Once the P_MIN and P_MAX have been calculated their difference is the
% x, y, and z extents or dimensions of the box with P_MIN and P_MAX at
% diagonaly opposite corners.
SIZ = P_MAX - P_MIN;
end