public int FindSticker(double x, double y, int mode) { double zmin = double.MaxValue; int res = -1; short[] fld = Cube.Field; for (int ns = 0; ns < NStk; ns++) { StkMesh s = Stks[ns]; if (mode == FIND_STICKER_SELECTED && (fld[ns] & 0x8000) == 0) { continue; } if (mode == FIND_STICKER_CORNER && s.Base.MinBDim != 0) { continue; } if (mode == FIND_STICKER_ANY && (ShowRank & (1 << Math.Min(s.Base.Rank, 11))) == 0) { continue; } if (BPln[s.NFace]) { continue; } double z = s.CheckRay(x, y, zmin); if (z != double.MaxValue && z < zmin) { zmin = z; res = ns; } } return(res); }
internal void InitPuzzle(Puzzle cube) { Cube = cube; int dim = Cube.Str.Dim; NF = Cube.Str.Faces.Length; NStk = Cube.Str.NStickers; SetColorsArray(null); StFaces = new StkMesh[NF]; FPoles = new double[NF][]; Stks = new StkMesh[NStk]; BPln = new bool[NF]; int[] vn = new int[100000 * 4]; lVN = 0; double[][][] FFPoles = new double[NF][][]; for (int i = 0; i < NF; i++) { PFace F = Cube.Str.Faces[i]; StFaces[i] = new StkMesh(F.Base.FaceMesh, i, F.Matrix); FPoles[i] = F.Pole; int fstk = F.FirstSticker; for (int j = 0; j < F.Base.NStickers; j++) { Stks[fstk + j] = new StkMesh(F.Base.StickerMesh[j], i, F.Matrix); Stks[fstk + j].FCtr = F.Pole; } double[][] baseFFP = F.Base.FPoles; FFPoles[i] = new double[baseFFP.Length][]; for (int j = 0; j < baseFFP.Length; j++) { FFPoles[i][j] = PGeom.ApplyMatrix(F.Matrix, baseFFP[j]); } } for (int i = 0; i < NF; i++) { StFaces[i].SetCoord(1, 1); } for (int i = 1; i < NF; i++) { for (int j = 0; j < i; j++) { double[][] pi = FFPoles[i], pj = FFPoles[j]; foreach (double[] vi in pi) { foreach (double[] vj in pj) { if (PtEq(vi, vj, dim)) { goto _1; } } } continue; _1: StkMesh Fi = StFaces[i], Fj = StFaces[j]; float[] fpi = Fi.Coords, fpj = Fj.Coords; for (int i1 = 0; i1 < fpi.Length; i1 += dim) { for (int j1 = 0; j1 < fpj.Length; j1 += dim) { if (PtEq(fpi, i1, fpj, j1, dim)) { vn[lVN++] = i; vn[lVN++] = i1; vn[lVN++] = j; vn[lVN++] = j1; break; } } } } } VertNetwork = new int[lVN]; Buffer.BlockCopy(vn, 0, VertNetwork, 0, lVN * sizeof(int)); }