Cube.of constructor
Creates a Cube from the your definition
colors U..R..F..D..L..B.
Implementation
factory Cube.of(List<Color> definition) {
if (definition.length != 54) {
throw ArgumentError('Invalid definition');
}
definition = Rotation.correctOrientation(definition);
final cp = List.filled(cornerCount, Corner.upRightFront);
final co = List.filled(cornerCount, 0);
final ep = List.filled(edgeCount, Edge.upRight);
final eo = List.filled(edgeCount, 0);
for (var i = 0; i < cornerCount; i++) {
var ori = 0;
// get the colors of the cube at corner i, starting with U/D
for (; ori < 3; ori++) {
if (definition[_cornerFacelet[i][ori].index] == Color.up ||
definition[_cornerFacelet[i][ori].index] == Color.down) {
break;
}
}
final a = definition[_cornerFacelet[i][(ori + 1) % 3].index];
final b = definition[_cornerFacelet[i][(ori + 2) % 3].index];
for (var j = 0; j < cornerCount; j++) {
if (a == _cornerColor[j][1] && b == _cornerColor[j][2]) {
cp[i] = Corner.values[j];
co[i] = ori % 3;
break;
}
}
}
for (var i = 0; i < edgeCount; i++) {
for (var j = 0; j < edgeCount; j++) {
if (definition[_edgeFacelet[i][0].index] == _edgeColor[j][0] &&
definition[_edgeFacelet[i][1].index] == _edgeColor[j][1]) {
ep[i] = Edge.values[j];
eo[i] = 0;
break;
}
if (definition[_edgeFacelet[i][0].index] == _edgeColor[j][1] &&
definition[_edgeFacelet[i][1].index] == _edgeColor[j][0]) {
ep[i] = Edge.values[j];
eo[i] = 1;
break;
}
}
}
return Cube._(cp: cp, co: co, ep: ep, eo: eo);
}