ftp.nice.ch/pub/next/science/mathematics/AliceCube.999.N.bs.tar.gz#/AliceCube/Plane.h

This is Plane.h in view mode; [Download] [Up]

/* One Plane of the Cube */

const CubeInt NumCubes = PlaneSize+2;
enum {BASE, CEIL=(NumCubes-1)};	/* Sometimes only half */
#import "Cubicle.h"

class Plane {
	Cubicle* cubes[NumCubes];
	CubeInt size;
      public:
	CubeAxis axis;

	Plane(CubeAxis newAxis=0) {
		axis = newAxis;
		size = 0;
		cubes[BASE] = cubes[CEIL] = (Cubicle*)0;
	}

	Plane& addCube(Cubicle *newCube) {
		cubes[++size] = newCube;
		return *this;
	}
	
	Plane& swap() {		/* Reorder Plane into a loop */
		Cubicle* tempCube = cubes[size];
		cubes[size] = cubes[size-1];
		cubes[size-1] = tempCube;
		return *this;
	}

	Plane& setFace(CubeFace newFace) {
		for (int c=1; c <= size; c++) {
			(*cubes[c])[axis] = newFace;
		}
		return *this;
	}

	CubeInt test() {
		CubeInt c = size;
		CubeFace testFace = (*cubes[c--])[axis];
		while(c) {
			if (!(testFace == (*cubes[c--])[axis])) return c;
		}
		return c;
	}
	
	Plane& rotate(CubeDir dir,CubeAxis around=XYZTMAX) {
		if (getDir(dir)) {
			cubes[BASE] = new Cubicle(*cubes[size]);
			for (int c=size; c >= 1; c--) {
				*cubes[c] = *cubes[c-1];
				cubes[c]->rotate(axis,around);
			}
			delete cubes[BASE];
			cubes[BASE] = (Cubicle*)0;
		} else {
			cubes[size+1] = new Cubicle(*cubes[1]);
			for (int c=1; c <= size; c++) {
				*cubes[c] = *cubes[c+1];
				cubes[c]->rotate(axis,around);
			}
			delete cubes[size+1];
			cubes[size+1] = (Cubicle*)0;
		}
		return *this;
	}

	CubeFace face(CubeInt c, int a) {
	    if (a < 0) a = axis;
	    return (*cubes[c+1])[(CubeAxis)a];
	}
	CubeFace operator[](CubeInt c) {return (*cubes[c+1])[axis];}
};

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.