/* Copyright (c) 1997-2004
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de

   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, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   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.

   $Project: polymake $$Id: EmbeddedGeometry.java,v 1.2 2004/06/22 16:22:39 gawrilow Exp $
*/

package de.tuberlin.polymake.common;

import jv.geom.*;
import jv.project.*;
import jv.vecmath.*;
import jv.object.*;

/**
 * This class implements ???
 * 
 * @author Thilo Schr&ouml;der
 */
public class EmbeddedGeometry implements Cloneable {
    
    protected int[] vertexList;
    protected PgGeometry geometry;
    protected boolean dynamic = false;
    
    public EmbeddedGeometry(int[] vertexList, PgGeometry geom, boolean dynamic) {
	if(vertexList != null) {
	    this.vertexList = new int[vertexList.length];
	    System.arraycopy(vertexList,0,this.vertexList,0,vertexList.length);
	}
	geometry = (PgGeometry)geom.clone();
	this.dynamic = dynamic;
    }
    
    public EmbeddedGeometry(int[] vertexList) {
	System.arraycopy(vertexList,0,this.vertexList,0,vertexList.length);
    }
    
    public void update(PgPointSet ps, boolean clearTag) {
	for(int i = 0; i < vertexList.length; ++i) {
	    geometry.getVertex(i).copyArray(ps.getVertex(vertexList[i]));
	    if (clearTag) {
		geometry.clearTagVertex(i,PsObject.IS_PICKED);
	    }
	}
	geometry.update(geometry);
    }
    
    public int[] getVertexList() {
	int[] vl = new int[vertexList.length];;
	System.arraycopy(this.vertexList,0,vl,0,vl.length);
	return vl;
    }

    public int getVertexIndex(int i) {
	return vertexList[i];
    }

    public String getName() {
	return geometry.getName();
    }

    public void setGeometry(PgGeometry g) {
	geometry = (PgGeometry)(g.clone());
    }

    public PgGeometry getGeometry() {
	return geometry;
    }

    public boolean isDynamic() {
	return dynamic;
    }

    public Object clone() {
	return new EmbeddedGeometry(vertexList,geometry,dynamic);
    }

    public String toString() {
	String msg = new String();
	msg += "geometry=" + geometry.toString() + "\n";
	msg += "vertexList=";
	if(vertexList!=null) {
	    for(int i = 0; i < vertexList.length; ++i) {
		msg += vertexList[i] + " ";
	    }
	} else {
	    msg += "null";
	}
	msg += "\ndynamic = " + dynamic +"\n";
	return msg;
    }
}
