// Group class for Verlet physics engine
// by Andreas Blixt <andreasblixt@msn.com> 2007
// Free for use. Please include this header.

Group = function (world) {
	// Make sure a world was passed.
	if (!(world instanceof World)) throw "First argument must be an instance of World.";

	// Store a reference to the specified world which this group should belong to.
	this.World = world;

	// Get a unique ID for this group.
	var idCounter = 1;
	while (this.World.GetByID(this.ID = "group" + idCounter++));

	// Create an array for the list of atoms in this group.
	this.Atoms = [];

	// Create an array for the list of constraints in this group.
	this.Constraints = [];

	// Add this group to the specified world.
	world.Groups.push(this);

	// Add this group to the global list of objects.
	world.All.push(this);
};

Group.prototype = {
	// A unique string identifying this particular group.
	ID: "",

	// A reference to the world which this group belongs to.
	World: null,

	// A list of atoms in this group.
	Atoms: null,

	// A list of constraints in this group.
	Constraints: null,

	// Creates a new atom.
	CreateAtom: function (x, y, radius, friction, density) {
		return new Atom(this, x, y, radius, friction, density);
	}
};