This is Cube.c in view mode; [Download] [Up]
/* Cube.c File */ extern "C" { #import <stdio.h> } #import "Cube.h" Plane* Cube::plane(CubeInt loc) { CubePos p = getPos(loc); CubeAxis a = getAxis(loc); Plane *newPlane = new Plane(a); for (CubeInt c=0; c<CubeSize; c++) { CubePos notop = (c & CAxisFlag[a]) ? LO : HI; if (notop ^ p) newPlane->addCube(&cubes[c]); } newPlane->swap(); /* Set Properly */ return newPlane; } Plane* Cube::plane(CubeInt loc, CubeAxis split) { CubePos p = getPos(loc); CubeAxis a = getAxis(loc); Plane *newPlane = new Plane[N_SIDE]; newPlane[LO].axis = newPlane[HI].axis = a; for (CubeInt c=0; c<CubeSize; c++) { CubePos noTop = (c & CAxisFlag[a]) ? LO : HI; CubePos sFlag = (c & CAxisFlag[split]) ? LO : HI; if (noTop ^ p) { newPlane[sFlag].addCube(&cubes[c]); } } newPlane[LO].swap(); /* Set Properly */ newPlane[HI].swap(); /* Set Properly */ return newPlane; } Cube& Cube::reset() { for (CubeCoord d = 0; d < CubeNCoords; d++) { Plane *oneSide = plane(d); oneSide->setFace((CubeFace)d); delete oneSide; } return *this; } CubeInt Cube::test() { CubeCoord side=CubeNSides; CubeInt count=CubeNSides; while (side--) { Plane *oneSide = plane(side); if (!oneSide->test()) count--; delete oneSide; } return count; } CubeInt Cube::print() { printf("X0Y0\tX1Y0\tX0Y1\tX1Y1\n"); for (short i=0;i <CubeSize;) { printf("["); for (CubeAxis j =0; j< CubeDim; j++) printf(" %d",cubes[i][j]); printf(" ]"); printf("%c", (++i % 4) ? '\t' : '\n'); } return CubeSize; }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.