/*
 * This file is part of Mapyrus, software for plotting maps.
 * Copyright (C) 2003, 2004, 2005 Simon Chenery.
 *
 * Mapyrus is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Mapyrus 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Mapyrus; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

/*
 * @(#) $Id$
 */
package org.mapyrus.function;

import org.mapyrus.Argument;
import org.mapyrus.ContextStack;
import org.mapyrus.MapyrusException;

/**
 * Function returning 1 if a rectangular area on page is protected.
 * This is most useful for determining if displaying a label or symbol
 * will overwrite an existing label or symbol.
 * For example, protected(12.1, 13.7, 13.33, 14.1) = 1.
 */
public class Protected extends Function
{
	/**
	 * @see org.mapyrus.function.Function#evaluate(org.mapyrus.ContextStack, org.mapyrus.Argument, org.mapyrus.Argument,
	 * org.mapyrus.ContextStack, org.mapyrus.ContextStack)
	 */
	public Argument evaluate(ContextStack context, Argument arg1, Argument arg2,
		Argument arg3, Argument arg4) throws MapyrusException
	{
		Argument retval;
		double x1 = arg1.getNumericValue();
		double y1 = arg2.getNumericValue();
		double x2 = arg3.getNumericValue();
		double y2 = arg4.getNumericValue();

		double xMin = Math.min(x1, x2);
		double yMin = Math.min(y1, y2);
		double xMax = Math.max(x1, x2);
		double yMax = Math.max(y1, y2);

		if (context.isProtected(xMin, yMin, xMax, yMax))
			retval = Argument.numericOne;
		else
			retval = Argument.numericZero; 
		return(retval);
	}

	/**
	 * @see org.mapyrus.function.Function#getMaxArgumentCount()
	 */
	public int getMaxArgumentCount()
	{
		return(4);
	}

	/**
	 * @see org.mapyrus.function.Function#getMinArgumentCount()
	 */
	public int getMinArgumentCount()
	{
		return(4);
	}

	/**
	 * @see org.mapyrus.function.Function#getName()
	 */
	public String getName()
	{
		return("protected");
	}
}

@@ -882,16 +882,51 @@
 ction;%0A%0A
+import java.awt.geom.Rectangle2D;%0A%0A
 import o
@@ -946,16 +946,16 @@
 gument;%0A
-
 import o
@@ -1015,16 +1015,52 @@
 ception;
+%0Aimport org.mapyrus.MapyrusMessages;
 %0A%0A/**%0A *
@@ -2119,24 +2119,1199 @@
 etval);%0A%09%7D%0A%0A
+%09/**%0A%09 * @see org.mapyrus.function.Function#evaluate(org.mapyrus.ContextStack, org.mapyrus.Argument)%0A%09 */%0A%09public Argument evaluate(ContextStack context, Argument arg1)%0A%09%09throws MapyrusException%0A%09%7B%0A%09%09Argument retval = Argument.numericZero;%0A%09%09Rectangle2D.Double rect = arg1.getGeometryBoundingBox();%0A%09%09if (rect != null && context.isProtected(rect.getMinX(), rect.getMinY(),%0A%09%09%09rect.getMaxX(), rect.getMaxY()))%0A%09%09%7B%0A%09%09%09retval = Argument.numericOne;%0A%09%09%7D%0A%09%09return(retval);%0A%09%7D%0A%0A%09/**%0A%09 * @see org.mapyrus.function.Function#evaluate(org.mapyrus.ContextStack,%0A%09 * org.mapyrus.Argument, org.mapyrus.Argument)%0A%09 */%0A%09public Argument evaluate(ContextStack context, Argument arg1, Argument arg2)%0A%09%09throws MapyrusException%0A%09%7B%0A%09%09throw new MapyrusException(MapyrusMessages.get(MapyrusMessages.WRONG_FUNCTION_VALUES));%0A%09%7D%0A%0A%09/**%0A%09 * @see org.mapyrus.function.Function#evaluate(org.mapyrus.ContextStack,%0A%09 * org.mapyrus.Argument, org.mapyrus.Argument, org.mapyrus.Argument)%0A%09 */%0A%09public Argument evaluate(ContextStack context, Argument arg1, Argument arg2,%0A%09%09Argument arg3) throws MapyrusException%0A%09%7B%0A%09%09throw new MapyrusException(MapyrusMessages.get(MapyrusMessages.WRONG_FUNCTION_VALUES));%0A%09%7D%0A%0A
 %09/**%0A%09 * @se
@@ -3532,33 +3532,33 @@
 t()%0A%09%7B%0A%09%09return(
-4
+1
 );%0A%09%7D%0A%0A%09/**%0A%09 * 

Allow single geometry argument as well as x1, y1, x2, y2.