コード例 #1
0
        internal static double Exact(double[] pa, double[] pb, double[] pc)
        {
            MacrosHelpers.TwoProduct(pa[0], pb[1], out double axby1, out double axby0);
            MacrosHelpers.TwoProduct(pa[0], pc[1], out double axcy1, out double axcy0);
            double[] aterms = new double[4];
            MacrosHelpers.TwoTwoDiff(axby1, axby0, axcy1, axcy0, out aterms[3], out aterms[2], out aterms[1], out aterms[0]);

            MacrosHelpers.TwoProduct(pb[0], pc[1], out double bxcy1, out double bxcy0);
            MacrosHelpers.TwoProduct(pb[0], pa[1], out double bxay1, out double bxay0);

            double[] bterms = new double[4];
            MacrosHelpers.TwoTwoDiff(bxcy1, bxcy0, bxay1, bxay0, out bterms[3], out bterms[2], out bterms[1], out bterms[0]);

            MacrosHelpers.TwoProduct(pc[0], pa[1], out double cxay1, out double cxay0);
            MacrosHelpers.TwoProduct(pc[0], pb[1], out double cxby1, out double cxby0);


            double[] cterms = new double[4];
            MacrosHelpers.TwoTwoDiff(cxay1, cxay0, cxby1, cxby0, out cterms[3], out cterms[2], out cterms[1], out cterms[0]);

            double[] v       = new double[8];
            double[] w       = new double[12];
            int      vlen    = ArithmeticFunctions.FastExpansionSumZeroelim(4, aterms, 4, bterms, v);
            int      wlength = ArithmeticFunctions.FastExpansionSumZeroelim(vlen, v, 4, cterms, w);

            return(w[wlength - 1]);
        }
コード例 #2
0
        internal static double Slow(double[] pa, double[] pb, double[] pc)
        {
            MacrosHelpers.TwoDiff(pa[0], pc[0], out double acx, out double acxtail);
            MacrosHelpers.TwoDiff(pa[1], pc[1], out double acy, out double acytail);
            MacrosHelpers.TwoDiff(pb[0], pc[0], out double bcx, out double bcxtail);
            MacrosHelpers.TwoDiff(pb[1], pc[1], out double bcy, out double bcytail);
            double[] axby = new double[8];

            MacrosHelpers.TwoTwoProduct(acx, acxtail, bcy, bcytail,
                                        out axby[7], out axby[6], out axby[5], out axby[4],
                                        out axby[3], out axby[2], out axby[1], out axby[0]);
            double negate     = -acy;
            double negatetail = -acytail;

            double[] bxay = new double[8];
            MacrosHelpers.TwoTwoProduct(bcx, bcxtail, negate, negatetail,
                                        out bxay[7], out bxay[6], out bxay[5], out bxay[4],
                                        out bxay[3], out bxay[2], out bxay[1], out bxay[0]);

            double[] deter    = new double[16];
            int      deterlen = ArithmeticFunctions.FastExpansionSumZeroelim(8, axby, 8, bxay, deter);

            return(deter[deterlen - 1]);
        }
コード例 #3
0
ファイル: InSphere.cs プロジェクト: modios/robust-predicates
        private static double Adapt(double[] pa, double[] pb, double[] pc, double[] pd, double[] pe, double permanent)
        {
            var aex = pa[0] - pe[0];
            var bex = pb[0] - pe[0];
            var cex = pc[0] - pe[0];
            var dex = pd[0] - pe[0];
            var aey = pa[1] - pe[1];
            var bey = pb[1] - pe[1];
            var cey = pc[1] - pe[1];
            var dey = pd[1] - pe[1];
            var aez = pa[2] - pe[2];
            var bez = pb[2] - pe[2];
            var cez = pc[2] - pe[2];
            var dez = pd[2] - pe[2];

            MacrosHelpers.TwoProduct(aex, bey, out double aexbey1, out double aexbey0);
            MacrosHelpers.TwoProduct(bex, aey, out double bexaey1, out double bexaey0);
            double[] ab = new double[4];
            MacrosHelpers.TwoTwoDiff(aexbey1, aexbey0, bexaey1, bexaey0, out ab[3], out ab[2], out ab[1], out ab[0]);

            MacrosHelpers.TwoProduct(bex, cey, out double bexcey1, out double bexcey0);
            MacrosHelpers.TwoProduct(cex, bey, out double cexbey1, out double cexbey0);
            double[] bc = new double[4];
            MacrosHelpers.TwoTwoDiff(bexcey1, bexcey0, cexbey1, cexbey0, out bc[3], out bc[2], out bc[1], out bc[0]);

            MacrosHelpers.TwoProduct(cex, dey, out double cexdey1, out double cexdey0);
            MacrosHelpers.TwoProduct(dex, cey, out double dexcey1, out double dexcey0);
            double[] cd = new double[4];
            MacrosHelpers.TwoTwoDiff(cexdey1, cexdey0, dexcey1, dexcey0, out cd[3], out cd[2], out cd[1], out cd[0]);

            MacrosHelpers.TwoProduct(dex, aey, out double dexaey1, out double dexaey0);
            MacrosHelpers.TwoProduct(aex, dey, out double aexdey1, out double aexdey0);
            double[] da = new double[4];
            MacrosHelpers.TwoTwoDiff(dexaey1, dexaey0, aexdey1, aexdey0, out da[3], out da[2], out da[1], out da[0]);

            MacrosHelpers.TwoProduct(aex, cey, out double aexcey1, out double aexcey0);
            MacrosHelpers.TwoProduct(cex, aey, out double cexaey1, out double cexaey0);
            double[] ac = new double[4];
            MacrosHelpers.TwoTwoDiff(aexcey1, aexcey0, cexaey1, cexaey0, out ac[3], out ac[2], out ac[1], out ac[0]);

            MacrosHelpers.TwoProduct(bex, dey, out double bexdey1, out double bexdey0);
            MacrosHelpers.TwoProduct(dex, bey, out double dexbey1, out double dexbey0);
            double[] bd = new double[4];
            MacrosHelpers.TwoTwoDiff(bexdey1, bexdey0, dexbey1, dexbey0, out bd[3], out bd[2], out bd[1], out bd[0]);

            double[] temp8a    = new double[8];
            double[] temp8b    = new double[8];
            double[] temp8c    = new double[8];
            var      temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, cd, bez, temp8a);
            var      temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bd, -cez, temp8b);
            var      temp8clen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, dez, temp8c);

            double[] temp16    = new double[16];
            var      temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a,
                                                                              temp8blen, temp8b, temp16);

            double[] temp24    = new double[24];
            var      temp24len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8clen, temp8c,
                                                                              temp16len, temp16, temp24);

            double[] temp48    = new double[48];
            var      temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, aex, temp48);

            double[] xdet = new double[96];
            var      xlen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, -aex, xdet);

            temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, aey, temp48);
            double[] ydet = new double[96];
            var      ylen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, -aey, ydet);

            temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, aez, temp48);
            double[] zdet = new double[96];
            var      zlen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, -aez, zdet);

            double[] xydet = new double[192];
            var      xylen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, xdet, ylen, ydet, xydet);

            double[] adet = new double[288];
            var      alen = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, xydet, zlen, zdet, adet);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, da, cez, temp8a);
            temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ac, dez, temp8b);
            temp8clen = ArithmeticFunctions.ScaleExpansionZeroelim(4, cd, aez, temp8c);
            temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a,
                                                                     temp8blen, temp8b, temp16);
            temp24len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8clen, temp8c,
                                                                     temp16len, temp16, temp24);
            temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, bex, temp48);
            xlen      = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, bex, xdet);
            temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, bey, temp48);
            ylen      = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, bey, ydet);
            temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, bez, temp48);
            zlen      = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, bez, zdet);
            xylen     = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, xdet, ylen, ydet, xydet);
            double[] bdet = new double[288];
            var      blen = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, xydet, zlen, zdet, bdet);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, dez, temp8a);
            temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bd, aez, temp8b);
            temp8clen = ArithmeticFunctions.ScaleExpansionZeroelim(4, da, bez, temp8c);
            temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a,
                                                                     temp8blen, temp8b, temp16);
            temp24len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8clen, temp8c,
                                                                     temp16len, temp16, temp24);
            temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, cex, temp48);
            xlen      = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, -cex, xdet);
            temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, cey, temp48);
            ylen      = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, -cey, ydet);
            temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, cez, temp48);
            zlen      = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, -cez, zdet);
            xylen     = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, xdet, ylen, ydet, xydet);
            double[] cdet = new double[288];
            var      clen = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, xydet, zlen, zdet, cdet);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, aez, temp8a);
            temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ac, -bez, temp8b);
            temp8clen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cez, temp8c);
            temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a,
                                                                     temp8blen, temp8b, temp16);
            temp24len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8clen, temp8c,
                                                                     temp16len, temp16, temp24);
            temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, dex, temp48);
            xlen      = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, dex, xdet);
            temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, dey, temp48);
            ylen      = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, dey, ydet);
            temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, dez, temp48);
            zlen      = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, dez, zdet);
            xylen     = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, xdet, ylen, ydet, xydet);
            double[] ddet = new double[288];
            var      dlen = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, xydet, zlen, zdet, ddet);

            double[] abdet     = new double[576];
            double[] cddet     = new double[576];
            double[] fin1      = new double[1152];
            var      ablen     = ArithmeticFunctions.FastExpansionSumZeroelim(alen, adet, blen, bdet, abdet);
            var      cdlen     = ArithmeticFunctions.FastExpansionSumZeroelim(clen, cdet, dlen, ddet, cddet);
            var      finlength = ArithmeticFunctions.FastExpansionSumZeroelim(ablen, abdet, cdlen, cddet, fin1);
            var      det       = ArithmeticFunctions.Estimate(finlength, fin1);
            var      errbound  = MacrosHelpers.IsperrboundB * permanent;

            if ((det >= errbound) || (-det >= errbound))
            {
                return(det);
            }

            MacrosHelpers.TwoDiffTail(pa[0], pe[0], aex, out double aextail);
            MacrosHelpers.TwoDiffTail(pa[1], pe[1], aey, out double aeytail);
            MacrosHelpers.TwoDiffTail(pa[2], pe[2], aez, out double aeztail);
            MacrosHelpers.TwoDiffTail(pb[0], pe[0], bex, out double bextail);
            MacrosHelpers.TwoDiffTail(pb[1], pe[1], bey, out double beytail);
            MacrosHelpers.TwoDiffTail(pb[2], pe[2], bez, out double beztail);
            MacrosHelpers.TwoDiffTail(pc[0], pe[0], cex, out double cextail);
            MacrosHelpers.TwoDiffTail(pc[1], pe[1], cey, out double ceytail);
            MacrosHelpers.TwoDiffTail(pc[2], pe[2], cez, out double ceztail);
            MacrosHelpers.TwoDiffTail(pd[0], pe[0], dex, out double dextail);
            MacrosHelpers.TwoDiffTail(pd[1], pe[1], dey, out double deytail);
            MacrosHelpers.TwoDiffTail(pd[2], pe[2], dez, out double deztail);

            if ((aextail == 0.0) && (aeytail == 0.0) && (aeztail == 0.0) &&
                (bextail == 0.0) && (beytail == 0.0) && (beztail == 0.0) &&
                (cextail == 0.0) && (ceytail == 0.0) && (ceztail == 0.0) &&
                (dextail == 0.0) && (deytail == 0.0) && (deztail == 0.0))
            {
                return(det);
            }

            var da3 = da[3];
            var ac3 = ac[3];
            var cd3 = cd[3];
            var ab3 = ab[3];
            var bc3 = bc[3];
            var bd3 = bd[3];

            errbound = MacrosHelpers.IsperrboundC * permanent + MacrosHelpers.Resulterrbound * Math.Abs(det);
            var abeps = (aex * beytail + bey * aextail)
                        - (aey * bextail + bex * aeytail);
            var bceps = (bex * ceytail + cey * bextail)
                        - (bey * cextail + cex * beytail);
            var cdeps = (cex * deytail + dey * cextail)
                        - (cey * dextail + dex * ceytail);
            var daeps = (dex * aeytail + aey * dextail)
                        - (dey * aextail + aex * deytail);
            var aceps = (aex * ceytail + cey * aextail)
                        - (aey * cextail + cex * aeytail);
            var bdeps = (bex * deytail + dey * bextail)
                        - (bey * dextail + dex * beytail);

            det += (((bex * bex + bey * bey + bez * bez)
                     * ((cez * daeps + dez * aceps + aez * cdeps)
                        + (ceztail * da3 + deztail * ac3 + aeztail * cd3))
                     + (dex * dex + dey * dey + dez * dez)
                     * ((aez * bceps - bez * aceps + cez * abeps)
                        + (aeztail * bc3 - beztail * ac3 + ceztail * ab3)))
                    - ((aex * aex + aey * aey + aez * aez)
                       * ((bez * cdeps - cez * bdeps + dez * bceps)
                          + (beztail * cd3 - ceztail * bd3 + deztail * bc3))
                       + (cex * cex + cey * cey + cez * cez)
                       * ((dez * abeps + aez * bdeps + bez * daeps)
                          + (deztail * ab3 + aeztail * bd3 + beztail * da3))))
                   + 2.0 * (((bex * bextail + bey * beytail + bez * beztail)
                             * (cez * da3 + dez * ac3 + aez * cd3)
                             + (dex * dextail + dey * deytail + dez * deztail)
                             * (aez * bc3 - bez * ac3 + cez * ab3))
                            - ((aex * aextail + aey * aeytail + aez * aeztail)
                               * (bez * cd3 - cez * bd3 + dez * bc3)
                               + (cex * cextail + cey * ceytail + cez * ceztail)
                               * (dez * ab3 + aez * bd3 + bez * da3)));
            if ((det >= errbound) || (-det >= errbound))
            {
                return(det);
            }

            return(Exact(pa, pb, pc, pd, pe));
        }
コード例 #4
0
ファイル: InSphere.cs プロジェクト: modios/robust-predicates
        private static double Exact(double[] pa, double[] pb, double[] pc, double[] pd, double[] pe)
        {
            MacrosHelpers.TwoProduct(pa[0], pb[1], out double axby1, out double axby0);
            MacrosHelpers.TwoProduct(pb[0], pa[1], out double bxay1, out double bxay0);
            var ab = new double[4];

            MacrosHelpers.TwoTwoDiff(axby1, axby0, bxay1, bxay0, out ab[3], out ab[2], out ab[1], out ab[0]);

            MacrosHelpers.TwoProduct(pb[0], pc[1], out double bxcy1, out double bxcy0);
            MacrosHelpers.TwoProduct(pc[0], pb[1], out double cxby1, out double cxby0);
            var bc = new double[4];

            MacrosHelpers.TwoTwoDiff(bxcy1, bxcy0, cxby1, cxby0, out bc[3], out bc[2], out bc[1], out bc[0]);

            MacrosHelpers.TwoProduct(pc[0], pd[1], out double cxdy1, out double cxdy0);
            MacrosHelpers.TwoProduct(pd[0], pc[1], out double dxcy1, out double dxcy0);
            var cd = new double[4];

            MacrosHelpers.TwoTwoDiff(cxdy1, cxdy0, dxcy1, dxcy0, out cd[3], out cd[2], out cd[1], out cd[0]);

            MacrosHelpers.TwoProduct(pd[0], pe[1], out double dxey1, out double dxey0);
            MacrosHelpers.TwoProduct(pe[0], pd[1], out double exdy1, out double exdy0);
            var de = new double[4];

            MacrosHelpers.TwoTwoDiff(dxey1, dxey0, exdy1, exdy0, out de[3], out de[2], out de[1], out de[0]);

            MacrosHelpers.TwoProduct(pe[0], pa[1], out double exay1, out double exay0);
            MacrosHelpers.TwoProduct(pa[0], pe[1], out double axey1, out double axey0);
            var ea = new double[4];

            MacrosHelpers.TwoTwoDiff(exay1, exay0, axey1, axey0, out ea[3], out ea[2], out ea[1], out ea[0]);

            MacrosHelpers.TwoProduct(pa[0], pc[1], out double axcy1, out double axcy0);
            MacrosHelpers.TwoProduct(pc[0], pa[1], out double cxay1, out double cxay0);
            var ac = new double[4];

            MacrosHelpers.TwoTwoDiff(axcy1, axcy0, cxay1, cxay0, out ac[3], out ac[2], out ac[1], out ac[0]);

            MacrosHelpers.TwoProduct(pb[0], pd[1], out double bxdy1, out double bxdy0);
            MacrosHelpers.TwoProduct(pd[0], pb[1], out double dxby1, out double dxby0);
            var bd = new double[4];

            MacrosHelpers.TwoTwoDiff(bxdy1, bxdy0, dxby1, dxby0, out bd[3], out bd[2], out bd[1], out bd[0]);

            MacrosHelpers.TwoProduct(pc[0], pe[1], out double cxey1, out double cxey0);
            MacrosHelpers.TwoProduct(pe[0], pc[1], out double excy1, out double excy0);
            var ce = new double[4];

            MacrosHelpers.TwoTwoDiff(cxey1, cxey0, excy1, excy0, out ce[3], out ce[2], out ce[1], out ce[0]);

            MacrosHelpers.TwoProduct(pd[0], pa[1], out double dxay1, out double dxay0);
            MacrosHelpers.TwoProduct(pa[0], pd[1], out double axdy1, out double axdy0);
            var da = new double[4];

            MacrosHelpers.TwoTwoDiff(dxay1, dxay0, axdy1, axdy0, out da[3], out da[2], out da[1], out da[0]);

            MacrosHelpers.TwoProduct(pe[0], pb[1], out double exby1, out double exby0);
            MacrosHelpers.TwoProduct(pb[0], pe[1], out double bxey1, out double bxey0);
            var eb = new double[4];

            MacrosHelpers.TwoTwoDiff(exby1, exby0, bxey1, bxey0, out eb[3], out eb[2], out eb[1], out eb[0]);

            var temp8a    = new double[8];
            var temp8b    = new double[8];
            var temp16    = new double[16];
            var temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, pa[2], temp8a);
            var temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ac, -pb[2], temp8b);
            var temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b,
                                                                         temp16);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, pc[2], temp8a);
            var abc    = new double[24];
            var abclen = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp16len, temp16,
                                                                      abc);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, cd, pb[2], temp8a);
            temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bd, -pc[2], temp8b);
            temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b,
                                                                     temp16);
            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, pd[2], temp8a);
            var bcd    = new double[24];
            var bcdlen = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp16len, temp16,
                                                                      bcd);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, de, pc[2], temp8a);
            temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ce, -pd[2], temp8b);
            temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b,
                                                                     temp16);
            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, cd, pe[2], temp8a);
            var cde    = new double[24];
            var cdelen = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp16len, temp16,
                                                                      cde);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ea, pd[2], temp8a);
            temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, da, -pe[2], temp8b);
            temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b,
                                                                     temp16);
            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, de, pa[2], temp8a);
            var dea    = new double[24];
            var dealen = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp16len, temp16,
                                                                      dea);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, pe[2], temp8a);
            temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, eb, -pa[2], temp8b);
            temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b,
                                                                     temp16);
            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ea, pb[2], temp8a);
            var eab    = new double[24];
            var eablen = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp16len, temp16,
                                                                      eab);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bd, pa[2], temp8a);
            temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, da, pb[2], temp8b);
            temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b,
                                                                     temp16);
            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, pd[2], temp8a);
            var abd    = new double[24];
            var abdlen = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp16len, temp16,
                                                                      abd);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ce, pb[2], temp8a);
            temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, eb, pc[2], temp8b);
            temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b,
                                                                     temp16);
            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, pe[2], temp8a);
            var bce    = new double[24];
            var bcelen = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp16len, temp16,
                                                                      bce);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, da, pc[2], temp8a);
            temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ac, pd[2], temp8b);
            temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b,
                                                                     temp16);
            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, cd, pa[2], temp8a);
            var cda    = new double[24];
            var cdalen = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp16len, temp16,
                                                                      cda);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, eb, pd[2], temp8a);
            temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bd, pe[2], temp8b);
            temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b,
                                                                     temp16);
            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, de, pb[2], temp8a);
            var deb    = new double[24];
            var deblen = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp16len, temp16,
                                                                      deb);

            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ac, pe[2], temp8a);
            temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ce, pa[2], temp8b);
            temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b,
                                                                     temp16);
            temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ea, pc[2], temp8a);
            var eac    = new double[24];
            var eaclen = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp16len, temp16,
                                                                      eac);

            var temp48a    = new double[48];
            var temp48b    = new double[48];
            var temp48alen = ArithmeticFunctions.FastExpansionSumZeroelim(cdelen, cde, bcelen, bce, temp48a);
            var temp48blen = ArithmeticFunctions.FastExpansionSumZeroelim(deblen, deb, bcdlen, bcd, temp48b);

            for (int i = 0; i < temp48blen; i++)
            {
                temp48b[i] = -temp48b[i];
            }

            var bcde    = new double[96];
            var bcdelen = ArithmeticFunctions.FastExpansionSumZeroelim(temp48alen, temp48a,
                                                                       temp48blen, temp48b, bcde);

            var temp192 = new double[192];
            var xlen    = ArithmeticFunctions.ScaleExpansionZeroelim(bcdelen, bcde, pa[0], temp192);

            var det384x = new double[384];
            var det384y = new double[384];
            var det384z = new double[384];

            xlen = ArithmeticFunctions.ScaleExpansionZeroelim(xlen, temp192, pa[0], det384x);
            var ylen = ArithmeticFunctions.ScaleExpansionZeroelim(bcdelen, bcde, pa[1], temp192);

            ylen = ArithmeticFunctions.ScaleExpansionZeroelim(ylen, temp192, pa[1], det384y);
            var zlen = ArithmeticFunctions.ScaleExpansionZeroelim(bcdelen, bcde, pa[2], temp192);

            zlen = ArithmeticFunctions.ScaleExpansionZeroelim(zlen, temp192, pa[2], det384z);

            var detxy = new double[786];
            var adet  = new double[1152];
            var xylen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, det384x, ylen, det384y, detxy);
            var alen  = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, detxy, zlen, det384z, adet);

            temp48alen = ArithmeticFunctions.FastExpansionSumZeroelim(dealen, dea, cdalen, cda, temp48a);
            temp48blen = ArithmeticFunctions.FastExpansionSumZeroelim(eaclen, eac, cdelen, cde, temp48b);
            for (int i = 0; i < temp48blen; i++)
            {
                temp48b[i] = -temp48b[i];
            }

            var cdea    = new double[1152];
            var cdealen = ArithmeticFunctions.FastExpansionSumZeroelim(temp48alen, temp48a,
                                                                       temp48blen, temp48b, cdea);

            xlen  = ArithmeticFunctions.ScaleExpansionZeroelim(cdealen, cdea, pb[0], temp192);
            xlen  = ArithmeticFunctions.ScaleExpansionZeroelim(xlen, temp192, pb[0], det384x);
            ylen  = ArithmeticFunctions.ScaleExpansionZeroelim(cdealen, cdea, pb[1], temp192);
            ylen  = ArithmeticFunctions.ScaleExpansionZeroelim(ylen, temp192, pb[1], det384y);
            zlen  = ArithmeticFunctions.ScaleExpansionZeroelim(cdealen, cdea, pb[2], temp192);
            zlen  = ArithmeticFunctions.ScaleExpansionZeroelim(zlen, temp192, pb[2], det384z);
            xylen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, det384x, ylen, det384y, detxy);
            var bdet = new double[1152];
            var blen = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, detxy, zlen, det384z, bdet);

            temp48alen = ArithmeticFunctions.FastExpansionSumZeroelim(eablen, eab, deblen, deb, temp48a);
            temp48blen = ArithmeticFunctions.FastExpansionSumZeroelim(abdlen, abd, dealen, dea, temp48b);
            for (int i = 0; i < temp48blen; i++)
            {
                temp48b[i] = -temp48b[i];
            }

            var deab    = new double[96];
            var deablen = ArithmeticFunctions.FastExpansionSumZeroelim(temp48alen, temp48a,
                                                                       temp48blen, temp48b, deab);

            xlen  = ArithmeticFunctions.ScaleExpansionZeroelim(deablen, deab, pc[0], temp192);
            xlen  = ArithmeticFunctions.ScaleExpansionZeroelim(xlen, temp192, pc[0], det384x);
            ylen  = ArithmeticFunctions.ScaleExpansionZeroelim(deablen, deab, pc[1], temp192);
            ylen  = ArithmeticFunctions.ScaleExpansionZeroelim(ylen, temp192, pc[1], det384y);
            zlen  = ArithmeticFunctions.ScaleExpansionZeroelim(deablen, deab, pc[2], temp192);
            zlen  = ArithmeticFunctions.ScaleExpansionZeroelim(zlen, temp192, pc[2], det384z);
            xylen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, det384x, ylen, det384y, detxy);
            var cdet = new double[1152];
            var clen = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, detxy, zlen, det384z, cdet);

            temp48alen = ArithmeticFunctions.FastExpansionSumZeroelim(abclen, abc, eaclen, eac, temp48a);
            temp48blen = ArithmeticFunctions.FastExpansionSumZeroelim(bcelen, bce, eablen, eab, temp48b);
            for (int i = 0; i < temp48blen; i++)
            {
                temp48b[i] = -temp48b[i];
            }

            var eabc    = new double[96];
            var eabclen = ArithmeticFunctions.FastExpansionSumZeroelim(temp48alen, temp48a,
                                                                       temp48blen, temp48b, eabc);

            xlen  = ArithmeticFunctions.ScaleExpansionZeroelim(eabclen, eabc, pd[0], temp192);
            xlen  = ArithmeticFunctions.ScaleExpansionZeroelim(xlen, temp192, pd[0], det384x);
            ylen  = ArithmeticFunctions.ScaleExpansionZeroelim(eabclen, eabc, pd[1], temp192);
            ylen  = ArithmeticFunctions.ScaleExpansionZeroelim(ylen, temp192, pd[1], det384y);
            zlen  = ArithmeticFunctions.ScaleExpansionZeroelim(eabclen, eabc, pd[2], temp192);
            zlen  = ArithmeticFunctions.ScaleExpansionZeroelim(zlen, temp192, pd[2], det384z);
            xylen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, det384x, ylen, det384y, detxy);
            var ddet = new double[1152];
            var dlen = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, detxy, zlen, det384z, ddet);

            temp48alen = ArithmeticFunctions.FastExpansionSumZeroelim(bcdlen, bcd, abdlen, abd, temp48a);
            temp48blen = ArithmeticFunctions.FastExpansionSumZeroelim(cdalen, cda, abclen, abc, temp48b);
            for (int i = 0; i < temp48blen; i++)
            {
                temp48b[i] = -temp48b[i];
            }

            var abcd    = new double[96];
            var abcdlen = ArithmeticFunctions.FastExpansionSumZeroelim(temp48alen, temp48a,
                                                                       temp48blen, temp48b, abcd);

            xlen  = ArithmeticFunctions.ScaleExpansionZeroelim(abcdlen, abcd, pe[0], temp192);
            xlen  = ArithmeticFunctions.ScaleExpansionZeroelim(xlen, temp192, pe[0], det384x);
            ylen  = ArithmeticFunctions.ScaleExpansionZeroelim(abcdlen, abcd, pe[1], temp192);
            ylen  = ArithmeticFunctions.ScaleExpansionZeroelim(ylen, temp192, pe[1], det384y);
            zlen  = ArithmeticFunctions.ScaleExpansionZeroelim(abcdlen, abcd, pe[2], temp192);
            zlen  = ArithmeticFunctions.ScaleExpansionZeroelim(zlen, temp192, pe[2], det384z);
            xylen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, det384x, ylen, det384y, detxy);
            var edet   = new double[1152];
            var elen   = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, detxy, zlen, det384z, edet);
            var abdet  = new double[2304];
            var ablen  = ArithmeticFunctions.FastExpansionSumZeroelim(alen, adet, blen, bdet, abdet);
            var cddet  = new double[2304];
            var cdlen  = ArithmeticFunctions.FastExpansionSumZeroelim(clen, cdet, dlen, ddet, cddet);
            var cdedet = new double[3456];

            cdelen = ArithmeticFunctions.FastExpansionSumZeroelim(cdlen, cddet, elen, edet, cdedet);
            var deter    = new double[5760];
            var deterlen = ArithmeticFunctions.FastExpansionSumZeroelim(ablen, abdet, cdelen, cdedet, deter);

            return(deter[deterlen - 1]);
        }
コード例 #5
0
ファイル: Orient3D.cs プロジェクト: modios/robust-predicates
        private static double Adapt(double[] pa, double[] pb, double[] pc, double[] pd, double permanent)
        {
            var adx = pa[0] - pd[0];
            var bdx = pb[0] - pd[0];
            var cdx = pc[0] - pd[0];
            var ady = pa[1] - pd[1];
            var bdy = pb[1] - pd[1];
            var cdy = pc[1] - pd[1];
            var adz = pa[2] - pd[2];
            var bdz = pb[2] - pd[2];
            var cdz = pc[2] - pd[2];

            MacrosHelpers.TwoProduct(bdx, cdy, out double bdxcdy1, out double bdxcdy0);
            MacrosHelpers.TwoProduct(cdx, bdy, out double cdxbdy1, out double cdxbdy0);
            var bc = new double[4];

            MacrosHelpers.TwoTwoDiff(bdxcdy1, bdxcdy0, cdxbdy1, cdxbdy0, out bc[3], out bc[2], out bc[1], out bc[0]);
            double[] adet = new double[8];
            var      alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, adz, adet);

            MacrosHelpers.TwoProduct(cdx, ady, out double cdxady1, out double cdxady0);
            MacrosHelpers.TwoProduct(adx, cdy, out double adxcdy1, out double adxcdy0);
            var ca = new double[4];

            MacrosHelpers.TwoTwoDiff(cdxady1, cdxady0, adxcdy1, adxcdy0, out ca[3], out ca[2], out ca[1], out ca[0]);
            double[] bdet = new double[8];
            var      blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ca, bdz, bdet);

            MacrosHelpers.TwoProduct(adx, bdy, out double adxbdy1, out double adxbdy0);
            MacrosHelpers.TwoProduct(bdx, ady, out double bdxady1, out double bdxady0);
            var ab = new double[4];

            MacrosHelpers.TwoTwoDiff(adxbdy1, adxbdy0, bdxady1, bdxady0, out ab[3], out ab[2], out ab[1], out ab[0]);

            double[] cdet = new double[8];
            var      clen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cdz, cdet);

            double[] abdet = new double[16];
            var      ablen = ArithmeticFunctions.FastExpansionSumZeroelim(alen, adet, blen, bdet, abdet);

            double[] fin1      = new double[192];
            var      finlength = ArithmeticFunctions.FastExpansionSumZeroelim(ablen, abdet, clen, cdet, fin1);

            var det = ArithmeticFunctions.Estimate(finlength, fin1);

            var errbound = MacrosHelpers.O3derrboundB * permanent;

            if ((det >= errbound) || (-det >= errbound))
            {
                return(det);
            }

            MacrosHelpers.TwoDiffTail(pa[0], pd[0], adx, out double adxtail);
            MacrosHelpers.TwoDiffTail(pb[0], pd[0], bdx, out double bdxtail);
            MacrosHelpers.TwoDiffTail(pc[0], pd[0], cdx, out double cdxtail);
            MacrosHelpers.TwoDiffTail(pa[1], pd[1], ady, out double adytail);
            MacrosHelpers.TwoDiffTail(pb[1], pd[1], bdy, out double bdytail);
            MacrosHelpers.TwoDiffTail(pc[1], pd[1], cdy, out double cdytail);
            MacrosHelpers.TwoDiffTail(pa[2], pd[2], adz, out double adztail);
            MacrosHelpers.TwoDiffTail(pb[2], pd[2], bdz, out double bdztail);
            MacrosHelpers.TwoDiffTail(pc[2], pd[2], cdz, out double cdztail);

            if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0) &&
                (adytail == 0.0) && (bdytail == 0.0) && (cdytail == 0.0) &&
                (adztail == 0.0) && (bdztail == 0.0) && (cdztail == 0.0))
            {
                return(det);
            }

            errbound = MacrosHelpers.O3derrboundC * permanent + MacrosHelpers.Resulterrbound * Math.Abs(det);
            det     += (adz * ((bdx * cdytail + cdy * bdxtail)
                               - (bdy * cdxtail + cdx * bdytail))
                        + adztail * (bdx * cdy - bdy * cdx))
                       + (bdz * ((cdx * adytail + ady * cdxtail)
                                 - (cdy * adxtail + adx * cdytail))
                          + bdztail * (cdx * ady - cdy * adx))
                       + (cdz * ((adx * bdytail + bdy * adxtail)
                                 - (ady * bdxtail + bdx * adytail))
                          + cdztail * (adx * bdy - ady * bdx));
            if ((det >= errbound) || (-det >= errbound))
            {
                return(det);
            }

            var finnow   = fin1;
            var fin2     = new double[192];
            var finother = fin2;

            double[] at_b = new double[4];
            double[] at_c = new double[4];
            int      at_blen;
            int      at_clen;

            if (adxtail == 0.0)
            {
                if (adytail == 0.0)
                {
                    at_b[0] = 0.0;
                    at_blen = 1;
                    at_c[0] = 0.0;
                    at_clen = 1;
                }
                else
                {
                    var negate = -adytail;
                    MacrosHelpers.TwoProduct(negate, bdx, out at_b[1], out at_b[0]);
                    at_blen = 2;
                    MacrosHelpers.TwoProduct(adytail, cdx, out at_c[1], out at_c[0]);
                    at_clen = 2;
                }
            }
            else
            {
                if (adytail == 0.0)
                {
                    MacrosHelpers.TwoProduct(adxtail, bdy, out at_b[1], out at_b[0]);
                    at_blen = 2;
                    var negate = -adxtail;
                    MacrosHelpers.TwoProduct(negate, cdy, out at_c[1], out at_c[0]);
                    at_clen = 2;
                }
                else
                {
                    MacrosHelpers.TwoProduct(adxtail, bdy, out double adxt_bdy1, out double adxt_bdy0);
                    MacrosHelpers.TwoProduct(adytail, bdx, out double adyt_bdx1, out double adyt_bdx0);
                    MacrosHelpers.TwoTwoDiff(adxt_bdy1, adxt_bdy0, adyt_bdx1, adyt_bdx0,
                                             out double at_blarge, out at_b[2], out at_b[1], out at_b[0]);
                    at_b[3] = at_blarge;
                    at_blen = 4;
                    MacrosHelpers.TwoProduct(adytail, cdx, out double adyt_cdx1, out double adyt_cdx0);
                    MacrosHelpers.TwoProduct(adxtail, cdy, out double adxt_cdy1, out double adxt_cdy0);
                    MacrosHelpers.TwoTwoDiff(adyt_cdx1, adyt_cdx0, adxt_cdy1, adxt_cdy0,
                                             out at_c[3], out at_c[2], out at_c[1], out at_c[0]);
                    at_clen = 4;
                }
            }
            double[] bt_c = new double[4];
            double[] bt_a = new double[4];
            int      bt_alen;
            int      bt_clen;

            if (bdxtail == 0.0)
            {
                if (bdytail == 0.0)
                {
                    bt_c[0] = 0.0;
                    bt_clen = 1;
                    bt_a[0] = 0.0;
                    bt_alen = 1;
                }
                else
                {
                    var negate = -bdytail;
                    MacrosHelpers.TwoProduct(negate, cdx, out bt_c[1], out bt_c[0]);
                    bt_clen = 2;
                    MacrosHelpers.TwoProduct(bdytail, adx, out bt_a[1], out bt_a[0]);
                    bt_alen = 2;
                }
            }
            else
            {
                if (bdytail == 0.0)
                {
                    MacrosHelpers.TwoProduct(bdxtail, cdy, out bt_c[1], out bt_c[0]);
                    bt_clen = 2;
                    var negate = -bdxtail;
                    MacrosHelpers.TwoProduct(negate, ady, out bt_a[1], out bt_a[0]);
                    bt_alen = 2;
                }
                else
                {
                    MacrosHelpers.TwoProduct(bdxtail, cdy, out double bdxt_cdy1, out double bdxt_cdy0);
                    MacrosHelpers.TwoProduct(bdytail, cdx, out double bdyt_cdx1, out double bdyt_cdx0);
                    MacrosHelpers.TwoTwoDiff(bdxt_cdy1, bdxt_cdy0, bdyt_cdx1, bdyt_cdx0,
                                             out bt_c[3], out bt_c[2], out bt_c[1], out bt_c[0]);
                    bt_clen = 4;
                    MacrosHelpers.TwoProduct(bdytail, adx, out double bdyt_adx1, out double bdyt_adx0);
                    MacrosHelpers.TwoProduct(bdxtail, ady, out double bdxt_ady1, out double bdxt_ady0);
                    MacrosHelpers.TwoTwoDiff(bdyt_adx1, bdyt_adx0, bdxt_ady1, bdxt_ady0,
                                             out bt_a[3], out bt_a[2], out bt_a[1], out bt_a[0]);
                    bt_alen = 4;
                }
            }
            double[] ct_a = new double[4];
            double[] ct_b = new double[4];
            int      ct_alen;
            int      ct_blen;

            if (cdxtail == 0.0)
            {
                if (cdytail == 0.0)
                {
                    ct_a[0] = 0.0;
                    ct_alen = 1;
                    ct_b[0] = 0.0;
                    ct_blen = 1;
                }
                else
                {
                    var negate = -cdytail;
                    MacrosHelpers.TwoProduct(negate, adx, out ct_a[1], out ct_a[0]);
                    ct_alen = 2;
                    MacrosHelpers.TwoProduct(cdytail, bdx, out ct_b[1], out ct_b[0]);
                    ct_blen = 2;
                }
            }
            else
            {
                if (cdytail == 0.0)
                {
                    MacrosHelpers.TwoProduct(cdxtail, ady, out ct_a[1], out ct_a[0]);
                    ct_alen = 2;
                    var negate = -cdxtail;
                    MacrosHelpers.TwoProduct(negate, bdy, out ct_b[1], out ct_b[0]);
                    ct_blen = 2;
                }
                else
                {
                    MacrosHelpers.TwoProduct(cdxtail, ady, out double cdxt_ady1, out double cdxt_ady0);
                    MacrosHelpers.TwoProduct(cdytail, adx, out double cdyt_adx1, out double cdyt_adx0);
                    MacrosHelpers.TwoTwoDiff(cdxt_ady1, cdxt_ady0, cdyt_adx1, cdyt_adx0,
                                             out ct_a[3], out ct_a[2], out ct_a[1], out ct_a[0]);
                    ct_alen = 4;
                    MacrosHelpers.TwoProduct(cdytail, bdx, out double cdyt_bdx1, out double cdyt_bdx0);
                    MacrosHelpers.TwoProduct(cdxtail, bdy, out double cdxt_bdy1, out double cdxt_bdy0);
                    MacrosHelpers.TwoTwoDiff(cdyt_bdx1, cdyt_bdx0, cdxt_bdy1, cdxt_bdy0,
                                             out ct_b[3], out ct_b[2], out ct_b[1], out ct_b[0]);
                    ct_blen = 4;
                }
            }
            double[] bct    = new double[8];
            var      bctlen = ArithmeticFunctions.FastExpansionSumZeroelim(bt_clen, bt_c, ct_blen, ct_b, bct);

            double[] u       = new double[4];
            double[] v       = new double[12];
            double[] w       = new double[16];
            var      wlength = ArithmeticFunctions.ScaleExpansionZeroelim(bctlen, bct, adz, w);

            finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, wlength, w,
                                                                     finother);
            var finswap = finnow; finnow = finother; finother = finswap;

            double[] cat    = new double[8];
            var      catlen = ArithmeticFunctions.FastExpansionSumZeroelim(ct_alen, ct_a, at_clen, at_c, cat);

            wlength   = ArithmeticFunctions.ScaleExpansionZeroelim(catlen, cat, bdz, w);
            finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, wlength, w,
                                                                     finother);
            finswap = finnow; finnow = finother; finother = finswap;
            double[] abt    = new double[8];
            var      abtlen = ArithmeticFunctions.FastExpansionSumZeroelim(at_blen, at_b, bt_alen, bt_a, abt);

            wlength   = ArithmeticFunctions.ScaleExpansionZeroelim(abtlen, abt, cdz, w);
            finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, wlength, w,
                                                                     finother);
            finswap  = finnow;
            finnow   = finother;
            finother = finswap;

            if (adztail != 0.0)
            {
                var vlength = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, adztail, v);
                finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, vlength, v,
                                                                         finother);
                finswap = finnow; finnow = finother; finother = finswap;
            }
            if (bdztail != 0.0)
            {
                var vlength = ArithmeticFunctions.ScaleExpansionZeroelim(4, ca, bdztail, v);
                finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, vlength, v,
                                                                         finother);
                finswap = finnow; finnow = finother; finother = finswap;
            }
            if (cdztail != 0.0)
            {
                var vlength = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cdztail, v);
                finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, vlength, v,
                                                                         finother);
                finswap = finnow; finnow = finother; finother = finswap;
            }

            if (adxtail != 0.0)
            {
                if (bdytail != 0.0)
                {
                    MacrosHelpers.TwoProduct(adxtail, bdytail, out double adxt_bdyt1, out double adxt_bdyt0);
                    MacrosHelpers.TwoOneProduct(adxt_bdyt1, adxt_bdyt0, cdz, out u[3], out u[2], out u[1], out u[0]);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother);
                    finswap   = finnow;
                    finnow    = finother;
                    finother  = finswap;
                    if (cdztail != 0.0)
                    {
                        MacrosHelpers.TwoOneProduct(adxt_bdyt1, adxt_bdyt0, cdztail, out u[3], out u[2], out u[1], out u[0]);
                        finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother);
                        finswap   = finnow;
                        finnow    = finother;
                        finother  = finswap;
                    }
                }
                if (cdytail != 0.0)
                {
                    var negate = -adxtail;
                    MacrosHelpers.TwoProduct(negate, cdytail, out double adxt_cdyt1, out double adxt_cdyt0);
                    MacrosHelpers.TwoOneProduct(adxt_cdyt1, adxt_cdyt0, bdz, out u[3], out u[2], out u[1], out u[0]);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother);
                    finswap   = finnow;
                    finnow    = finother;
                    finother  = finswap;
                    if (bdztail != 0.0)
                    {
                        MacrosHelpers.TwoOneProduct(adxt_cdyt1, adxt_cdyt0, bdztail, out u[3], out u[2], out u[1], out u[0]);
                        finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother);
                        finswap   = finnow; finnow = finother; finother = finswap;
                    }
                }
            }
            if (bdxtail != 0.0)
            {
                if (cdytail != 0.0)
                {
                    MacrosHelpers.TwoProduct(bdxtail, cdytail, out double bdxt_cdyt1, out double bdxt_cdyt0);
                    MacrosHelpers.TwoOneProduct(bdxt_cdyt1, bdxt_cdyt0, adz, out u[3], out u[2], out u[1], out u[0]);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u,
                                                                             finother);
                    finswap = finnow; finnow = finother; finother = finswap;
                    if (adztail != 0.0)
                    {
                        MacrosHelpers.TwoOneProduct(bdxt_cdyt1, bdxt_cdyt0, adztail, out u[3], out u[2], out u[1], out u[0]);
                        finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u,
                                                                                 finother);
                        finswap = finnow; finnow = finother; finother = finswap;
                    }
                }
                if (adytail != 0.0)
                {
                    var negate = -bdxtail;
                    MacrosHelpers.TwoProduct(negate, adytail, out double bdxt_adyt1, out double bdxt_adyt0);
                    MacrosHelpers.TwoOneProduct(bdxt_adyt1, bdxt_adyt0, cdz, out u[3], out u[2], out u[1], out u[0]);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u,
                                                                             finother);
                    finswap = finnow; finnow = finother; finother = finswap;
                    if (cdztail != 0.0)
                    {
                        MacrosHelpers.TwoOneProduct(bdxt_adyt1, bdxt_adyt0, cdztail, out u[3], out u[2], out u[1], out u[0]);
                        finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u,
                                                                                 finother);
                        finswap = finnow; finnow = finother; finother = finswap;
                    }
                }
            }
            if (cdxtail != 0.0)
            {
                if (adytail != 0.0)
                {
                    MacrosHelpers.TwoProduct(cdxtail, adytail, out double cdxt_adyt1, out double cdxt_adyt0);
                    MacrosHelpers.TwoOneProduct(cdxt_adyt1, cdxt_adyt0, bdz, out u[3], out u[2], out u[1], out u[0]);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u,
                                                                             finother);
                    finswap = finnow; finnow = finother; finother = finswap;
                    if (bdztail != 0.0)
                    {
                        MacrosHelpers.TwoOneProduct(cdxt_adyt1, cdxt_adyt0, bdztail, out u[3], out u[2], out u[1], out u[0]);
                        finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u,
                                                                                 finother);
                        finswap = finnow; finnow = finother; finother = finswap;
                    }
                }
                if (bdytail != 0.0)
                {
                    var negate = -cdxtail;
                    MacrosHelpers.TwoProduct(negate, bdytail, out double cdxt_bdyt1, out double cdxt_bdyt0);
                    MacrosHelpers.TwoOneProduct(cdxt_bdyt1, cdxt_bdyt0, adz, out u[3], out u[2], out u[1], out u[0]);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u,
                                                                             finother);
                    finswap = finnow; finnow = finother; finother = finswap;
                    if (adztail != 0.0)
                    {
                        MacrosHelpers.TwoOneProduct(cdxt_bdyt1, cdxt_bdyt0, adztail, out u[3], out u[2], out u[1], out u[0]);
                        finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u,
                                                                                 finother);
                        finswap = finnow; finnow = finother; finother = finswap;
                    }
                }
            }

            if (adztail != 0.0)
            {
                wlength   = ArithmeticFunctions.ScaleExpansionZeroelim(bctlen, bct, adztail, w);
                finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, wlength, w,
                                                                         finother);
                finswap = finnow; finnow = finother; finother = finswap;
            }
            if (bdztail != 0.0)
            {
                wlength   = ArithmeticFunctions.ScaleExpansionZeroelim(catlen, cat, bdztail, w);
                finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, wlength, w,
                                                                         finother);
                finswap = finnow; finnow = finother; finother = finswap;
            }
            if (cdztail != 0.0)
            {
                wlength   = ArithmeticFunctions.ScaleExpansionZeroelim(abtlen, abt, cdztail, w);
                finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, wlength, w,
                                                                         finother);
                finswap = finnow; finnow = finother; finother = finswap;
            }

            return(finnow[finlength - 1]);
        }
コード例 #6
0
ファイル: InCircle.cs プロジェクト: modios/robust-predicates
        internal static double Exact(double[] pa, double[] pb, double[] pc, double[] pd)
        {
            MacrosHelpers.TwoProduct(pa[0], pb[1], out double axby1, out double axby0);
            MacrosHelpers.TwoProduct(pb[0], pa[1], out double bxay1, out double bxay0);

            var ab = new double[4];

            MacrosHelpers.TwoTwoDiff(axby1, axby0, bxay1, bxay0, out ab[3], out ab[2], out ab[1], out ab[0]);

            var bc = new double[4];

            MacrosHelpers.TwoProduct(pb[0], pc[1], out double bxcy1, out double bxcy0);
            MacrosHelpers.TwoProduct(pc[0], pb[1], out double cxby1, out double cxby0);
            MacrosHelpers.TwoTwoDiff(bxcy1, bxcy0, cxby1, cxby0, out bc[3], out bc[2], out bc[1], out bc[0]);

            var cd = new double[4];

            MacrosHelpers.TwoProduct(pc[0], pd[1], out double cxdy1, out double cxdy0);
            MacrosHelpers.TwoProduct(pd[0], pc[1], out double dxcy1, out double dxcy0);
            MacrosHelpers.TwoTwoDiff(cxdy1, cxdy0, dxcy1, dxcy0, out cd[3], out cd[2], out cd[1], out cd[0]);

            var da = new double[4];

            MacrosHelpers.TwoProduct(pd[0], pa[1], out double dxay1, out double dxay0);
            MacrosHelpers.TwoProduct(pa[0], pd[1], out double axdy1, out double axdy0);
            MacrosHelpers.TwoTwoDiff(dxay1, dxay0, axdy1, axdy0, out da[3], out da[2], out da[1], out da[0]);

            var ac = new double[4];

            MacrosHelpers.TwoProduct(pa[0], pc[1], out double axcy1, out double axcy0);
            MacrosHelpers.TwoProduct(pc[0], pa[1], out double cxay1, out double cxay0);
            MacrosHelpers.TwoTwoDiff(axcy1, axcy0, cxay1, cxay0, out ac[3], out ac[2], out ac[1], out ac[0]);

            var bd = new double[4];

            MacrosHelpers.TwoProduct(pb[0], pd[1], out double bxdy1, out double bxdy0);
            MacrosHelpers.TwoProduct(pd[0], pb[1], out double dxby1, out double dxby0);
            MacrosHelpers.TwoTwoDiff(bxdy1, bxdy0, dxby1, dxby0, out bd[3], out bd[2], out bd[1], out bd[0]);

            var temp8   = new double[8];
            var templen = ArithmeticFunctions.FastExpansionSumZeroelim(4, cd, 4, da, temp8);
            var cda     = new double[12];
            var cdalen  = ArithmeticFunctions.FastExpansionSumZeroelim(templen, temp8, 4, ac, cda);
            var dab     = new double[12];

            templen = ArithmeticFunctions.FastExpansionSumZeroelim(4, da, 4, ab, temp8);
            var dablen = ArithmeticFunctions.FastExpansionSumZeroelim(templen, temp8, 4, bd, dab);

            for (int i = 0; i < 4; i++)
            {
                bd[i] = -bd[i];
                ac[i] = -ac[i];
            }

            var abc = new double[12];

            templen = ArithmeticFunctions.FastExpansionSumZeroelim(4, ab, 4, bc, temp8);
            var abclen = ArithmeticFunctions.FastExpansionSumZeroelim(templen, temp8, 4, ac, abc);

            templen = ArithmeticFunctions.FastExpansionSumZeroelim(4, bc, 4, cd, temp8);

            var bcd    = new double[12];
            var bcdlen = ArithmeticFunctions.FastExpansionSumZeroelim(templen, temp8, 4, bd, bcd);

            var det24x = new double[24];
            var xlen   = ArithmeticFunctions.ScaleExpansionZeroelim(bcdlen, bcd, pa[0], det24x);

            double[] det48x = new double[48];
            xlen = ArithmeticFunctions.ScaleExpansionZeroelim(xlen, det24x, pa[0], det48x);
            double[] det24y = new double[24];
            var      ylen   = ArithmeticFunctions.ScaleExpansionZeroelim(bcdlen, bcd, pa[1], det24y);

            double[] det48y = new double[48];
            ylen = ArithmeticFunctions.ScaleExpansionZeroelim(ylen, det24y, pa[1], det48y);
            double[] adet = new double[96];
            var      alen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, det48x, ylen, det48y, adet);

            xlen = ArithmeticFunctions.ScaleExpansionZeroelim(cdalen, cda, pb[0], det24x);
            xlen = ArithmeticFunctions.ScaleExpansionZeroelim(xlen, det24x, -pb[0], det48x);
            ylen = ArithmeticFunctions.ScaleExpansionZeroelim(cdalen, cda, pb[1], det24y);
            ylen = ArithmeticFunctions.ScaleExpansionZeroelim(ylen, det24y, -pb[1], det48y);
            double[] bdet = new double[96];
            var      blen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, det48x, ylen, det48y, bdet);

            xlen = ArithmeticFunctions.ScaleExpansionZeroelim(dablen, dab, pc[0], det24x);
            xlen = ArithmeticFunctions.ScaleExpansionZeroelim(xlen, det24x, pc[0], det48x);
            ylen = ArithmeticFunctions.ScaleExpansionZeroelim(dablen, dab, pc[1], det24y);
            ylen = ArithmeticFunctions.ScaleExpansionZeroelim(ylen, det24y, pc[1], det48y);
            var cdet = new double[96];
            var clen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, det48x, ylen, det48y, cdet);

            xlen = ArithmeticFunctions.ScaleExpansionZeroelim(abclen, abc, pd[0], det24x);
            xlen = ArithmeticFunctions.ScaleExpansionZeroelim(xlen, det24x, -pd[0], det48x);
            ylen = ArithmeticFunctions.ScaleExpansionZeroelim(abclen, abc, pd[1], det24y);
            ylen = ArithmeticFunctions.ScaleExpansionZeroelim(ylen, det24y, -pd[1], det48y);
            double[] ddet = new double[96];
            var      dlen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, det48x, ylen, det48y, ddet);

            double[] abdet = new double[192];
            var      ablen = ArithmeticFunctions.FastExpansionSumZeroelim(alen, adet, blen, bdet, abdet);

            double[] cddet = new double[192];
            var      cdlen = ArithmeticFunctions.FastExpansionSumZeroelim(clen, cdet, dlen, ddet, cddet);

            double[] deter    = new double[384];
            var      deterlen = ArithmeticFunctions.FastExpansionSumZeroelim(ablen, abdet, cdlen, cddet, deter);

            return(deter[deterlen - 1]);
        }
コード例 #7
0
ファイル: InCircle.cs プロジェクト: modios/robust-predicates
        private static double Adapt(double[] pa, double[] pb, double[] pc, double[] pd, double permanent)
        {
            var adx = pa[0] - pd[0];
            var bdx = pb[0] - pd[0];
            var cdx = pc[0] - pd[0];
            var ady = pa[1] - pd[1];
            var bdy = pb[1] - pd[1];
            var cdy = pc[1] - pd[1];

            MacrosHelpers.TwoProduct(bdx, cdy, out double bdxcdy1, out double bdxcdy0);
            MacrosHelpers.TwoProduct(cdx, bdy, out double cdxbdy1, out double cdxbdy0);
            var bc = new double[4];

            MacrosHelpers.TwoTwoDiff(bdxcdy1, bdxcdy0, cdxbdy1, cdxbdy0, out bc[3], out bc[2], out bc[1], out bc[0]);

            double[] axbc    = new double[8];
            var      axbclen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, adx, axbc);

            double[] axxbc    = new double[16];
            var      axxbclen = ArithmeticFunctions.ScaleExpansionZeroelim(axbclen, axbc, adx, axxbc);

            double[] aybc    = new double[8];
            var      aybclen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, ady, aybc);

            double[] ayybc    = new double[16];
            var      ayybclen = ArithmeticFunctions.ScaleExpansionZeroelim(aybclen, aybc, ady, ayybc);

            double[] adet = new double[32];
            var      alen = ArithmeticFunctions.FastExpansionSumZeroelim(axxbclen, axxbc, ayybclen, ayybc, adet);

            MacrosHelpers.TwoProduct(cdx, ady, out double cdxady1, out double cdxady0);
            MacrosHelpers.TwoProduct(adx, cdy, out double adxcdy1, out double adxcdy0);
            var ca = new double[4];

            MacrosHelpers.TwoTwoDiff(cdxady1, cdxady0, adxcdy1, adxcdy0, out ca[3], out ca[2], out ca[1], out ca[0]);

            double[] bxca    = new double[8];
            var      bxcalen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ca, bdx, bxca);

            double[] bxxca    = new double[16];
            var      bxxcalen = ArithmeticFunctions.ScaleExpansionZeroelim(bxcalen, bxca, bdx, bxxca);

            double[] byca    = new double[8];
            var      bycalen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ca, bdy, byca);

            double[] byyca    = new double[16];
            var      byycalen = ArithmeticFunctions.ScaleExpansionZeroelim(bycalen, byca, bdy, byyca);

            double[] bdet = new double[32];
            var      blen = ArithmeticFunctions.FastExpansionSumZeroelim(bxxcalen, bxxca, byycalen, byyca, bdet);



            MacrosHelpers.TwoProduct(adx, bdy, out double adxbdy1, out double adxbdy0);
            MacrosHelpers.TwoProduct(bdx, ady, out double bdxady1, out double bdxady0);
            var ab = new double[4];

            MacrosHelpers.TwoTwoDiff(adxbdy1, adxbdy0, bdxady1, bdxady0, out ab[3], out ab[2], out ab[1], out ab[0]);

            double[] cxab    = new double[8];
            var      cxablen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cdx, cxab);

            double[] cxxab    = new double[16];
            var      cxxablen = ArithmeticFunctions.ScaleExpansionZeroelim(cxablen, cxab, cdx, cxxab);

            double[] cyab    = new double[8];
            var      cyablen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cdy, cyab);

            double[] cyyab    = new double[16];
            var      cyyablen = ArithmeticFunctions.ScaleExpansionZeroelim(cyablen, cyab, cdy, cyyab);

            double[] cdet = new double[32];
            var      clen = ArithmeticFunctions.FastExpansionSumZeroelim(cxxablen, cxxab, cyyablen, cyyab, cdet);

            double[] abdet = new double[64];
            var      ablen = ArithmeticFunctions.FastExpansionSumZeroelim(alen, adet, blen, bdet, abdet);

            double[] fin1      = new double[1152];
            var      finlength = ArithmeticFunctions.FastExpansionSumZeroelim(ablen, abdet, clen, cdet, fin1);

            var det      = ArithmeticFunctions.Estimate(finlength, fin1);
            var errbound = MacrosHelpers.IccerrboundB * permanent;

            if ((det >= errbound) || (-det >= errbound))
            {
                return(det);
            }

            MacrosHelpers.TwoDiffTail(pa[0], pd[0], adx, out double adxtail);
            MacrosHelpers.TwoDiffTail(pa[1], pd[1], ady, out double adytail);
            MacrosHelpers.TwoDiffTail(pb[0], pd[0], bdx, out double bdxtail);
            MacrosHelpers.TwoDiffTail(pb[1], pd[1], bdy, out double bdytail);
            MacrosHelpers.TwoDiffTail(pc[0], pd[0], cdx, out double cdxtail);
            MacrosHelpers.TwoDiffTail(pc[1], pd[1], cdy, out double cdytail);

            if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0) &&
                (adytail == 0.0) && (bdytail == 0.0) && (cdytail == 0.0))
            {
                return(det);
            }

            errbound = MacrosHelpers.IccerrboundC * permanent + MacrosHelpers.Resulterrbound * Math.Abs(det);
            det     += ((adx * adx + ady * ady) * ((bdx * cdytail + cdy * bdxtail)
                                                   - (bdy * cdxtail + cdx * bdytail))
                        + 2.0 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx))
                       + ((bdx * bdx + bdy * bdy) * ((cdx * adytail + ady * cdxtail)
                                                     - (cdy * adxtail + adx * cdytail))
                          + 2.0 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx))
                       + ((cdx * cdx + cdy * cdy) * ((adx * bdytail + bdy * adxtail)
                                                     - (ady * bdxtail + bdx * adytail))
                          + 2.0 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx));
            if ((det >= errbound) || (-det >= errbound))
            {
                return(det);
            }


            var finnow   = fin1;
            var fin2     = new double[1152];
            var finother = fin2;

            double[] aa = new double[4];
            double[] bb = new double[4];
            double[] cc = new double[4];

            if ((bdxtail != 0.0) || (bdytail != 0.0) ||
                (cdxtail != 0.0) || (cdytail != 0.0))
            {
                MacrosHelpers.Square(adx, out double adxadx1, out double adxadx0);
                MacrosHelpers.Square(ady, out double adyady1, out double adyady0);
                MacrosHelpers.TwoTwoSum(adxadx1, adxadx0, adyady1, adyady0, out aa[3], out aa[2], out aa[1], out aa[0]);
            }
            if ((cdxtail != 0.0) || (cdytail != 0.0) ||
                (adxtail != 0.0) || (adytail != 0.0))
            {
                MacrosHelpers.Square(bdx, out double bdxbdx1, out double bdxbdx0);
                MacrosHelpers.Square(bdy, out double bdybdy1, out double bdybdy0);
                MacrosHelpers.TwoTwoSum(bdxbdx1, bdxbdx0, bdybdy1, bdybdy0, out bb[3], out bb[2], out bb[1], out bb[0]);
            }
            if ((adxtail != 0.0) || (adytail != 0.0) ||
                (bdxtail != 0.0) || (bdytail != 0.0))
            {
                MacrosHelpers.Square(cdx, out double cdxcdx1, out double cdxcdx0);
                MacrosHelpers.Square(cdy, out double cdycdy1, out double cdycdy0);
                MacrosHelpers.TwoTwoSum(cdxcdx1, cdxcdx0, cdycdy1, cdycdy0, out cc[3], out cc[2], out cc[1], out cc[0]);
            }


            double[] finswap;
            double[] temp16a  = new double[16];
            double[] temp32a  = new double[32];
            double[] temp16b  = new double[16];
            double[] temp32b  = new double[32];
            double[] temp16c  = new double[16];
            double[] temp48   = new double[48];
            double[] axtbc    = new double[8];
            int      axtbclen = 0;

            if (adxtail != 0.0)
            {
                axtbclen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, adxtail, axtbc);
                var      temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbclen, axtbc, 2.0 * adx, temp16a);
                double[] axtcc      = new double[8];
                var      axtcclen   = ArithmeticFunctions.ScaleExpansionZeroelim(4, cc, adxtail, axtcc);
                var      temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(axtcclen, axtcc, bdy, temp16b);
                double[] axtbb      = new double[8];
                var      axtbblen   = ArithmeticFunctions.ScaleExpansionZeroelim(4, bb, adxtail, axtbb);
                var      temp16clen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbblen, axtbb, -cdy, temp16c);

                var temp32alen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                              temp16blen, temp16b, temp32a);

                var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16clen, temp16c,
                                                                             temp32alen, temp32a, temp48);
                finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len,
                                                                         temp48, finother);
                finswap  = finnow;
                finnow   = finother;
                finother = finswap;
            }

            int aytbclen = 0;

            double[] aytbc = new double[8];
            if (adytail != 0.0)
            {
                aytbclen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, adytail, aytbc);
                var      temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbclen, aytbc, 2.0 * ady, temp16a);
                double[] aytbb      = new double[8];
                var      aytbblen   = ArithmeticFunctions.ScaleExpansionZeroelim(4, bb, adytail, aytbb);
                var      temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbblen, aytbb, cdx, temp16b);
                double[] aytcc      = new double[8];
                var      aytcclen   = ArithmeticFunctions.ScaleExpansionZeroelim(4, cc, adytail, aytcc);
                var      temp16clen = ArithmeticFunctions.ScaleExpansionZeroelim(aytcclen, aytcc, -bdx, temp16c);
                var      temp32alen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                   temp16blen, temp16b, temp32a);
                var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16clen, temp16c,
                                                                             temp32alen, temp32a, temp48);
                finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len,
                                                                         temp48, finother);
                finswap  = finnow;
                finnow   = finother;
                finother = finswap;
            }

            int bxtcalen = 0;

            double[] bxtca = new double[8];
            if (bdxtail != 0.0)
            {
                bxtcalen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ca, bdxtail, bxtca);
                var      temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcalen, bxtca, 2.0 * bdx, temp16a);
                double[] bxtaa      = new double[8];
                var      bxtaalen   = ArithmeticFunctions.ScaleExpansionZeroelim(4, aa, bdxtail, bxtaa);
                var      temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtaalen, bxtaa, cdy, temp16b);
                double[] bxtcc      = new double[8];
                var      bxtcclen   = ArithmeticFunctions.ScaleExpansionZeroelim(4, cc, bdxtail, bxtcc);
                var      temp16clen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcclen, bxtcc, -ady, temp16c);
                var      temp32alen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                   temp16blen, temp16b, temp32a);
                var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16clen, temp16c,
                                                                             temp32alen, temp32a, temp48);
                finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len,
                                                                         temp48, finother);
                finswap  = finnow;
                finnow   = finother;
                finother = finswap;
            }

            int bytcalen = 0;

            double[] bytca = new double[8];
            if (bdytail != 0.0)
            {
                bytcalen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ca, bdytail, bytca);
                var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcalen, bytca, 2.0 * bdy,
                                                                            temp16a);

                double[] bytcc      = new double[8];
                var      bytcclen   = ArithmeticFunctions.ScaleExpansionZeroelim(4, cc, bdytail, bytcc);
                var      temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcclen, bytcc, adx, temp16b);

                double[] bytaa      = new double[8];
                var      bytaalen   = ArithmeticFunctions.ScaleExpansionZeroelim(4, aa, bdytail, bytaa);
                var      temp16clen = ArithmeticFunctions.ScaleExpansionZeroelim(bytaalen, bytaa, -cdx, temp16c);
                var      temp32alen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                   temp16blen, temp16b, temp32a);
                var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16clen, temp16c,
                                                                             temp32alen, temp32a, temp48);
                finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len,
                                                                         temp48, finother);
                finswap  = finnow;
                finnow   = finother;
                finother = finswap;
            }

            int cxtablen = 0;

            double[] cxtab = new double[8];
            if (cdxtail != 0.0)
            {
                cxtablen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cdxtail, cxtab);
                var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtablen, cxtab, 2.0 * cdx,
                                                                            temp16a);
                double[] cxtbb      = new double[8];
                var      cxtbblen   = ArithmeticFunctions.ScaleExpansionZeroelim(4, bb, cdxtail, cxtbb);
                var      temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtbblen, cxtbb, ady, temp16b);
                double[] cxtaa      = new double[8];
                var      cxtaalen   = ArithmeticFunctions.ScaleExpansionZeroelim(4, aa, cdxtail, cxtaa);
                var      temp16clen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtaalen, cxtaa, -bdy, temp16c);

                var temp32alen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                              temp16blen, temp16b, temp32a);
                var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16clen, temp16c,
                                                                             temp32alen, temp32a, temp48);
                finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len,
                                                                         temp48, finother);
                finswap  = finnow;
                finnow   = finother;
                finother = finswap;
            }

            int cytablen = 0;

            double[] cytab = new double[8];
            if (cdytail != 0.0)
            {
                cytablen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cdytail, cytab);
                var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(cytablen, cytab, 2.0 * cdy,
                                                                            temp16a);

                double[] cytaa      = new double[8];
                var      cytaalen   = ArithmeticFunctions.ScaleExpansionZeroelim(4, aa, cdytail, cytaa);
                var      temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(cytaalen, cytaa, bdx, temp16b);

                double[] cytbb      = new double[8];
                var      cytbblen   = ArithmeticFunctions.ScaleExpansionZeroelim(4, bb, cdytail, cytbb);
                var      temp16clen = ArithmeticFunctions.ScaleExpansionZeroelim(cytbblen, cytbb, -adx, temp16c);

                var temp32alen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                              temp16blen, temp16b, temp32a);
                var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16clen, temp16c,
                                                                             temp32alen, temp32a, temp48);
                finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len,
                                                                         temp48, finother);
                finswap  = finnow;
                finnow   = finother;
                finother = finswap;
            }

            int bcttlen;

            double[] bct = new double[8];
            int      bctlen;
            var      bctt = new double[4];

            double[] temp64 = new double[64];
            double[] u      = new double[5];
            double[] v      = new double[5];
            if ((adxtail != 0.0) || (adytail != 0.0))
            {
                if ((bdxtail != 0.0) || (bdytail != 0.0) ||
                    (cdxtail != 0.0) || (cdytail != 0.0))
                {
                    MacrosHelpers.TwoProduct(bdxtail, cdy, out double ti1, out double ti0);
                    MacrosHelpers.TwoProduct(bdx, cdytail, out double tj1, out double tj0);
                    MacrosHelpers.TwoTwoSum(ti1, ti0, tj1, tj0, out u[3], out u[2], out u[1], out u[0]);
                    var negate = -bdy;
                    MacrosHelpers.TwoProduct(cdxtail, negate, out ti1, out ti0);
                    negate = -bdytail;
                    MacrosHelpers.TwoProduct(cdx, negate, out tj1, out tj0);

                    MacrosHelpers.TwoTwoSum(ti1, ti0, tj1, tj0, out v[3], out v[2], out v[1], out v[0]);
                    bctlen = ArithmeticFunctions.FastExpansionSumZeroelim(4, u, 4, v, bct);

                    MacrosHelpers.TwoProduct(bdxtail, cdytail, out ti1, out ti0);
                    MacrosHelpers.TwoProduct(cdxtail, bdytail, out tj1, out tj0);
                    MacrosHelpers.TwoTwoDiff(ti1, ti0, tj1, tj0, out bctt[3], out bctt[2], out bctt[1], out bctt[0]);
                    bcttlen = 4;
                }
                else
                {
                    bct[0]  = 0.0;
                    bctlen  = 1;
                    bctt[0] = 0.0;
                    bcttlen = 1;
                }

                double[] temp8 = new double[8];
                if (adxtail != 0.0)
                {
                    var      temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbclen, axtbc, adxtail, temp16a);
                    double[] axtbct     = new double[16];
                    var      axtbctlen  = ArithmeticFunctions.ScaleExpansionZeroelim(bctlen, bct, adxtail, axtbct);
                    var      temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbctlen, axtbct, 2.0 * adx,
                                                                                     temp32a);
                    var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                 temp32alen, temp32a, temp48);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len,
                                                                             temp48, finother);
                    finswap  = finnow;
                    finnow   = finother;
                    finother = finswap;
                    if (bdytail != 0.0)
                    {
                        var temp8len = ArithmeticFunctions.ScaleExpansionZeroelim(4, cc, adxtail, temp8);
                        temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(temp8len, temp8, bdytail,
                                                                                temp16a);
                        finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp16alen,
                                                                                 temp16a, finother);
                        finswap  = finnow;
                        finnow   = finother;
                        finother = finswap;
                    }
                    if (cdytail != 0.0)
                    {
                        var temp8len = ArithmeticFunctions.ScaleExpansionZeroelim(4, bb, -adxtail, temp8);
                        temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(temp8len, temp8, cdytail,
                                                                                temp16a);
                        finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp16alen,
                                                                                 temp16a, finother);
                        finswap  = finnow;
                        finnow   = finother;
                        finother = finswap;
                    }

                    temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbctlen, axtbct, adxtail,
                                                                            temp32a);
                    double[] axtbctt    = new double[8];
                    var      axtbcttlen = ArithmeticFunctions.ScaleExpansionZeroelim(bcttlen, bctt, adxtail, axtbctt);
                    temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbcttlen, axtbctt, 2.0 * adx,
                                                                            temp16a);
                    var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbcttlen, axtbctt, adxtail,
                                                                                temp16b);
                    var temp32blen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                  temp16blen, temp16b, temp32b);
                    var temp64len = ArithmeticFunctions.FastExpansionSumZeroelim(temp32alen, temp32a,
                                                                                 temp32blen, temp32b, temp64);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp64len,
                                                                             temp64, finother);
                    finswap  = finnow;
                    finnow   = finother;
                    finother = finswap;
                }
                if (adytail != 0.0)
                {
                    double[] aytbct     = new double[16];
                    var      temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbclen, aytbc, adytail, temp16a);
                    var      aytbctlen  = ArithmeticFunctions.ScaleExpansionZeroelim(bctlen, bct, adytail, aytbct);
                    var      temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbctlen, aytbct, 2.0 * ady,
                                                                                     temp32a);
                    var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                 temp32alen, temp32a, temp48);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len,
                                                                             temp48, finother);

                    finswap  = finnow;
                    finnow   = finother;
                    finother = finswap;

                    temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbctlen, aytbct, adytail,
                                                                            temp32a);
                    double[] aytbctt    = new double[16];
                    var      aytbcttlen = ArithmeticFunctions.ScaleExpansionZeroelim(bcttlen, bctt, adytail, aytbctt);
                    temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbcttlen, aytbctt, 2.0 * ady,
                                                                            temp16a);
                    var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbcttlen, aytbctt, adytail,
                                                                                temp16b);
                    var temp32blen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                  temp16blen, temp16b, temp32b);
                    var temp64len = ArithmeticFunctions.FastExpansionSumZeroelim(temp32alen, temp32a,
                                                                                 temp32blen, temp32b, temp64);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp64len,
                                                                             temp64, finother);
                    finswap  = finnow;
                    finnow   = finother;
                    finother = finswap;
                }
            }
            double[] cat  = new double[8];
            double[] catt = new double[4];
            if ((bdxtail != 0.0) || (bdytail != 0.0))
            {
                int cattlen;
                int catlen;
                if ((cdxtail != 0.0) || (cdytail != 0.0) ||
                    (adxtail != 0.0) || (adytail != 0.0))
                {
                    MacrosHelpers.TwoProduct(cdxtail, ady, out double ti1, out double ti0);
                    MacrosHelpers.TwoProduct(cdx, adytail, out double tj1, out double tj0);

                    MacrosHelpers.TwoTwoSum(ti1, ti0, tj1, tj0, out u[3], out u[2], out u[1], out u[0]);

                    var negate = -cdy;
                    MacrosHelpers.TwoProduct(adxtail, negate, out ti1, out ti0);
                    negate = -cdytail;
                    MacrosHelpers.TwoProduct(adx, negate, out tj1, out tj0);
                    MacrosHelpers.TwoTwoSum(ti1, ti0, tj1, tj0, out v[3], out v[2], out v[1], out v[0]);

                    catlen = ArithmeticFunctions.FastExpansionSumZeroelim(4, u, 4, v, cat);

                    MacrosHelpers.TwoProduct(cdxtail, adytail, out ti1, out ti0);
                    MacrosHelpers.TwoProduct(adxtail, cdytail, out tj1, out tj0);
                    MacrosHelpers.TwoTwoDiff(ti1, ti0, tj1, tj0, out catt[3], out catt[2], out catt[1], out catt[0]);
                    cattlen = 4;
                }
                else
                {
                    cat[0]  = 0.0;
                    catlen  = 1;
                    catt[0] = 0.0;
                    cattlen = 1;
                }

                double[] temp8   = new double[8];
                double[] bxtcat  = new double[16];
                double[] bxtcatt = new double[8];
                if (bdxtail != 0.0)
                {
                    var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcalen, bxtca, bdxtail, temp16a);
                    var bxtcatlen  = ArithmeticFunctions.ScaleExpansionZeroelim(catlen, cat, bdxtail, bxtcat);
                    var temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcatlen, bxtcat, 2.0 * bdx,
                                                                                temp32a);
                    var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                 temp32alen, temp32a, temp48);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len,
                                                                             temp48, finother);
                    finswap  = finnow;
                    finnow   = finother;
                    finother = finswap;
                    if (cdytail != 0.0)
                    {
                        var temp8len = ArithmeticFunctions.ScaleExpansionZeroelim(4, aa, bdxtail, temp8);
                        temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(temp8len, temp8, cdytail,
                                                                                temp16a);
                        finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp16alen,
                                                                                 temp16a, finother);
                        finswap  = finnow;
                        finnow   = finother;
                        finother = finswap;
                    }
                    if (adytail != 0.0)
                    {
                        var temp8len = ArithmeticFunctions.ScaleExpansionZeroelim(4, cc, -bdxtail, temp8);
                        temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(temp8len, temp8, adytail,
                                                                                temp16a);
                        finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp16alen,
                                                                                 temp16a, finother);
                        finswap  = finnow;
                        finnow   = finother;
                        finother = finswap;
                    }

                    temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcatlen, bxtcat, bdxtail,
                                                                            temp32a);
                    var bxtcattlen = ArithmeticFunctions.ScaleExpansionZeroelim(cattlen, catt, bdxtail, bxtcatt);
                    temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcattlen, bxtcatt, 2.0 * bdx,
                                                                            temp16a);
                    var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcattlen, bxtcatt, bdxtail,
                                                                                temp16b);
                    var temp32blen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                  temp16blen, temp16b, temp32b);
                    var temp64len = ArithmeticFunctions.FastExpansionSumZeroelim(temp32alen, temp32a,
                                                                                 temp32blen, temp32b, temp64);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp64len,
                                                                             temp64, finother);
                    finswap  = finnow;
                    finnow   = finother;
                    finother = finswap;
                }
                double[] bytcat  = new double[16];
                double[] bytcatt = new double[8];
                if (bdytail != 0.0)
                {
                    var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcalen, bytca, bdytail, temp16a);
                    var bytcatlen  = ArithmeticFunctions.ScaleExpansionZeroelim(catlen, cat, bdytail, bytcat);
                    var temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcatlen, bytcat, 2.0 * bdy,
                                                                                temp32a);
                    var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                 temp32alen, temp32a, temp48);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len,
                                                                             temp48, finother);
                    finswap  = finnow;
                    finnow   = finother;
                    finother = finswap;


                    temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcatlen, bytcat, bdytail,
                                                                            temp32a);
                    var bytcattlen = ArithmeticFunctions.ScaleExpansionZeroelim(cattlen, catt, bdytail, bytcatt);
                    temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcattlen, bytcatt, 2.0 * bdy,
                                                                            temp16a);
                    var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcattlen, bytcatt, bdytail,
                                                                                temp16b);
                    var temp32blen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                  temp16blen, temp16b, temp32b);
                    var temp64len = ArithmeticFunctions.FastExpansionSumZeroelim(temp32alen, temp32a,
                                                                                 temp32blen, temp32b, temp64);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp64len,
                                                                             temp64, finother);
                    finswap  = finnow;
                    finnow   = finother;
                    finother = finswap;
                }
            }
            double[] abt  = new double[8];
            double[] abtt = new double[4];
            if ((cdxtail != 0.0) || (cdytail != 0.0))
            {
                int abtlen;
                int abttlen;
                if ((adxtail != 0.0) || (adytail != 0.0) ||
                    (bdxtail != 0.0) || (bdytail != 0.0))
                {
                    MacrosHelpers.TwoProduct(adxtail, bdy, out double ti1, out double ti0);
                    MacrosHelpers.TwoProduct(adx, bdytail, out double tj1, out double tj0);
                    MacrosHelpers.TwoTwoSum(ti1, ti0, tj1, tj0, out u[3], out u[2], out u[1], out u[0]);
                    var negate = -ady;
                    MacrosHelpers.TwoProduct(bdxtail, negate, out ti1, out ti0);
                    negate = -adytail;
                    MacrosHelpers.TwoProduct(bdx, negate, out tj1, out tj0);
                    MacrosHelpers.TwoTwoSum(ti1, ti0, tj1, tj0, out v[3], out v[2], out v[1], out v[0]);
                    abtlen = ArithmeticFunctions.FastExpansionSumZeroelim(4, u, 4, v, abt);

                    MacrosHelpers.TwoProduct(adxtail, bdytail, out ti1, out ti0);
                    MacrosHelpers.TwoProduct(bdxtail, adytail, out tj1, out tj0);
                    MacrosHelpers.TwoTwoDiff(ti1, ti0, tj1, tj0, out abtt[3], out abtt[2], out abtt[1], out abtt[0]);
                    abttlen = 4;
                }
                else
                {
                    abt[0]  = 0.0;
                    abtlen  = 1;
                    abtt[0] = 0.0;
                    abttlen = 1;
                }

                double[] temp8   = new double[8];
                double[] cxtabt  = new double[16];
                double[] cxtabtt = new double[8];
                if (cdxtail != 0.0)
                {
                    var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtablen, cxtab, cdxtail, temp16a);
                    var cxtabtlen  = ArithmeticFunctions.ScaleExpansionZeroelim(abtlen, abt, cdxtail, cxtabt);
                    var temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtabtlen, cxtabt, 2.0 * cdx,
                                                                                temp32a);
                    var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                 temp32alen, temp32a, temp48);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len,
                                                                             temp48, finother);
                    finswap  = finnow;
                    finnow   = finother;
                    finother = finswap;

                    if (adytail != 0.0)
                    {
                        var temp8len = ArithmeticFunctions.ScaleExpansionZeroelim(4, bb, cdxtail, temp8);
                        temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(temp8len, temp8, adytail,
                                                                                temp16a);
                        finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp16alen,
                                                                                 temp16a, finother);
                        finswap  = finnow;
                        finnow   = finother;
                        finother = finswap;
                    }
                    if (bdytail != 0.0)
                    {
                        var temp8len = ArithmeticFunctions.ScaleExpansionZeroelim(4, aa, -cdxtail, temp8);
                        temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(temp8len, temp8, bdytail,
                                                                                temp16a);
                        finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp16alen,
                                                                                 temp16a, finother);
                        finswap  = finnow;
                        finnow   = finother;
                        finother = finswap;
                    }

                    temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtabtlen, cxtabt, cdxtail,
                                                                            temp32a);
                    var cxtabttlen = ArithmeticFunctions.ScaleExpansionZeroelim(abttlen, abtt, cdxtail, cxtabtt);
                    temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtabttlen, cxtabtt, 2.0 * cdx,
                                                                            temp16a);
                    var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtabttlen, cxtabtt, cdxtail,
                                                                                temp16b);
                    var temp32blen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                  temp16blen, temp16b, temp32b);
                    var temp64len = ArithmeticFunctions.FastExpansionSumZeroelim(temp32alen, temp32a,
                                                                                 temp32blen, temp32b, temp64);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp64len,
                                                                             temp64, finother);
                    finswap  = finnow;
                    finnow   = finother;
                    finother = finswap;
                }

                double[] cytabt  = new double[16];
                double[] cytabtt = new double[8];
                if (cdytail != 0.0)
                {
                    var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(cytablen, cytab, cdytail, temp16a);
                    var cytabtlen  = ArithmeticFunctions.ScaleExpansionZeroelim(abtlen, abt, cdytail, cytabt);
                    var temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(cytabtlen, cytabt, 2.0 * cdy,
                                                                                temp32a);
                    var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                 temp32alen, temp32a, temp48);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len,
                                                                             temp48, finother);
                    finswap = finnow; finnow = finother; finother = finswap;


                    temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(cytabtlen, cytabt, cdytail,
                                                                            temp32a);
                    var cytabttlen = ArithmeticFunctions.ScaleExpansionZeroelim(abttlen, abtt, cdytail, cytabtt);
                    temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(cytabttlen, cytabtt, 2.0 * cdy,
                                                                            temp16a);
                    var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(cytabttlen, cytabtt, cdytail,
                                                                                temp16b);
                    var temp32blen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a,
                                                                                  temp16blen, temp16b, temp32b);
                    var temp64len = ArithmeticFunctions.FastExpansionSumZeroelim(temp32alen, temp32a,
                                                                                 temp32blen, temp32b, temp64);
                    finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp64len,
                                                                             temp64, finother);
                    finswap  = finnow;
                    finnow   = finother;
                    finother = finswap;
                }
            }

            return(finnow[finlength - 1]);
        }
コード例 #8
0
        private static double Adapt(double[] pa, double[] pb, double[] pc, double detsum)
        {
            double acx = pa[0] - pc[0];
            double bcx = pb[0] - pc[0];
            double acy = pa[1] - pc[1];
            double bcy = pb[1] - pc[1];

            MacrosHelpers.TwoProduct(acx, bcy, out double detleft, out double detlefttail);
            MacrosHelpers.TwoProduct(acy, bcx, out double detright, out double detrighttail);
            double[] B = new double[4];
            MacrosHelpers.TwoTwoDiff(detleft, detlefttail, detright, detrighttail, out B[3], out B[2], out B[1], out B[0]);

            double det      = ArithmeticFunctions.Estimate(4, B);
            double errbound = MacrosHelpers.CcwerrboundB * detsum;

            if ((det >= errbound) || (-det >= errbound))
            {
                return(det);
            }

            MacrosHelpers.TwoDiffTail(pa[0], pc[0], acx, out double acxtail);
            MacrosHelpers.TwoDiffTail(pb[0], pc[0], bcx, out double bcxtail);
            MacrosHelpers.TwoDiffTail(pa[1], pc[1], acy, out double acytail);
            MacrosHelpers.TwoDiffTail(pb[1], pc[1], bcy, out double bcytail);

            if ((acxtail == 0.0) && (acytail == 0.0) &&
                (bcxtail == 0.0) && (bcytail == 0.0))
            {
                return(det);
            }

            errbound = MacrosHelpers.CcwerrboundC * detsum + MacrosHelpers.Resulterrbound * Math.Abs(det);
            det     += (acx * bcytail + bcy * acxtail)
                       - (acy * bcxtail + bcx * acytail);
            if ((det >= errbound) || (-det >= errbound))
            {
                return(det);
            }

            double[] u = new double[4];
            MacrosHelpers.TwoProduct(acxtail, bcy, out double s1, out double s0);
            MacrosHelpers.TwoProduct(acytail, bcx, out double t1, out double t0);
            MacrosHelpers.TwoTwoDiff(s1, s0, t1, t0, out u[3], out u[2], out u[1], out u[0]);

            double[] C1       = new double[8];
            int      C1length = ArithmeticFunctions.FastExpansionSumZeroelim(4, B, 4, u, C1);

            MacrosHelpers.TwoProduct(acx, bcytail, out s1, out s0);
            MacrosHelpers.TwoProduct(acy, bcxtail, out t1, out t0);
            MacrosHelpers.TwoTwoDiff(s1, s0, t1, t0, out u[3], out u[2], out u[1], out u[0]);
            double[] C2       = new double[12];
            int      C2length = ArithmeticFunctions.FastExpansionSumZeroelim(C1length, C1, 4, u, C2);

            MacrosHelpers.TwoProduct(acxtail, bcytail, out s1, out s0);
            MacrosHelpers.TwoProduct(acytail, bcxtail, out t1, out t0);
            MacrosHelpers.TwoTwoDiff(s1, s0, t1, t0, out u[3], out u[2], out u[1], out u[0]);

            double[] D       = new double[16];
            int      Dlength = ArithmeticFunctions.FastExpansionSumZeroelim(C2length, C2, 4, u, D);

            return(D[Dlength - 1]);
        }