/*  This file is part of the source code for 3D-XplorMath-J, Version 1.0 (January 2008).
 *  Copyright (c) 2008 The 3D-XplorMath Consortium (http://3d-xplormath.org).
 *  This source code is released under a BSD License, which allows redistribution   
 *  in source and binary form, with or without modification, provided copyright
 *  and license information are included, and with no warranty or guarantee of
 *  any kind.  For details, see http://3d-xplormath.org/j/source/BSDLicense.txt
 */
 
 package vmm.core.render;

import java.awt.Graphics2D;
import java.awt.geom.Point2D;

import vmm.core.Transform;

public class Pixels2D extends GeometryElement2D {
	
	private double[] x,y;
	
	public Pixels2D(double x, double y) {
		this.x = new double[] { x };
		this.y = new double[] { y };
	}
	
	public Pixels2D(Point2D[] pt, int startIndex, int endIndex) {
		x = new double[endIndex - startIndex];
		y = new double[endIndex - startIndex];
		for (int i = startIndex; i < endIndex; i++) {
			if (pt[i] == null || Double.isNaN(pt[i].getY()))
				x[i-startIndex] = Double.NaN;
			else {
				x[i-startIndex] = pt[i].getX();
				y[i-startIndex] = pt[i].getY();
			}
		}
	}

	protected void draw(Transform transform, Graphics2D g) {
		Point2D.Double p = new Point2D.Double();
		for (int i = 0; i < x.length; i++)
			if ( ! Double.isNaN(x[i])) {
				p.setLocation(x[i],y[i]);
				transform.windowToViewport(p);
				transform.getUntransformedGraphics().fillRect( (int)(p.getX()+0.4999), (int)(p.getY()+0.4999), 1, 1);
			}
	}
	
	

}
