//-----------------------------------------------------------------------------
// Copyright © 2006 - Philip Howard - All rights reserved
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/arith
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	libh at ipal dot org
// homepage	http://phil.ipal.org/
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 120 columns wide.
//-----------------------------------------------------------------------------

#include "arith_lib.h"

__FMACRO_BEGIN__
//-----------------------------------------------------------------------------
// macro	zoom_calc
//
// purpose	Given a set of multiply/add values from a zoom scan, and a set
//		of 2D view coordinates, transform the coordinates into the new
//		zoomed in view.
//
// arguments	1 (lvalue) edge position on X axis on left
//		2 (lvalue) edge position on Y axis on top
//		3 (lvalue) edge position on X axis on right
//		4 (lvalue) edge position on Y axis on bottom
//		5 (value) already scanned X axis multiplier
//		6 (value) already scanned Y axis multiplier
//		7 (value) already scanned X axis adder
//		8 (value) already scanned Y axis adder
//
// returns	(int) == -1 : failure
//		(int) >=  0 : success
//-----------------------------------------------------------------------------
#define zoom_calc(xl,yt,xr,yb,xm,ym,xa,ya) ({					\
	{									\
		typeof(xr) libh__d;						\
		typeof(xr) libh__m;						\
		libh__d = ((xr)-(xl))*(xm)/2.0;					\
		libh__m = ((xr)+(xl))/2.0+(xa);					\
		(xl) = libh__m - libh__d;					\
		(xr) = libh__m + libh__d;					\
	}									\
	{									\
		typeof(yt) libh__d;						\
		typeof(yt) libh__m;						\
		libh__d = ((yt)-(yb))*(ym)/2.0;					\
		libh__m = ((yt)+(yb))/2.0+(ya);					\
		(yb) = libh__m - libh__d;					\
		(yt) = libh__m + libh__d;					\
	}									\
	0;									\
})

__FMACRO_END__

