/*
 * Created on Oct 31, 2005
 *
 * This class is a collection of methods for JavaView specific data
 * structures.
 */
package de.tuberlin.polymake.common;

import jv.geom.PgPointSet;
import jv.vecmath.PdVector;

/**
 * @author thilosch
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class JavaviewUtils {
	
	public static PgPointSet toPgPointSet(PointSet ps) {
		PgPointSet pts = new PgPointSet(ps.getDim());
		pts.setName(ps.getName());
		
		for(int i = 0; i < ps.getNPoints(); ++i) {
			pts.addVertex(JavaviewUtils.toPdVector(ps.getPoint(i)));
		}
		return pts;
	}
	
	/**
	 * @param point
	 * @return
	 */
	public static PdVector toPdVector(PolymakePoint point) {
		PdVector vec = new PdVector(point.getCoords());
		vec.setName(point.getLabel());
		return vec;
	}
	
	public static PolymakePoint toPolymakePoint(PdVector pt) {
		String label = pt.getName();
		double[] coords = new double[pt.getSize()];
		System.arraycopy(pt.getEntries(),0,coords,0,pt.getEntries().length);
		return new PolymakePoint(coords,label);
	}

	/**
	 * @param jvPointSet
	 * @return
	 */
	public static PointSet toPointSet(PgPointSet jvPointSet) {
		PointSet points = new PointSet(jvPointSet.getName(),jvPointSet.getNumVertices());
		for(int i=0; i < points.getNPoints(); ++i)
		{
		    points.setPoint(i,JavaviewUtils.toPolymakePoint(jvPointSet.getVertex(i)));
		}
		return points;
	}
}
