/*
 *    Geotools2 - OpenSource mapping toolkit
 *    http://geotools.org
 *    (C) 2002, Geotools Project Managment Committee (PMC)
 *
 *    This library 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;
 *    version 2.1 of the License.
 *
 *    This library 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.
 *
 */
package org.geotools.renderer.shape;

import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

import com.vividsolutions.jts.geom.Envelope;

/**
 * An abstract java awt shape that will allow a SimpleGeometry to be drawn using Graphics2D 
 * 
 * @author jeichar
 * @since 2.1.x
 * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/shapefile-renderer/src/main/java/org/geotools/renderer/shape/AbstractShape.java $
 */
public abstract class AbstractShape implements Shape {

	protected SimpleGeometry geom;
	
	/**
	 * @param geom
	 */
	public AbstractShape(SimpleGeometry geom) {
		this.geom=geom;
	}

	/* (non-Javadoc)
	 * @see java.awt.Shape#getBounds()
	 */
	public Rectangle getBounds() {
		return new Rectangle((int)geom.bbox.getMinX(), (int)geom.bbox.getMinY(), 
				(int)geom.bbox.getWidth(), (int)geom.bbox.getHeight());
	}

	/* (non-Javadoc)
	 * @see java.awt.Shape#getBounds2D()
	 */
	public Rectangle2D getBounds2D() {
		return new Rectangle2D.Double(geom.bbox.getMinX(), geom.bbox.getMinY(), 
				geom.bbox.getWidth(), geom.bbox.getHeight());
	}

	/* (non-Javadoc)
	 * @see java.awt.Shape#contains(double, double)
	 */
	public boolean contains(double x, double y) {
		return geom.bbox.contains(x,y);
	}

	/* (non-Javadoc)
	 * @see java.awt.Shape#contains(java.awt.geom.Point2D)
	 */
	public boolean contains(Point2D p) {
		return geom.bbox.contains(p.getX(), p.getY());
	}

	/* (non-Javadoc)
	 * @see java.awt.Shape#intersects(double, double, double, double)
	 */
	public boolean intersects(double x, double y, double w, double h) {
		return geom.bbox.intersects(new Envelope( x,x+w,y,y+h));
	}

	/* (non-Javadoc)
	 * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
	 */
	public boolean intersects(Rectangle2D r) {
		return geom.bbox.intersects(new Envelope(r.getMinX(), r.getMaxX(), 
				r.getMinY(), r.getMaxY()));
	}

	/* (non-Javadoc)
	 * @see java.awt.Shape#contains(double, double, double, double)
	 */
	public boolean contains(double x, double y, double w, double h) {
		return geom.bbox.contains(new Envelope( x,x+w,y,y+h));
	}

	/* (non-Javadoc)
	 * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
	 */
	public boolean contains(Rectangle2D r) {
		return geom.bbox.contains(new Envelope(r.getMinX(), r.getMaxX(), 
				r.getMinY(), r.getMaxY()));
	}


}
