Exemple #1
0
        internal PAxis(PAxis src, double [] tw)
        {
            Base   = src.Base;
            Dir    = PGeom.ApplyTwist(tw, src.Dir);
            Matrix = PGeom.ApplyTwist(tw, src.Matrix);
            int ntw = src.Twists.Length;

            Twists = new double[ntw][];
            for (int i = 0; i < ntw; i++)
            {
                Twists[i] = PGeom.ApplyTwist(tw, src.Twists[i]);
            }
        }
Exemple #2
0
        internal PAxis(PBaseAxis bas)
        {
            Base = bas;
            Dir  = bas.Dir;
            int dim = Dir.Length;

            Matrix = PGeom.MatrixIdentity(dim);
            int ntw = bas.Twists.Length;

            Twists = new double[ntw][];
            for (int i = 0; i < ntw; i++)
            {
                Twists[i] = bas.Twists[i].Dir;
            }
        }
Exemple #3
0
        private void ExpandAxes()
        {
            int q = BaseAxes.Length;

            PAxis[] CAxes = new PAxis[MaxNAxes];
            for (int i = 0; i < q; i++)
            {
                PBaseAxis ax = BaseAxes[i];
                ax.Id = i;
                ax.ExpandPrimaryTwists();
                CAxes[i] = new PAxis(ax); // matrix=id
            }
            for (int p = 0; p < q; p++)
            {
                double[] R = CAxes[p].Dir;
                foreach (double [] G in Group)
                {
                    double[] v = PGeom.ApplyTwist(G, R);
                    int      j;
                    bool     qr;
                    for (j = 0; j < q; j++)
                    {
                        if (PGeom.AxisEqual(v, CAxes[j].Dir, out qr))
                        {
                            break;
                        }
                    }
                    if (j == q)
                    {
                        if (q == MaxNAxes)
                        {
                            throw new Exception("Too many axes");
                        }
                        CAxes[q] = new PAxis(CAxes[p], G);
                        q++;
                    }
                }
            }
            Axes = new PAxis[q];
            for (int i = 0; i < q; i++)
            {
                Axes[i]    = CAxes[i];
                Axes[i].Id = i;
            }
        }
Exemple #4
0
        private void FillFromStrings(string[] descr)
        {
            int       naxis = 0;
            int       caxis = 0;
            PBaseAxis ax    = null;
            int       state = 0;
            int       nv;
            int       fline = 0;

            QSimplified = false;
            try {
                while (state >= 0)
                {
                    if (fline == descr.Length)
                    {
                        if (state != 7)
                        {
                            throw new Exception("Unexpected end");
                        }
                        break;
                    }
                    string line = descr[fline++];
                    if (line == "" || line == null || line[0] == '#')
                    {
                        continue;
                    }
                    string[] str = line.Split(' ', '\t');
                    if (str.Length == 0 || str[0] == "" || str[0] == null)
                    {
                        continue;
                    }
                    string cmd = str[0].ToLowerInvariant();
                    switch (state)
                    {
                    case 0:
                        if (cmd != "dim")
                        {
                            throw new Exception("'Dim' required");
                        }
                        Dim = int.Parse(str[1]);
                        break;

                    case 1:
                        if (cmd != "naxis")
                        {
                            throw new Exception("'NAxis' required");
                        }
                        naxis    = int.Parse(str[1]);
                        BaseAxes = new PBaseAxis[naxis];
                        break;

                    case 2:
                        if (cmd != "faces")
                        {
                            throw new Exception("'Faces' required");
                        }
                        nv        = str.Length - 1;
                        BaseFaces = new PBaseFace[nv];
                        for (int i = 0; i < nv; i++)
                        {
                            BaseFaces[i] = new PBaseFace(GetVector(str[i + 1], Dim));
                        }
                        break;

                    case 3:
                        if (cmd == "simplified")
                        {
                            QSimplified = true; state--; break;
                        }
                        if (cmd != "group")
                        {
                            throw new Exception("'Group' required");
                        }
                        nv    = str.Length - 1;
                        Group = new double[nv][];
                        for (int i = 0; i < nv; i++)
                        {
                            Group[i] = GetVector(str[i + 1], 2 * Dim);
                            PGeom.GetOrder(Group[i]);
                        }
                        if (naxis == 0)
                        {
                            state = -2;
                        }
                        break;

                    case 4:
                        if (cmd != "axis")
                        {
                            throw new Exception("'Axis' required");
                        }
                        ax = new PBaseAxis(GetVector(str[1], Dim));
                        break;

                    case 5:
                        if (cmd != "twists")
                        {
                            throw new Exception("'Twists' required");
                        }
                        nv        = str.Length - 1;
                        ax.Twists = new PBaseTwist[nv];
                        for (int i = 0; i < nv; i++)
                        {
                            ax.Twists[i] = new PBaseTwist(GetVector(str[i + 1], 2 * Dim));
                        }
                        break;

                    case 6:
                        if (cmd != "cuts")
                        {
                            throw new Exception("'Cuts' required");
                        }
                        nv     = str.Length - 1;
                        ax.Cut = new double[nv];
                        for (int i = 0; i < nv; i++)
                        {
                            ax.Cut[i] = double.Parse(str[i + 1], CultureInfo.InvariantCulture);
                        }
                        ax.AdjustCuts();
                        BaseAxes[caxis++] = ax;
                        ax = null;
                        break;

                    case 7: {
                        if (cmd == "fixedmask")
                        {
                            BaseAxes[caxis - 1].FixedMask = int.Parse(str[1]);
                            if (caxis == naxis)
                            {
                                state = -2;
                            }
                            else
                            {
                                state = 3;
                            }
                            break;
                        }
                        if (caxis != naxis)
                        {
                            state = 4; goto case 4;
                        }
                        state = -2;
                        break;
                    }
                    }
                    state++;
                }
            } catch (Exception e) {
                throw new Exception("Error: " + e.Message + " in line " + fline + ": " + (descr[fline] ?? "{null}"));
            }
        }
Exemple #5
0
        private int[][] ConvertStickersFromLayers(PBaseAxis Ax, double[,] matr, PermByMatr P)
        {
            for (int i = 0; i < Axes.Length; i++)
            {
                P.CvAxes[i] = FindAxis(Axes[i].Dir, matr);
            }
            for (int i = 0; i < Faces.Length; i++)
            {
                P.CvFaces[i] = FindFace(Faces[i].Pole, matr);
            }

            int[][] res = new int[Ax.NLayers][];
            for (int i = 0; i < Ax.NLayers; i++)
            {
                if (Ax.Layers[i] != null)
                {
                    int[] rres = (int[])Ax.Layers[i].Clone();

                    int f0 = -1, f1 = -1;
                    int nca = 0;
                    for (int j = 0; j < rres.Length; j++)
                    {
                        int  h  = rres[j];
                        bool cf = false;
                        while (f0 < Faces.Length - 1 && h >= Faces[f0 + 1].FirstSticker)
                        {
                            f0++; cf = true;
                        }
                        if (cf)
                        {
                            f1  = P.CvFaces[f0];
                            nca = Faces[f0].Base.NCutAxes;
                            P.ReallocPerm(nca);
                            for (int k = 0; k < nca; k++)
                            {
                                int rax = Faces[f0].CutAxes[k];
                                int pax = Math.Abs(rax) - 1;
                                int s   = rax < 0 ? -P.CvAxes[pax] : P.CvAxes[pax];
                                for (int l = 0; l < nca; l++)
                                {
                                    int s1 = Faces[f1].CutAxes[l];
                                    if (s1 == s || s1 == -s)
                                    {
                                        P.PermAxes[k] = l;
                                        P.InvAxes[k]  = (s1 != s) ? Axes[pax].Base.NLayers - 1 : 0;
                                        s             = 0;
                                        break;
                                    }
                                }
                                if (s != 0)
                                {
                                    throw new Exception("Can't find converted cutting axis");
                                }
                            }
                        }
                        int ns = h - Faces[f0].FirstSticker;
                        for (int k = 0; k < nca; k++)
                        {
                            int m = Faces[f0].Base.StickerMask[ns, k];
                            if (P.InvAxes[k] != 0)
                            {
                                m = P.InvAxes[k] - m;
                            }
                            P.StkMask[P.PermAxes[k]] = m;
                        }
                        rres[j] = Faces[f1].FirstSticker + Faces[f0].Base.FindByMask(P.StkMask);
                    }
                    res[i] = rres;
                }
            }
            return(res);
        }