#
# NEED_PARMS maxx maxy zfactor
#
# HELP: SYNOPSIS:
# HELP:     threeplane/views_autosize_internal maxx maxy zfactor
# HELP:
# HELP: DESCRIPTION:
# HELP:     Set the size/zoom for all three planes by making a best fit
# HELP:     for a maxx by maxy screen.
#
DECLARE struct $root.macros
DECLARE struct $root.macros.threeplane
DECLARE struct $root.macros.threeplane.autosize
DECLARE double $root.macros.threeplane.autosize.zoomfactor
DECLARE double $zoomfactor
DECLARE double $zfactor
DECLARE double $sumx
DECLARE double $sumy
DECLARE double $maxx
DECLARE double $maxy

CECHO ${$maxx=(double)$argv[1]}
CECHO ${$maxy=(double)$argv[2]}
CECHO ${$zfactor=(double)$argv[3]}

CECHO ${$sumx=$root.vol[current].size.x+$root.vol[current].size.y}
CECHO ${$sumy=$root.vol[current].size.y+$root.vol[current].size.z*$zfactor}
CECHO ${$zoomfactor=$maxx/$sumx}
{ IF1 ${$zoomfactor>$maxy/$sumy}
	CECHO ${$zoomfactor=$maxy/$sumy}
} IF1 0 0

{ IF2 ${$zoomfactor>=1.0}
	CECHO ${$zoomfactor=(int)$zoomfactor}
} IF2 0 0

{ IF3 ${$zoomfactor<1.0}
	CECHO ${$zoomfactor=(int)(1.0/$zoomfactor+0.999999)}
	CECHO ${$zoomfactor=1.0/$zoomfactor}
} IF3 0 0

! threeplane/views_size ${$zoomfactor}
! threeplane/views_zoom ${$zoomfactor}
! threeplane/stretchz ${$zfactor} ${$zoomfactor}
CECHO ${$root.macros.threeplane.autosize.zoomfactor=$zoomfactor}
