// a database of polygon definitions

public class polygonDB
{
private static polyDEF polydefs[];
private static int     size;
private static int     num;

//--------- optimization ---------
public  static void init_static(int dim) // dim = max number of polygon definitions
    {
	size = dim;
	num  = 0;
	polydefs = new polyDEF[size];
    }
//--------------------------------
    
public static boolean insert(polyDEF polydef)
    {
	for(int i=0; i<num; i++)
	    {
		if(polydefs[i].name.equals(polydef.name))
		    {
			System.err.println("polygon definition "+ polydef.name +" already exists in the database");
			return false;
		    }
	    }
	polydefs[num++] = polydef;
	return true;
    }

public static polyDEF find(String name)
    {
	for(int i=0; i<num; i++)
	    {
		if(polydefs[i].name.equals(name))
		    return polydefs[i];
	    }
	System.err.println("polygon definition "+ name +" does not exists in the database");
	return null;
    }

public static poly makepoly(String name, bodypart bp)
    {
	polyDEF p = find(name);
	if(p == null)
	    {
		System.err.println("cannot create undefined polygon "+ name);
		return null;
	    }
	return p.makepoly(bp);
    }
}

