示例#1
0
        /*@Nonnull*/
        private static Point decodeStarpipe(string input, int firstindex, string extrapostfix,
                                            /*@Nonnull*/ Data mapcoderData)
        {
            // returns Point.isUndefined() in case or error
            int storageStart = 0;
            int thiscodexlen = mapcoderData.CodexLen;

            int value = fastDecode(input); // decode top (before dot)

            value *= 961 * 31;
            Point triple = decodeTriple(input.Substring(input.Length - 3));
            // decode bottom 3 chars

            int i;

            for (i = firstindex; ; i++)
            {
                if (Data.CalcCodexLen(i) != thiscodexlen)
                {
                    return(Point.undefined()); // return undefined
                }
                if (i > firstindex)
                {
                    mapcoderData.dataSetup(i);
                }

                int maxx = mapcoderData.MapcoderRect.getMaxX();
                int maxy = mapcoderData.MapcoderRect.getMaxY();
                int minx = mapcoderData.MapcoderRect.getMinX();
                int miny = mapcoderData.MapcoderRect.getMinY();

                int h    = (maxy - miny + 89) / 90;
                int xdiv = Common.XDivider(miny, maxy);
                int w    = ((maxx - minx) * 4 + xdiv - 1) / xdiv;

                h = 176 * ((h + 176 - 1) / 176);
                w = 168 * ((w + 168 - 1) / 168);

                int product = (w / 168) * (h / 176) * 961 * 31;

                int goodRounder = mapcoderData.Codex >= 23 ? 961 * 961 * 31 : 961 * 961;
                if (mapcoderData.PipeType == 8)
                {
                    // *+
                    product = ((storageStart + product + goodRounder - 1) / goodRounder) * goodRounder - storageStart;
                }

                if (value >= storageStart && value < storageStart + product)
                {
                    // code belongs here?
                    int dividerx = (maxx - minx + w - 1) / w;
                    int dividery = (maxy - miny + h - 1) / h;

                    value -= storageStart;
                    value  = value / (961 * 31);
                    // PIPELETTER DECODE
                    int vx = value / (h / 176);
                    vx = vx * 168 + triple.getLonMicroDeg();
                    int vy = (value % (h / 176)) * 176 + triple.getLatMicroDeg();

                    int cornery = maxy - vy * dividery;
                    int cornerx = minx + vx * dividerx;

                    /*
                     * Sri Lanka Defect (v1.1)
                     * {
                     *   int c1 = (zonedata == 0) ? -1 : decode_chars[(int) input .charAt(input.length() - 3)];
                     *   Point zd = addzonedata(cornery + (triple.getY() - 176) dividery,
                     *     cornerx - triple.getX() * dividerx, 176 * dividery, 168 * dividerx, c1, dividerx,
                     *     dividery);
                     *   cornery = zd.getY();
                     *   cornerx = zd.getX();
                     * }
                     */

                    Point retval = add2res(cornery, cornerx, dividerx << 2, dividery, -1, extrapostfix);

                    return(retval);
                }
                storageStart += product;
            }
            // unreachable
        }