System.Math.Abs(double)

Here are the examples of the csharp api System.Math.Abs(double) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3544 Examples 7

19 Source : ScSelectLogic.cs
with MIT License
from 0x1000000

private static async Task Arithmetic(IScenarioContext context)
        {
            var doubleResult = (double)await Select(Cast((Literal(7) + 3 - Literal(1)) * 2 / 6, SqlType.Double))
                .QueryScalar(context.Database);

            if (Math.Abs(doubleResult - 3.0) > 0)
            {
                throw new Exception("Something went wrong");
            }
        }

19 Source : bdsvd.cs
with MIT License
from 1CM69

private static bool bidiagonalsvddecompositioninternal(ref double[] d, double[] e, int n, bool isupper, bool isfractionalaccuracyrequired, ref double[,] u, int ustart, int nru, ref double[,] c, int cstart, int ncc, ref double[,] vt, int vstart, int ncvt)
  {
    int index1 = 0;
    double num1 = 0.0;
    double num2 = 0.0;
    double cs1 = 0.0;
    double sn1 = 0.0;
    double num3 = 0.0;
    double ssmin1 = 0.0;
    double ssmin2 = 0.0;
    double ssmax = 0.0;
    double num4 = 0.0;
    double num5 = 0.0;
    double sn2 = 0.0;
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    double[] numArray3 = new double[0];
    double[] numArray4 = new double[0];
    double[] numArray5 = new double[0];
    double[] numArray6 = new double[0];
    double[] numArray7 = new double[0];
    double[] numArray8 = new double[0];
    double r = 0.0;
    e = (double[]) e.Clone();
    bool flag1 = true;
    if (n == 0)
      return flag1;
    if (n == 1)
    {
      if (d[1] < 0.0)
      {
        d[1] = -d[1];
        if (ncvt > 0)
        {
          for (int index2 = vstart; index2 <= vstart + ncvt - 1; ++index2)
            vt[vstart, index2] = -1.0 * vt[vstart, index2];
        }
      }
      return flag1;
    }
    double[] c1 = new double[n - 1 + 1];
    double[] s1 = new double[n - 1 + 1];
    double[] c2 = new double[n - 1 + 1];
    double[] s2 = new double[n - 1 + 1];
    int m2 = ustart + System.Math.Max(nru - 1, 0);
    int n2_1 = vstart + System.Math.Max(ncvt - 1, 0);
    int n2_2 = cstart + System.Math.Max(ncc - 1, 0);
    double[] work1 = new double[m2 + 1];
    double[] work2 = new double[n2_1 + 1];
    double[] work3 = new double[n2_2 + 1];
    int num6 = 12;
    bool isforward = true;
    double[] numArray9 = new double[n + 1];
    for (int index2 = 1; index2 <= n - 1; ++index2)
      numArray9[index2] = e[index2];
    e = new double[n + 1];
    for (int index2 = 1; index2 <= n - 1; ++index2)
      e[index2] = numArray9[index2];
    e[n] = 0.0;
    int num7 = 0;
    double num8 = 5E-16;
    double num9 = 1E-300;
    if (!isupper)
    {
      for (int index2 = 1; index2 <= n - 1; ++index2)
      {
        rotations.generaterotation(d[index2], e[index2], ref cs1, ref sn2, ref num3);
        d[index2] = num3;
        e[index2] = sn2 * d[index2 + 1];
        d[index2 + 1] = cs1 * d[index2 + 1];
        c1[index2] = cs1;
        s1[index2] = sn2;
      }
      if (nru > 0)
        rotations.applyrotationsfromtheright(isforward, ustart, m2, 1 + ustart - 1, n + ustart - 1, ref c1, ref s1, ref u, ref work1);
      if (ncc > 0)
        rotations.applyrotationsfromtheleft(isforward, 1 + cstart - 1, n + cstart - 1, cstart, n2_2, ref c1, ref s1, ref c, ref work3);
    }
    double num10 = System.Math.Max(10.0, System.Math.Min(100.0, System.Math.Pow(num8, -0.125))) * num8;
    if (!isfractionalaccuracyrequired)
      num10 = -num10;
    double val1_1 = 0.0;
    for (int index2 = 1; index2 <= n; ++index2)
      val1_1 = System.Math.Max(val1_1, System.Math.Abs(d[index2]));
    for (int index2 = 1; index2 <= n - 1; ++index2)
      val1_1 = System.Math.Max(val1_1, System.Math.Abs(e[index2]));
    double val1_2 = 0.0;
    double num11;
    if (num10 >= 0.0)
    {
      double val1_3 = System.Math.Abs(d[1]);
      if (val1_3 != 0.0)
      {
        double val2 = val1_3;
        for (int index2 = 2; index2 <= n; ++index2)
        {
          val2 = System.Math.Abs(d[index2]) * (val2 / (val2 + System.Math.Abs(e[index2 - 1])));
          val1_3 = System.Math.Min(val1_3, val2);
          if (val1_3 == 0.0)
            break;
        }
      }
      double num12 = val1_3 / System.Math.Sqrt((double) n);
      num11 = System.Math.Max(num10 * num12, (double) (num6 * n * n) * num9);
    }
    else
      num11 = System.Math.Max(System.Math.Abs(num10) * val1_1, (double) (num6 * n * n) * num9);
    int num13 = num6 * n * n;
    int num14 = 0;
    int num15 = -1;
    int num16 = -1;
    int index3 = n;
    while (index3 > 1)
    {
      if (num14 > num13)
        return false;
      if (num10 < 0.0 & System.Math.Abs(d[index3]) <= num11)
        d[index3] = 0.0;
      double val1_3 = System.Math.Abs(d[index3]);
      double val1_4 = val1_3;
      bool flag2 = false;
      for (int index2 = 1; index2 <= index3 - 1; ++index2)
      {
        index1 = index3 - index2;
        double num12 = System.Math.Abs(d[index1]);
        double val2 = System.Math.Abs(e[index1]);
        if (num10 < 0.0 & num12 <= num11)
          d[index1] = 0.0;
        if (val2 <= num11)
        {
          flag2 = true;
          break;
        }
        val1_4 = System.Math.Min(val1_4, num12);
        val1_3 = System.Math.Max(val1_3, System.Math.Max(num12, val2));
      }
      if (!flag2)
      {
        index1 = 0;
      }
      else
      {
        e[index1] = 0.0;
        if (index1 == index3 - 1)
        {
          --index3;
          continue;
        }
      }
      ++index1;
      if (index1 == index3 - 1)
      {
        bdsvd.svdv2x2(d[index3 - 1], e[index3 - 1], d[index3], ref ssmin2, ref ssmax, ref num5, ref num2, ref num4, ref num1);
        d[index3 - 1] = ssmax;
        e[index3 - 1] = 0.0;
        d[index3] = ssmin2;
        if (ncvt > 0)
        {
          int index2 = index3 + (vstart - 1);
          int index4 = index3 - 1 + (vstart - 1);
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            work2[index5] = num2 * vt[index4, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            work2[index5] = work2[index5] + num5 * vt[index2, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[index2, index5] = num2 * vt[index2, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[index2, index5] = vt[index2, index5] - num5 * vt[index4, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[index4, index5] = work2[index5];
        }
        if (nru > 0)
        {
          int index2 = index3 + ustart - 1;
          int index4 = index3 - 1 + ustart - 1;
          for (int index5 = ustart; index5 <= m2; ++index5)
            work1[index5] = num1 * u[index5, index4];
          for (int index5 = ustart; index5 <= m2; ++index5)
            work1[index5] = work1[index5] + num4 * u[index5, index2];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, index2] = num1 * u[index5, index2];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, index2] = u[index5, index2] - num4 * u[index5, index4];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, index4] = work1[index5];
        }
        if (ncc > 0)
        {
          int index2 = index3 + cstart - 1;
          int index4 = index3 - 1 + cstart - 1;
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            work3[index5] = num1 * c[index4, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            work3[index5] = work3[index5] + num4 * c[index2, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[index2, index5] = num1 * c[index2, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[index2, index5] = c[index2, index5] - num4 * c[index4, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[index4, index5] = work3[index5];
        }
        index3 -= 2;
      }
      else
      {
        bool flag3 = false;
        if (num7 == 1 & System.Math.Abs(d[index1]) < 0.001 * System.Math.Abs(d[index3]))
          flag3 = true;
        if (num7 == 2 & System.Math.Abs(d[index3]) < 0.001 * System.Math.Abs(d[index1]))
          flag3 = true;
        if (index1 != num15 | index3 != num16 | flag3)
          num7 = System.Math.Abs(d[index1]) < System.Math.Abs(d[index3]) ? 2 : 1;
        if (num7 == 1)
        {
          if (System.Math.Abs(e[index3 - 1]) <= System.Math.Abs(num10) * System.Math.Abs(d[index3]) | num10 < 0.0 & System.Math.Abs(e[index3 - 1]) <= num11)
          {
            e[index3 - 1] = 0.0;
            continue;
          }
          if (num10 >= 0.0)
          {
            double val2 = System.Math.Abs(d[index1]);
            val1_2 = val2;
            bool flag4 = false;
            for (int index2 = index1; index2 <= index3 - 1; ++index2)
            {
              if (System.Math.Abs(e[index2]) <= num10 * val2)
              {
                e[index2] = 0.0;
                flag4 = true;
                break;
              }
              val2 = System.Math.Abs(d[index2 + 1]) * (val2 / (val2 + System.Math.Abs(e[index2])));
              val1_2 = System.Math.Min(val1_2, val2);
            }
            if (flag4)
              continue;
          }
        }
        else
        {
          if (System.Math.Abs(e[index1]) <= System.Math.Abs(num10) * System.Math.Abs(d[index1]) | num10 < 0.0 & System.Math.Abs(e[index1]) <= num11)
          {
            e[index1] = 0.0;
            continue;
          }
          if (num10 >= 0.0)
          {
            double val2 = System.Math.Abs(d[index3]);
            val1_2 = val2;
            bool flag4 = false;
            for (int index2 = index3 - 1; index2 >= index1; --index2)
            {
              if (System.Math.Abs(e[index2]) <= num10 * val2)
              {
                e[index2] = 0.0;
                flag4 = true;
                break;
              }
              val2 = System.Math.Abs(d[index2]) * (val2 / (val2 + System.Math.Abs(e[index2])));
              val1_2 = System.Math.Min(val1_2, val2);
            }
            if (flag4)
              continue;
          }
        }
        num15 = index1;
        num16 = index3;
        if (num10 >= 0.0 & (double) n * num10 * (val1_2 / val1_3) <= System.Math.Max(num8, 0.01 * num10))
        {
          ssmin1 = 0.0;
        }
        else
        {
          double num12;
          if (num7 == 1)
          {
            num12 = System.Math.Abs(d[index1]);
            bdsvd.svd2x2(d[index3 - 1], e[index3 - 1], d[index3], ref ssmin1, ref num3);
          }
          else
          {
            num12 = System.Math.Abs(d[index3]);
            bdsvd.svd2x2(d[index1], e[index1], d[index1 + 1], ref ssmin1, ref num3);
          }
          if (num12 > 0.0 && AP.Math.Sqr(ssmin1 / num12) < num8)
            ssmin1 = 0.0;
        }
        num14 = num14 + index3 - index1;
        double cs2;
        if (ssmin1 == 0.0)
        {
          if (num7 == 1)
          {
            cs1 = 1.0;
            cs2 = 1.0;
            for (int index2 = index1; index2 <= index3 - 1; ++index2)
            {
              rotations.generaterotation(d[index2] * cs1, e[index2], ref cs1, ref sn2, ref num3);
              if (index2 > index1)
                e[index2 - 1] = sn1 * num3;
              rotations.generaterotation(cs2 * num3, d[index2 + 1] * sn2, ref cs2, ref sn1, ref r);
              d[index2] = r;
              c1[index2 - index1 + 1] = cs1;
              s1[index2 - index1 + 1] = sn2;
              c2[index2 - index1 + 1] = cs2;
              s2[index2 - index1 + 1] = sn1;
            }
            double num12 = d[index3] * cs1;
            d[index3] = num12 * cs2;
            e[index3 - 1] = num12 * sn1;
            if (ncvt > 0)
              rotations.applyrotationsfromtheleft(isforward, index1 + vstart - 1, index3 + vstart - 1, vstart, n2_1, ref c1, ref s1, ref vt, ref work2);
            if (nru > 0)
              rotations.applyrotationsfromtheright(isforward, ustart, m2, index1 + ustart - 1, index3 + ustart - 1, ref c2, ref s2, ref u, ref work1);
            if (ncc > 0)
              rotations.applyrotationsfromtheleft(isforward, index1 + cstart - 1, index3 + cstart - 1, cstart, n2_2, ref c2, ref s2, ref c, ref work3);
            if (System.Math.Abs(e[index3 - 1]) <= num11)
              e[index3 - 1] = 0.0;
          }
          else
          {
            cs1 = 1.0;
            cs2 = 1.0;
            for (int index2 = index3; index2 >= index1 + 1; --index2)
            {
              rotations.generaterotation(d[index2] * cs1, e[index2 - 1], ref cs1, ref sn2, ref num3);
              if (index2 < index3)
                e[index2] = sn1 * num3;
              rotations.generaterotation(cs2 * num3, d[index2 - 1] * sn2, ref cs2, ref sn1, ref r);
              d[index2] = r;
              c1[index2 - index1] = cs1;
              s1[index2 - index1] = -sn2;
              c2[index2 - index1] = cs2;
              s2[index2 - index1] = -sn1;
            }
            double num12 = d[index1] * cs1;
            d[index1] = num12 * cs2;
            e[index1] = num12 * sn1;
            if (ncvt > 0)
              rotations.applyrotationsfromtheleft(!isforward, index1 + vstart - 1, index3 + vstart - 1, vstart, n2_1, ref c2, ref s2, ref vt, ref work2);
            if (nru > 0)
              rotations.applyrotationsfromtheright(!isforward, ustart, m2, index1 + ustart - 1, index3 + ustart - 1, ref c1, ref s1, ref u, ref work1);
            if (ncc > 0)
              rotations.applyrotationsfromtheleft(!isforward, index1 + cstart - 1, index3 + cstart - 1, cstart, n2_2, ref c1, ref s1, ref c, ref work3);
            if (System.Math.Abs(e[index1]) <= num11)
              e[index1] = 0.0;
          }
        }
        else if (num7 == 1)
        {
          double f1 = (System.Math.Abs(d[index1]) - ssmin1) * (bdsvd.extsignbdsqr(1.0, d[index1]) + ssmin1 / d[index1]);
          double g = e[index1];
          for (int index2 = index1; index2 <= index3 - 1; ++index2)
          {
            rotations.generaterotation(f1, g, ref num2, ref num5, ref num3);
            if (index2 > index1)
              e[index2 - 1] = num3;
            double f2 = num2 * d[index2] + num5 * e[index2];
            e[index2] = num2 * e[index2] - num5 * d[index2];
            g = num5 * d[index2 + 1];
            d[index2 + 1] = num2 * d[index2 + 1];
            rotations.generaterotation(f2, g, ref num1, ref num4, ref num3);
            d[index2] = num3;
            f1 = num1 * e[index2] + num4 * d[index2 + 1];
            d[index2 + 1] = num1 * d[index2 + 1] - num4 * e[index2];
            if (index2 < index3 - 1)
            {
              g = num4 * e[index2 + 1];
              e[index2 + 1] = num1 * e[index2 + 1];
            }
            c1[index2 - index1 + 1] = num2;
            s1[index2 - index1 + 1] = num5;
            c2[index2 - index1 + 1] = num1;
            s2[index2 - index1 + 1] = num4;
          }
          e[index3 - 1] = f1;
          if (ncvt > 0)
            rotations.applyrotationsfromtheleft(isforward, index1 + vstart - 1, index3 + vstart - 1, vstart, n2_1, ref c1, ref s1, ref vt, ref work2);
          if (nru > 0)
            rotations.applyrotationsfromtheright(isforward, ustart, m2, index1 + ustart - 1, index3 + ustart - 1, ref c2, ref s2, ref u, ref work1);
          if (ncc > 0)
            rotations.applyrotationsfromtheleft(isforward, index1 + cstart - 1, index3 + cstart - 1, cstart, n2_2, ref c2, ref s2, ref c, ref work3);
          if (System.Math.Abs(e[index3 - 1]) <= num11)
            e[index3 - 1] = 0.0;
        }
        else
        {
          double f1 = (System.Math.Abs(d[index3]) - ssmin1) * (bdsvd.extsignbdsqr(1.0, d[index3]) + ssmin1 / d[index3]);
          double g = e[index3 - 1];
          for (int index2 = index3; index2 >= index1 + 1; --index2)
          {
            rotations.generaterotation(f1, g, ref num2, ref num5, ref num3);
            if (index2 < index3)
              e[index2] = num3;
            double f2 = num2 * d[index2] + num5 * e[index2 - 1];
            e[index2 - 1] = num2 * e[index2 - 1] - num5 * d[index2];
            g = num5 * d[index2 - 1];
            d[index2 - 1] = num2 * d[index2 - 1];
            rotations.generaterotation(f2, g, ref num1, ref num4, ref num3);
            d[index2] = num3;
            f1 = num1 * e[index2 - 1] + num4 * d[index2 - 1];
            d[index2 - 1] = num1 * d[index2 - 1] - num4 * e[index2 - 1];
            if (index2 > index1 + 1)
            {
              g = num4 * e[index2 - 2];
              e[index2 - 2] = num1 * e[index2 - 2];
            }
            c1[index2 - index1] = num2;
            s1[index2 - index1] = -num5;
            c2[index2 - index1] = num1;
            s2[index2 - index1] = -num4;
          }
          e[index1] = f1;
          if (System.Math.Abs(e[index1]) <= num11)
            e[index1] = 0.0;
          if (ncvt > 0)
            rotations.applyrotationsfromtheleft(!isforward, index1 + vstart - 1, index3 + vstart - 1, vstart, n2_1, ref c2, ref s2, ref vt, ref work2);
          if (nru > 0)
            rotations.applyrotationsfromtheright(!isforward, ustart, m2, index1 + ustart - 1, index3 + ustart - 1, ref c1, ref s1, ref u, ref work1);
          if (ncc > 0)
            rotations.applyrotationsfromtheleft(!isforward, index1 + cstart - 1, index3 + cstart - 1, cstart, n2_2, ref c1, ref s1, ref c, ref work3);
        }
      }
    }
    for (int index2 = 1; index2 <= n; ++index2)
    {
      if (d[index2] < 0.0)
      {
        d[index2] = -d[index2];
        if (ncvt > 0)
        {
          for (int index4 = vstart; index4 <= n2_1; ++index4)
            vt[index2 + vstart - 1, index4] = -1.0 * vt[index2 + vstart - 1, index4];
        }
      }
    }
    for (int index2 = 1; index2 <= n - 1; ++index2)
    {
      int index4 = 1;
      double num12 = d[1];
      for (int index5 = 2; index5 <= n + 1 - index2; ++index5)
      {
        if (d[index5] <= num12)
        {
          index4 = index5;
          num12 = d[index5];
        }
      }
      if (index4 != n + 1 - index2)
      {
        d[index4] = d[n + 1 - index2];
        d[n + 1 - index2] = num12;
        if (ncvt > 0)
        {
          int num17 = n + 1 - index2;
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            work2[index5] = vt[index4 + vstart - 1, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[index4 + vstart - 1, index5] = vt[num17 + vstart - 1, index5];
          for (int index5 = vstart; index5 <= n2_1; ++index5)
            vt[num17 + vstart - 1, index5] = work2[index5];
        }
        if (nru > 0)
        {
          int num17 = n + 1 - index2;
          for (int index5 = ustart; index5 <= m2; ++index5)
            work1[index5] = u[index5, index4 + ustart - 1];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, index4 + ustart - 1] = u[index5, num17 + ustart - 1];
          for (int index5 = ustart; index5 <= m2; ++index5)
            u[index5, num17 + ustart - 1] = work1[index5];
        }
        if (ncc > 0)
        {
          int num17 = n + 1 - index2;
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            work3[index5] = c[index4 + cstart - 1, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[index4 + cstart - 1, index5] = c[num17 + cstart - 1, index5];
          for (int index5 = cstart; index5 <= n2_2; ++index5)
            c[num17 + cstart - 1, index5] = work3[index5];
        }
      }
    }
    return flag1;
  }

19 Source : bdsvd.cs
with MIT License
from 1CM69

private static double extsignbdsqr(double a, double b)
  {
    return b < 0.0 ? -System.Math.Abs(a) : System.Math.Abs(a);
  }

19 Source : bdsvd.cs
with MIT License
from 1CM69

private static void svd2x2(double f, double g, double h, ref double ssmin, ref double ssmax)
  {
    double val1_1 = System.Math.Abs(f);
    double val2_1 = System.Math.Abs(g);
    double val2_2 = System.Math.Abs(h);
    double num1 = System.Math.Min(val1_1, val2_2);
    double val1_2 = System.Math.Max(val1_1, val2_2);
    if (num1 == 0.0)
    {
      ssmin = 0.0;
      if (val1_2 == 0.0)
        ssmax = val2_1;
      else
        ssmax = System.Math.Max(val1_2, val2_1) * System.Math.Sqrt(1.0 + AP.Math.Sqr(System.Math.Min(val1_2, val2_1) / System.Math.Max(val1_2, val2_1)));
    }
    else if (val2_1 < val1_2)
    {
      double num2 = 1.0 + num1 / val1_2;
      double num3 = (val1_2 - num1) / val1_2;
      double num4 = AP.Math.Sqr(val2_1 / val1_2);
      double num5 = 2.0 / (System.Math.Sqrt(num2 * num2 + num4) + System.Math.Sqrt(num3 * num3 + num4));
      ssmin = num1 * num5;
      ssmax = val1_2 / num5;
    }
    else
    {
      double num2 = val1_2 / val2_1;
      if (num2 == 0.0)
      {
        ssmin = num1 * val1_2 / val2_1;
        ssmax = val2_1;
      }
      else
      {
        double num3 = 1.0 + num1 / val1_2;
        double num4 = (val1_2 - num1) / val1_2;
        double num5 = 1.0 / (System.Math.Sqrt(1.0 + AP.Math.Sqr(num3 * num2)) + System.Math.Sqrt(1.0 + AP.Math.Sqr(num4 * num2)));
        ssmin = num1 * num5 * num2;
        ssmin = ssmin + ssmin;
        ssmax = val2_1 / (num5 + num5);
      }
    }
  }

19 Source : bdsvd.cs
with MIT License
from 1CM69

private static void svdv2x2(double f, double g, double h, ref double ssmin, ref double ssmax, ref double snr, ref double csr, ref double snl, ref double csl)
  {
    double num1 = 0.0;
    double num2 = 0.0;
    double num3 = 0.0;
    double num4 = 0.0;
    double b1 = 0.0;
    double b2 = f;
    double num5 = System.Math.Abs(b2);
    double num6 = h;
    double num7 = System.Math.Abs(h);
    int num8 = 1;
    bool flag1 = num7 > num5;
    if (flag1)
    {
      num8 = 3;
      double num9 = b2;
      b2 = num6;
      num6 = num9;
      double num10 = num5;
      num5 = num7;
      num7 = num10;
    }
    double b3 = g;
    double num11 = System.Math.Abs(b3);
    if (num11 == 0.0)
    {
      ssmin = num7;
      ssmax = num5;
      num1 = 1.0;
      num2 = 1.0;
      num3 = 0.0;
      num4 = 0.0;
    }
    else
    {
      bool flag2 = true;
      if (num11 > num5)
      {
        num8 = 2;
        if (num5 / num11 < 5E-16)
        {
          flag2 = false;
          ssmax = num11;
          if (num7 > 1.0)
          {
            double num9 = num11 / num7;
            ssmin = num5 / num9;
          }
          else
          {
            double num9 = num5 / num11;
            ssmin = num9 * num7;
          }
          num1 = 1.0;
          num3 = num6 / b3;
          num4 = 1.0;
          num2 = b2 / b3;
        }
      }
      if (flag2)
      {
        double a = num5 - num7;
        double num9 = a != num5 ? a / num5 : 1.0;
        double num10 = b3 / b2;
        double num12 = 2.0 - num9;
        double num13 = num10 * num10;
        double num14 = System.Math.Sqrt(num12 * num12 + num13);
        double num15 = num9 != 0.0 ? System.Math.Sqrt(num9 * num9 + num13) : System.Math.Abs(num10);
        double num16 = 0.5 * (num14 + num15);
        ssmin = num7 / num16;
        ssmax = num5 * num16;
        double num17 = num13 != 0.0 ? (num10 / (num14 + num12) + num10 / (num15 + num9)) * (1.0 + num16) : (num9 != 0.0 ? b3 / bdsvd.extsignbdsqr(a, b2) + num10 / num12 : bdsvd.extsignbdsqr(2.0, b2) * bdsvd.extsignbdsqr(1.0, b3));
        double num18 = System.Math.Sqrt(num17 * num17 + 4.0);
        num2 = 2.0 / num18;
        num4 = num17 / num18;
        num1 = (num2 + num4 * num10) / num16;
        num3 = num6 / b2 * num4 / num16;
      }
    }
    if (flag1)
    {
      csl = num4;
      snl = num2;
      csr = num3;
      snr = num1;
    }
    else
    {
      csl = num1;
      snl = num3;
      csr = num2;
      snr = num4;
    }
    if (num8 == 1)
      b1 = bdsvd.extsignbdsqr(1.0, csr) * bdsvd.extsignbdsqr(1.0, csl) * bdsvd.extsignbdsqr(1.0, f);
    if (num8 == 2)
      b1 = bdsvd.extsignbdsqr(1.0, snr) * bdsvd.extsignbdsqr(1.0, csl) * bdsvd.extsignbdsqr(1.0, g);
    if (num8 == 3)
      b1 = bdsvd.extsignbdsqr(1.0, snr) * bdsvd.extsignbdsqr(1.0, snl) * bdsvd.extsignbdsqr(1.0, h);
    ssmax = bdsvd.extsignbdsqr(ssmax, b1);
    ssmin = bdsvd.extsignbdsqr(ssmin, b1 * bdsvd.extsignbdsqr(1.0, f) * bdsvd.extsignbdsqr(1.0, h));
  }

19 Source : blas.cs
with MIT License
from 1CM69

public static int columnidxabsmax(ref double[,] x, int i1, int i2, int j)
  {
    int index1 = i1;
    System.Math.Abs(x[index1, j]);
    for (int index2 = i1 + 1; index2 <= i2; ++index2)
    {
      if (System.Math.Abs(x[index2, j]) > System.Math.Abs(x[index1, j]))
        index1 = index2;
    }
    return index1;
  }

19 Source : blas.cs
with MIT License
from 1CM69

public static double upperhessenberg1norm(ref double[,] a, int i1, int i2, int j1, int j2, ref double[] work)
  {
    for (int index = j1; index <= j2; ++index)
      work[index] = 0.0;
    for (int index1 = i1; index1 <= i2; ++index1)
    {
      for (int index2 = System.Math.Max(j1, j1 + index1 - i1 - 1); index2 <= j2; ++index2)
        work[index2] = work[index2] + System.Math.Abs(a[index1, index2]);
    }
    double val1 = 0.0;
    for (int index = j1; index <= j2; ++index)
      val1 = System.Math.Max(val1, work[index]);
    return val1;
  }

19 Source : blas.cs
with MIT License
from 1CM69

public static double pythag2(double x, double y)
  {
    double val1 = System.Math.Abs(x);
    double val2 = System.Math.Abs(y);
    double num1 = System.Math.Max(val1, val2);
    double num2 = System.Math.Min(val1, val2);
    return num2 != 0.0 ? num1 * System.Math.Sqrt(1.0 + AP.Math.Sqr(num2 / num1)) : num1;
  }

19 Source : leastsquares.cs
with MIT License
from 1CM69

public static void buildlinearleastsquares(ref double[] x, ref double[] y, int n, ref double a, ref double b)
  {
    double num1 = (double) n;
    double num2 = 0.0;
    double num3 = 0.0;
    double num4 = 0.0;
    double num5 = 0.0;
    for (int index = 0; index <= n - 1; ++index)
    {
      num3 += x[index];
      num2 += AP.Math.Sqr(x[index]);
      num4 += y[index];
      num5 += x[index] * y[index];
    }
    double num6 = System.Math.Atan2(2.0 * num3, num2 - num1) / 2.0;
    double X1 = System.Math.Cos(num6);
    double X2 = System.Math.Sin(num6);
    double num7 = AP.Math.Sqr(X1) * num1 + AP.Math.Sqr(X2) * num2 - 2.0 * X2 * X1 * num3;
    double num8 = AP.Math.Sqr(X2) * num1 + AP.Math.Sqr(X1) * num2 + 2.0 * X2 * X1 * num3;
    double num9 = System.Math.Abs(num7) <= System.Math.Abs(num8) ? System.Math.Abs(num8) : System.Math.Abs(num7);
    double num10 = X1 * num4 - X2 * num5;
    double num11 = X2 * num4 + X1 * num5;
    double num12 = System.Math.Abs(num7) <= num9 * 5E-16 * 1000.0 ? 0.0 : num10 / num7;
    double num13 = System.Math.Abs(num8) <= num9 * 5E-16 * 1000.0 ? 0.0 : num11 / num8;
    a = X1 * num12 + X2 * num13;
    b = -(X2 * num12) + X1 * num13;
  }

19 Source : reflections.cs
with MIT License
from 1CM69

public static void generatereflection(ref double[] x, int n, ref double tau)
  {
    if (n <= 1)
    {
      tau = 0.0;
    }
    else
    {
      double num1 = x[1];
      double val2 = 0.0;
      for (int index = 2; index <= n; ++index)
        val2 = System.Math.Max(System.Math.Abs(x[index]), val2);
      double d = 0.0;
      if (val2 != 0.0)
      {
        for (int index = 2; index <= n; ++index)
          d += AP.Math.Sqr(x[index] / val2);
        d = System.Math.Sqrt(d) * val2;
      }
      if (d == 0.0)
      {
        tau = 0.0;
      }
      else
      {
        double num2 = System.Math.Max(System.Math.Abs(num1), System.Math.Abs(d));
        double num3 = -(num2 * System.Math.Sqrt(AP.Math.Sqr(num1 / num2) + AP.Math.Sqr(d / num2)));
        if (num1 < 0.0)
          num3 = -num3;
        tau = (num3 - num1) / num3;
        double num4 = 1.0 / (num1 - num3);
        for (int index = 2; index <= n; ++index)
          x[index] = num4 * x[index];
        x[1] = num3;
      }
    }
  }

19 Source : reflections.cs
with MIT License
from 1CM69

private static void testreflections()
  {
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    double[] numArray3 = new double[0];
    double[,] numArray4 = new double[0, 0];
    double[,] numArray5 = new double[0, 0];
    double[,] numArray6 = new double[0, 0];
    double[,] numArray7 = new double[0, 0];
    double num1 = 0.0;
    double tau = 0.0;
    int num2 = 1000;
    double val1_1 = 0.0;
    double val1_2 = 0.0;
    double val1_3 = 0.0;
    for (int index1 = 1; index1 <= num2; ++index1)
    {
      int num3 = 1 + AP.Math.RandomInteger(10);
      int num4 = 1 + AP.Math.RandomInteger(10);
      int num5 = System.Math.Max(num4, num3);
      double[] numArray8 = new double[num5 + 1];
      double[] numArray9 = new double[num5 + 1];
      double[] work = new double[num5 + 1];
      double[,] numArray10 = new double[num5 + 1, num5 + 1];
      double[,] numArray11 = new double[num5 + 1, num5 + 1];
      double[,] c = new double[num5 + 1, num5 + 1];
      double[,] numArray12 = new double[num5 + 1, num5 + 1];
      for (int index2 = 1; index2 <= num3; ++index2)
      {
        numArray8[index2] = 2.0 * AP.Math.RandomReal() - 1.0;
        numArray9[index2] = numArray8[index2];
      }
      reflections.generatereflection(ref numArray9, num3, ref tau);
      double num6 = numArray9[1];
      numArray9[1] = 1.0;
      for (int index2 = 1; index2 <= num3; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
          numArray10[index2, index3] = index2 != index3 ? -(tau * numArray9[index2] * numArray9[index3]) : 1.0 - tau * numArray9[index2] * numArray9[index3];
      }
      double num7 = 0.0;
      for (int index2 = 1; index2 <= num3; ++index2)
      {
        double num8 = 0.0;
        for (int index3 = 1; index3 <= num3; ++index3)
          num8 += numArray10[index2, index3] * numArray8[index3];
        num7 = index2 != 1 ? System.Math.Max(num7, System.Math.Abs(num8)) : System.Math.Max(num7, System.Math.Abs(num8 - num6));
      }
      val1_3 = System.Math.Max(val1_3, num7);
      for (int index2 = 1; index2 <= num4; ++index2)
      {
        numArray8[index2] = 2.0 * AP.Math.RandomReal() - 1.0;
        numArray9[index2] = numArray8[index2];
      }
      for (int index2 = 1; index2 <= num4; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
        {
          numArray11[index2, index3] = 2.0 * AP.Math.RandomReal() - 1.0;
          c[index2, index3] = numArray11[index2, index3];
        }
      }
      reflections.generatereflection(ref numArray9, num4, ref tau);
      num1 = numArray9[1];
      numArray9[1] = 1.0;
      reflections.applyreflectionfromtheleft(ref c, tau, ref numArray9, 1, num4, 1, num3, ref work);
      for (int index2 = 1; index2 <= num4; ++index2)
      {
        for (int index3 = 1; index3 <= num4; ++index3)
          numArray10[index2, index3] = index2 != index3 ? -(tau * numArray9[index2] * numArray9[index3]) : 1.0 - tau * numArray9[index2] * numArray9[index3];
      }
      for (int index2 = 1; index2 <= num4; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
        {
          double num8 = 0.0;
          for (int index4 = 1; index4 <= num4; ++index4)
            num8 += numArray10[index2, index4] * numArray11[index4, index3];
          numArray12[index2, index3] = num8;
        }
      }
      double num9 = 0.0;
      for (int index2 = 1; index2 <= num4; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
          num9 = System.Math.Max(num9, System.Math.Abs(c[index2, index3] - numArray12[index2, index3]));
      }
      val1_2 = System.Math.Max(val1_2, num9);
      for (int index2 = 1; index2 <= num3; ++index2)
      {
        numArray8[index2] = 2.0 * AP.Math.RandomReal() - 1.0;
        numArray9[index2] = numArray8[index2];
      }
      for (int index2 = 1; index2 <= num4; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
        {
          numArray11[index2, index3] = 2.0 * AP.Math.RandomReal() - 1.0;
          c[index2, index3] = numArray11[index2, index3];
        }
      }
      reflections.generatereflection(ref numArray9, num3, ref tau);
      num1 = numArray9[1];
      numArray9[1] = 1.0;
      reflections.applyreflectionfromtheright(ref c, tau, ref numArray9, 1, num4, 1, num3, ref work);
      for (int index2 = 1; index2 <= num3; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
          numArray10[index2, index3] = index2 != index3 ? -(tau * numArray9[index2] * numArray9[index3]) : 1.0 - tau * numArray9[index2] * numArray9[index3];
      }
      for (int index2 = 1; index2 <= num4; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
        {
          double num8 = 0.0;
          for (int index4 = 1; index4 <= num3; ++index4)
            num8 += numArray11[index2, index4] * numArray10[index4, index3];
          numArray12[index2, index3] = num8;
        }
      }
      double num10 = 0.0;
      for (int index2 = 1; index2 <= num4; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
          num10 = System.Math.Max(num10, System.Math.Abs(c[index2, index3] - numArray12[index2, index3]));
      }
      val1_1 = System.Math.Max(val1_1, num10);
    }
    numArray1 = new double[11];
    double[] x = new double[11];
    for (int index = 1; index <= 10; ++index)
      x[index] = 1E+298 * (2.0 * AP.Math.RandomReal() - 1.0);
    reflections.generatereflection(ref x, 10, ref tau);
    Console.Write("TESTING REFLECTIONS");
    Console.WriteLine();
    Console.Write("Preplaced count is ");
    Console.Write("{0,0:d}", (object) num2);
    Console.WriteLine();
    Console.Write("Generate     absolute error is       ");
    Console.Write("{0,5:E3}", (object) val1_3);
    Console.WriteLine();
    Console.Write("Apply(Left)  absolute error is       ");
    Console.Write("{0,5:E3}", (object) val1_2);
    Console.WriteLine();
    Console.Write("Apply(Right) absolute error is       ");
    Console.Write("{0,5:E3}", (object) val1_1);
    Console.WriteLine();
    Console.Write("Overflow crash test preplaceded");
    Console.WriteLine();
  }

19 Source : rotations.cs
with MIT License
from 1CM69

public static void generaterotation(double f, double g, ref double cs, ref double sn, ref double r)
  {
    if (g == 0.0)
    {
      cs = 1.0;
      sn = 0.0;
      r = f;
    }
    else if (f == 0.0)
    {
      cs = 0.0;
      sn = 1.0;
      r = g;
    }
    else
    {
      double X1 = f;
      double X2 = g;
      r = System.Math.Sqrt(AP.Math.Sqr(X1) + AP.Math.Sqr(X2));
      cs = X1 / r;
      sn = X2 / r;
      if (!(System.Math.Abs(f) > System.Math.Abs(g) & cs < 0.0))
        return;
      cs = -cs;
      sn = -sn;
      r = -r;
    }
  }

19 Source : rotations.cs
with MIT License
from 1CM69

private static void testrotations()
  {
    double[,] numArray1 = new double[0, 0];
    double[,] numArray2 = new double[0, 0];
    double[,] numArray3 = new double[0, 0];
    double[,] numArray4 = new double[0, 0];
    double[] numArray5 = new double[0];
    double[] numArray6 = new double[0];
    double[] numArray7 = new double[0];
    double[] numArray8 = new double[0];
    double[] numArray9 = new double[0];
    int num1 = 1000;
    double val2_1 = 0.0;
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      int num2 = 2 + AP.Math.RandomInteger(50);
      int num3 = 2 + AP.Math.RandomInteger(50);
      bool isforward = AP.Math.RandomReal() > 0.5;
      int num4 = System.Math.Max(num2, num3);
      double[,] a1 = new double[num2 + 1, num3 + 1];
      double[,] a2 = new double[num2 + 1, num3 + 1];
      double[,] a3 = new double[num2 + 1, num3 + 1];
      double[,] a4 = new double[num2 + 1, num3 + 1];
      double[] c1 = new double[num2 - 1 + 1];
      double[] s1 = new double[num2 - 1 + 1];
      double[] c2 = new double[num3 - 1 + 1];
      double[] s2 = new double[num3 - 1 + 1];
      double[] work = new double[num4 + 1];
      for (int index2 = 1; index2 <= num2; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
        {
          a1[index2, index3] = 2.0 * AP.Math.RandomReal() - 1.0;
          a2[index2, index3] = a1[index2, index3];
          a3[index2, index3] = a1[index2, index3];
          a4[index2, index3] = a1[index2, index3];
        }
      }
      for (int index2 = 1; index2 <= num2 - 1; ++index2)
      {
        double num5 = 2.0 * System.Math.PI * AP.Math.RandomReal();
        c1[index2] = System.Math.Cos(num5);
        s1[index2] = System.Math.Sin(num5);
      }
      for (int index2 = 1; index2 <= num3 - 1; ++index2)
      {
        double num5 = 2.0 * System.Math.PI * AP.Math.RandomReal();
        c2[index2] = System.Math.Cos(num5);
        s2[index2] = System.Math.Sin(num5);
      }
      rotations.applyrotationsfromtheleft(isforward, 1, num2, 1, num3, ref c1, ref s1, ref a1, ref work);
      for (int index2 = 1; index2 <= num3; ++index2)
        rotations.applyrotationsfromtheleft(isforward, 1, num2, index2, index2, ref c1, ref s1, ref a2, ref work);
      double val1_1 = 0.0;
      for (int index2 = 1; index2 <= num2; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
          val1_1 = System.Math.Max(val1_1, System.Math.Abs(a1[index2, index3] - a2[index2, index3]));
      }
      double val2_2 = System.Math.Max(val1_1, val2_1);
      rotations.applyrotationsfromtheright(isforward, 1, num2, 1, num3, ref c2, ref s2, ref a3, ref work);
      for (int index2 = 1; index2 <= num2; ++index2)
        rotations.applyrotationsfromtheright(isforward, index2, index2, 1, num3, ref c2, ref s2, ref a4, ref work);
      double val1_2 = 0.0;
      for (int index2 = 1; index2 <= num2; ++index2)
      {
        for (int index3 = 1; index3 <= num3; ++index3)
          val1_2 = System.Math.Max(val1_2, System.Math.Abs(a3[index2, index3] - a4[index2, index3]));
      }
      val2_1 = System.Math.Max(val1_2, val2_2);
    }
    Console.Write("TESTING ROTATIONS");
    Console.WriteLine();
    Console.Write("Preplaced count ");
    Console.Write("{0,0:d}", (object) num1);
    Console.WriteLine();
    Console.Write("Error is ");
    Console.Write("{0,5:E3}", (object) val2_1);
    Console.WriteLine();
  }

19 Source : spline3.cs
with MIT License
from 1CM69

public static void buildakimaspline(double[] x, double[] y, int n, ref double[] c)
  {
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    double[] numArray3 = new double[0];
    x = (double[]) x.Clone();
    y = (double[]) y.Clone();
    spline3.heapsortpoints(ref x, ref y, n);
    double[] numArray4 = new double[n - 2 + 1];
    double[] numArray5 = new double[n - 2 + 1];
    for (int index = 0; index <= n - 2; ++index)
      numArray5[index] = (y[index + 1] - y[index]) / (x[index + 1] - x[index]);
    for (int index = 1; index <= n - 2; ++index)
      numArray4[index] = System.Math.Abs(numArray5[index] - numArray5[index - 1]);
    double[] d = new double[n - 1 + 1];
    for (int index = 2; index <= n - 3; ++index)
      d[index] = System.Math.Abs(numArray4[index - 1]) + System.Math.Abs(numArray4[index + 1]) == 0.0 ? ((x[index + 1] - x[index]) * numArray5[index - 1] + (x[index] - x[index - 1]) * numArray5[index]) / (x[index + 1] - x[index - 1]) : (numArray4[index + 1] * numArray5[index - 1] + numArray4[index - 1] * numArray5[index]) / (numArray4[index + 1] + numArray4[index - 1]);
    d[0] = spline3.diffthreepoint(x[0], x[0], y[0], x[1], y[1], x[2], y[2]);
    d[1] = spline3.diffthreepoint(x[1], x[0], y[0], x[1], y[1], x[2], y[2]);
    d[n - 2] = spline3.diffthreepoint(x[n - 2], x[n - 3], y[n - 3], x[n - 2], y[n - 2], x[n - 1], y[n - 1]);
    d[n - 1] = spline3.diffthreepoint(x[n - 1], x[n - 3], y[n - 3], x[n - 2], y[n - 2], x[n - 1], y[n - 1]);
    spline3.buildhermitespline(x, y, d, n, ref c);
  }

19 Source : blas.cs
with MIT License
from 1CM69

public static int rowidxabsmax(ref double[,] x, int j1, int j2, int i)
  {
    int index1 = j1;
    System.Math.Abs(x[i, index1]);
    for (int index2 = j1 + 1; index2 <= j2; ++index2)
    {
      if (System.Math.Abs(x[i, index2]) > System.Math.Abs(x[i, index1]))
        index1 = index2;
    }
    return index1;
  }

19 Source : blas.cs
with MIT License
from 1CM69

public static double vectornorm2(ref double[] x, int i1, int i2)
  {
    int num1 = i2 - i1 + 1;
    if (num1 < 1)
      return 0.0;
    if (num1 == 1)
      return System.Math.Abs(x[i1]);
    double num2 = 0.0;
    double d = 1.0;
    for (int index = i1; index <= i2; ++index)
    {
      if (x[index] != 0.0)
      {
        double num3 = System.Math.Abs(x[index]);
        if (num2 < num3)
        {
          d = 1.0 + d * AP.Math.Sqr(num2 / num3);
          num2 = num3;
        }
        else
          d += AP.Math.Sqr(num3 / num2);
      }
    }
    return num2 * System.Math.Sqrt(d);
  }

19 Source : blas.cs
with MIT License
from 1CM69

public static int vectoridxabsmax(ref double[] x, int i1, int i2)
  {
    int index1 = i1;
    System.Math.Abs(x[index1]);
    for (int index2 = i1 + 1; index2 <= i2; ++index2)
    {
      if (System.Math.Abs(x[index2]) > System.Math.Abs(x[index1]))
        index1 = index2;
    }
    return index1;
  }

19 Source : GCodeParser.cs
with MIT License
from 3RD-Dimension

static void Parse(string line, int lineNumber)
		{
			MatchCollection matches = GCodeSplitter.Matches(line);

			List<Word> Words = new List<Word>(matches.Count);

			foreach (Match match in matches)
			{
				Words.Add(new Word() { Command = match.Groups[1].Value[0], Parameter = double.Parse(match.Groups[2].Value, Constants.DecimalParseFormat) });
			}

			for (int i = 0; i < Words.Count; i++)
			{
				if (Words[i].Command == 'N')
				{
					Words.RemoveAt(i--);
					continue;
				}

				if (IgnoreAxes.Contains(Words[i].Command) && Properties.Settings.Default.IgnoreAdditionalAxes)
				{
					Words.RemoveAt(i--);
					continue;
				}

				if (!ValidWords.Contains(Words[i].Command))
				{
					Warnings.Add($"ignoring unknown word (letter): \"{Words[i]}\". (line {lineNumber})");
					Words.RemoveAt(i--);
					continue;
				}

				if (Words[i].Command != 'F')
					continue;

				State.Feed = Words[i].Parameter;
				if (State.Unit == ParseUnit.Imperial)
					State.Feed *= 25.4;
				Words.RemoveAt(i--);
				continue;
			}

			for (int i = 0; i < Words.Count; i++)
			{
				if (Words[i].Command == 'M')
				{
					int param = (int)Words[i].Parameter;

					if (param != Words[i].Parameter || param < 0)
						throw new ParseException("M code can only have positive integer parameters", lineNumber);

					Commands.Add(new MCode() { Code = param, LineNumber = lineNumber });

					Words.RemoveAt(i);
					i--;
					continue;
				}

				if (Words[i].Command == 'S')
				{
					double param = Words[i].Parameter;

					if (param < 0)
						Warnings.Add($"spindle speed must be positive. (line {lineNumber})");

					Commands.Add(new Spindle() { Speed = Math.Abs(param), LineNumber = lineNumber });

					Words.RemoveAt(i);
					i--;
					continue;
				}

				if (Words[i].Command == 'G' && !MotionCommands.Contains(Words[i].Parameter))
				{
					#region UnitPlaneDistanceMode

					double param = Words[i].Parameter;

					if (param == 90)
					{
						State.DistanceMode = ParseDistanceMode.Absolute;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 91)
					{
						State.DistanceMode = ParseDistanceMode.Incremental;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 90.1)
					{
						State.ArcDistanceMode = ParseDistanceMode.Absolute;
						Words.RemoveAt(i);
						continue;
					}
					if (param == 91.1)
					{
						State.ArcDistanceMode = ParseDistanceMode.Incremental;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 21)
					{
						State.Unit = ParseUnit.Metric;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 20)
					{
						State.Unit = ParseUnit.Imperial;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 17)
					{
						State.Plane = ArcPlane.XY;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 18)
					{
						State.Plane = ArcPlane.ZX;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 19)
					{
						State.Plane = ArcPlane.YZ;
						Words.RemoveAt(i);
						i--;
						continue;
					}
					if (param == 4)
					{
						if (Words.Count >= 2 && Words[i + 1].Command == 'P')
						{
							if (Words[i + 1].Parameter < 0)
								Warnings.Add($"dwell time must be positive. (line {lineNumber})");

							Commands.Add(new Dwell() { Seconds = Math.Abs(Words[i + 1].Parameter), LineNumber = lineNumber });
							Words.RemoveAt(i + 1);
							Words.RemoveAt(i);
							i--;
							continue;
						}
					}

					Warnings.Add($"ignoring unknown command G{param}. (line {lineNumber})");
					Words.RemoveAt(i--);
					#endregion
				}
			}

			if (Words.Count == 0)
				return;

			int MotionMode = State.LastMotionMode;

			if (Words.First().Command == 'G')
			{
				MotionMode = (int)Words.First().Parameter;
				State.LastMotionMode = MotionMode;
				Words.RemoveAt(0);
			}

			if (MotionMode < 0)
				throw new ParseException("no motion mode active", lineNumber);

			double UnitMultiplier = (State.Unit == ParseUnit.Metric) ? 1 : 25.4;

			Vector3 EndPos = State.Position;

			if (State.DistanceMode == ParseDistanceMode.Incremental && State.PositionValid.Any(isValid => !isValid))
			{
				throw new ParseException("incremental motion is only allowed after an absolute position has been established (eg. with \"G90 G0 X0 Y0 Z5\")", lineNumber);
			}

			if ((MotionMode == 2 || MotionMode == 3) && State.PositionValid.Any(isValid => !isValid))
			{
				throw new ParseException("arcs (G2/G3) are only allowed after an absolute position has been established (eg. with \"G90 G0 X0 Y0 Z5\")", lineNumber);
			}

			#region FindEndPos
			{
				int Incremental = (State.DistanceMode == ParseDistanceMode.Incremental) ? 1 : 0;

				for (int i = 0; i < Words.Count; i++)
				{
					if (Words[i].Command != 'X')
						continue;
					EndPos.X = Words[i].Parameter * UnitMultiplier + Incremental * EndPos.X;
					Words.RemoveAt(i);
					State.PositionValid[0] = true;
					break;
				}

				for (int i = 0; i < Words.Count; i++)
				{
					if (Words[i].Command != 'Y')
						continue;
					EndPos.Y = Words[i].Parameter * UnitMultiplier + Incremental * EndPos.Y;
					Words.RemoveAt(i);
					State.PositionValid[1] = true;
					break;
				}

				for (int i = 0; i < Words.Count; i++)
				{
					if (Words[i].Command != 'Z')
						continue;
					EndPos.Z = Words[i].Parameter * UnitMultiplier + Incremental * EndPos.Z;
					Words.RemoveAt(i);
					State.PositionValid[2] = true;
					break;
				}
			}
			#endregion

			if (MotionMode != 0 && State.Feed <= 0)
			{
				throw new ParseException("feed rate undefined", lineNumber);
			}

			if (MotionMode == 1 && State.PositionValid.Any(isValid => !isValid))
			{
				Warnings.Add($"a feed move is used before an absolute position is established, height maps will not be applied to this motion. (line {lineNumber})");
			}

			if (MotionMode <= 1)
			{
				if (Words.Count > 0)
					Warnings.Add($"motion command must be last in line (ignoring unused words {string.Join(" ", Words)} in block). (line {lineNumber})");

				Line motion = new Line();
				motion.Start = State.Position;
				motion.End = EndPos;
				motion.Feed = State.Feed;
				motion.Rapid = MotionMode == 0;
				motion.LineNumber = lineNumber;
				State.PositionValid.CopyTo(motion.PositionValid, 0);

				Commands.Add(motion);
				State.Position = EndPos;
				return;
			}

			double U, V;

			bool IJKused = false;

			switch (State.Plane)
			{
				default:
					U = State.Position.X;
					V = State.Position.Y;
					break;
				case ArcPlane.YZ:
					U = State.Position.Y;
					V = State.Position.Z;
					break;
				case ArcPlane.ZX:
					U = State.Position.Z;
					V = State.Position.X;
					break;
			}

			#region FindIJK
			{
				int ArcIncremental = (State.ArcDistanceMode == ParseDistanceMode.Incremental) ? 1 : 0;

				for (int i = 0; i < Words.Count; i++)
				{
					if (Words[i].Command != 'I')
						continue;

					switch (State.Plane)
					{
						case ArcPlane.XY:
							U = Words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.X;
							break;
						case ArcPlane.YZ:
							throw new ParseException("current plane is YZ, I word is invalid", lineNumber);
						case ArcPlane.ZX:
							V = Words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.X;
							break;
					}

					IJKused = true;
					Words.RemoveAt(i);
					break;
				}

				for (int i = 0; i < Words.Count; i++)
				{
					if (Words[i].Command != 'J')
						continue;

					switch (State.Plane)
					{
						case ArcPlane.XY:
							V = Words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.Y;
							break;
						case ArcPlane.YZ:
							U = Words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.Y;
							break;
						case ArcPlane.ZX:
							throw new ParseException("current plane is ZX, J word is invalid", lineNumber);
					}

					IJKused = true;
					Words.RemoveAt(i);
					break;
				}

				for (int i = 0; i < Words.Count; i++)
				{
					if (Words[i].Command != 'K')
						continue;

					switch (State.Plane)
					{
						case ArcPlane.XY:
							throw new ParseException("current plane is XY, K word is invalid", lineNumber);
						case ArcPlane.YZ:
							V = Words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.Z;
							break;
						case ArcPlane.ZX:
							U = Words[i].Parameter * UnitMultiplier + ArcIncremental * State.Position.Z;
							break;
					}

					IJKused = true;
					Words.RemoveAt(i);
					break;
				}
			}
			#endregion

			#region ResolveRadius
			for (int i = 0; i < Words.Count; i++)
			{
				if (Words[i].Command != 'R')
					continue;

				if (IJKused)
					throw new ParseException("both IJK and R notation used", lineNumber);

				if (State.Position == EndPos)
					throw new ParseException("arcs in R-notation must have non-coincident start and end points", lineNumber);

				double Radius = Words[i].Parameter * UnitMultiplier;

				if (Radius == 0)
					throw new ParseException("radius can't be zero", lineNumber);

				double A, B;

				switch (State.Plane)
				{
					default:
						A = EndPos.X;
						B = EndPos.Y;
						break;
					case ArcPlane.YZ:
						A = EndPos.Y;
						B = EndPos.Z;
						break;
					case ArcPlane.ZX:
						A = EndPos.Z;
						B = EndPos.X;
						break;
				}

				A -= U;     //(AB) = vector from start to end of arc along the axes of the current plane
				B -= V;

				//see grbl/gcode.c
				double h_x2_div_d = 4.0 * (Radius * Radius) - (A * A + B * B);
				if (h_x2_div_d < 0)
				{
					throw new ParseException("arc radius too small to reach both ends", lineNumber);
				}

				h_x2_div_d = -Math.Sqrt(h_x2_div_d) / Math.Sqrt(A * A + B * B);

				if (MotionMode == 3 ^ Radius < 0)
				{
					h_x2_div_d = -h_x2_div_d;
				}

				U += 0.5 * (A - (B * h_x2_div_d));
				V += 0.5 * (B + (A * h_x2_div_d));

				Words.RemoveAt(i);
				break;
			}
			#endregion

			if (Words.Count > 0)
				Warnings.Add($"motion command must be last in line (ignoring unused words {string.Join(" ", Words)} in block). (line {lineNumber})");

			Arc arc = new Arc();
			arc.Start = State.Position;
			arc.End = EndPos;
			arc.Feed = State.Feed;
			arc.Direction = (MotionMode == 2) ? ArcDirection.CW : ArcDirection.CCW;
			arc.U = U;
			arc.V = V;
			arc.LineNumber = lineNumber;
			arc.Plane = State.Plane;

			Commands.Add(arc);
			State.Position = EndPos;
			return;
		}

19 Source : gps2bd.cs
with MIT License
from 734843327

private static double transformLat(double lat, double lon)
        {
            double ret = -100.0 + 2.0 * lat + 3.0 * lon + 0.2 * lon * lon + 0.1 * lat * lon + 0.2 * Math.Sqrt(Math.Abs(lat));
            ret += (20.0 * Math.Sin(6.0 * lat * pi) + 20.0 * Math.Sin(2.0 * lat * pi)) * 2.0 / 3.0;
            ret += (20.0 * Math.Sin(lon * pi) + 40.0 * Math.Sin(lon / 3.0 * pi)) * 2.0 / 3.0;
            ret += (160.0 * Math.Sin(lon / 12.0 * pi) + 320 * Math.Sin(lon * pi / 30.0)) * 2.0 / 3.0;
            return ret;
        }

19 Source : gps2bd.cs
with MIT License
from 734843327

private static double transformLon(double lat, double lon)
        {
            double ret = 300.0 + lat + 2.0 * lon + 0.1 * lat * lat + 0.1 * lat * lon + 0.1 * Math.Sqrt(Math.Abs(lat));
            ret += (20.0 * Math.Sin(6.0 * lat * pi) + 20.0 * Math.Sin(2.0 * lat * pi)) * 2.0 / 3.0;
            ret += (20.0 * Math.Sin(lat * pi) + 40.0 * Math.Sin(lat / 3.0 * pi)) * 2.0 / 3.0;
            ret += (150.0 * Math.Sin(lat / 12.0 * pi) + 300.0 * Math.Sin(lat / 30.0 * pi)) * 2.0 / 3.0;
            return ret;
        }

19 Source : Mathd.cs
with MIT License
from 734843327

public static double Abs(double d) {
            return Math.Abs(d);
        }

19 Source : DMSkinComplexWindow.cs
with MIT License
from 944095635

private IntPtr WmNCHitTest(IntPtr lParam, ref bool handled)
        {
            this.mousePoint.X = (int)(short)(lParam.ToInt32() & 0xFFFF);
            this.mousePoint.Y = (int)(short)(lParam.ToInt32() >> 16);
            if (ResizeMode == ResizeMode.CanResize || ResizeMode == ResizeMode.CanResizeWithGrip)
            {
                handled = true;
                //if (Math.Abs(this.mousePoint.Y - this.Top) <= this.cornerWidth
                //    && Math.Abs(this.mousePoint.X - this.Left) <= this.cornerWidth)
                //{ // 左上 
                //    return new IntPtr((int)Win32.HitTest.HTTOPLEFT);
                //}
                //else if (Math.Abs(this.ActualHeight + this.Top - this.mousePoint.Y) <= this.cornerWidth
                //    && Math.Abs(this.mousePoint.X - this.Left) <= this.cornerWidth)
                //{ // 左下  
                //    return new IntPtr((int)Win32.HitTest.HTBOTTOMLEFT);
                //}
                //else if (Math.Abs(this.mousePoint.Y - this.Top) <= this.cornerWidth
                //    && Math.Abs(this.ActualWidth + this.Left - this.mousePoint.X) <= this.cornerWidth)
                //{ //右上
                //    return new IntPtr((int)Win32.HitTest.HTTOPRIGHT);
                //}
                //else if (Math.Abs(this.mousePoint.X - this.Left) <= 30)
                //{ // 左侧边框
                //    return new IntPtr((int)Win32.HitTest.HTLEFT);
                //}
                //else if (Math.Abs(this.mousePoint.Y - this.Top) <= 30)
                //{ // 顶部  
                //    return new IntPtr((int)Win32.HitTest.HTTOP);
                //}
                if (Math.Abs(this.ActualWidth + this.Left - this.mousePoint.X) <= this.cornerWidth
                    && Math.Abs(this.ActualHeight + this.Top - this.mousePoint.Y) <= this.cornerWidth)
                { // 右下 
                    return new IntPtr((int)HitTest.HTBOTTOMRIGHT);
                }
                else if (Math.Abs(this.ActualWidth + this.Left - this.mousePoint.X) <= 4 && Math.Abs(this.mousePoint.Y - this.Top) > 50)
                { // 右  
                    return new IntPtr((int)HitTest.HTRIGHT);
                }
                else if (Math.Abs(this.ActualHeight + this.Top - this.mousePoint.Y) <= 4)
                { // 底部  
                    return new IntPtr((int)HitTest.HTBOTTOM);
                }
            }
            handled = false;
            return IntPtr.Zero;
        }

19 Source : CloudSection.cs
with GNU Lesser General Public License v3.0
from 9and3

protected override void SolveInstance(IGH_DataAccess DA) {

            // Input
            var cgh = new GH_Cloud();
            DA.GetData(0, ref cgh);

            List<Plane> planes = new List<Plane>(); ;
            DA.GetDataList(1, planes);

            double distance = 1;
            DA.GetData(2, ref distance);


            DA.SetData(0, new GH_Cloud(SectionCloud(cgh.Value,planes,Math.Abs(distance), distance < 0)));


        }

19 Source : CloudSection.cs
with GNU Lesser General Public License v3.0
from 9and3

public PointCloud SectionCloud(PointCloud cloud, List<Plane> planes,  double tol = 0.001, bool project = false) {

            bool[] flags = new bool[cloud.Count];
            int[] cID = new int[cloud.Count];

          

            int count = 1;
            foreach (Plane plane in planes) {

                   double[] eq = plane.GetPlaneEquation();
                   double denom = 1 / Math.Sqrt(eq[0] * eq[0] + eq[1] * eq[1] + eq[2] * eq[2]);


                System.Threading.Tasks.Parallel.For(0, cloud.Count, i => {
                    // for (int i = 0; i < cloud_.Count; i++) {

                    if (flags[i]) return;

                    if (Math.Abs(FastPlaneToPt(denom, eq[0], eq[1], eq[2], eq[3], cloud[i].Location)) <= tol) {
                        flags[i] = true;
                        cID[i] = count;
                    }


                });

                count++;
            }

            int cc = 0;
            List<int> idList = new List<int>();
            for (int i = 0; i < cloud.Count; i++) {
                //bool f = inverse ? !flags[i] : flags[i];
                if (flags[i]) {
                    idList.Add(i);
                    cc++;
                }
            }

            int[] idArray = idList.ToArray();
            Point3d[] points = new Point3d[cc];
            Vector3d[] normals = new Vector3d[cc];
            Color[] colors = new Color[cc];

            System.Threading.Tasks.Parallel.For(0, idArray.Length, i => {


                int id = idArray[i];
                var p = cloud[(int)id];
                points[i] = p.Location;
                normals[i] = p.Normal;
                colors[i] = p.Color;

            });

            PointCloud croppedCloud = new PointCloud();
            croppedCloud.AddRange(points, normals, colors);

            //PointCloud croppedCloud = new PointCloud();
            //for (int i = 0; i < cloud.Count; i++) {
            //    //bool f = inverse ? !flags[i] : flags[i];
            //    bool f =  flags[i];
            //    if (f) {
            //        if (cloud.ContainsNormals) {
            //            croppedCloud.Add(cloud[i].Location, cloud[i].Normal, cloud[i].Color);
            //        } else {
            //            croppedCloud.Add(cloud[i].Location, cloud[i].Color);
            //        }
            //    }
            //}


            if (project) {
               // if (planes.Count == 1) {
                    croppedCloud.Transform(Rhino.Geometry.Transform.PlanarProjection(planes[0]));
                //} else {

                //    for (int i = 0; i < cloud.Count; i++) {

                //    }
                }
                return croppedCloud;

            }

19 Source : Geometry.cs
with GNU Lesser General Public License v3.0
from 9and3

public static Tuple<List<Polyline>,List<Polyline>,List<Polyline>> BooleanIntersection(List<Curve> curves, List<Curve> cutters, double dist, double scale =1e10) {
            //http://www.angusj.com/delphi/clipper/doreplacedentation/Docs/Overview/Example.htm

            //  A = NGonsCore.Geometry.Polyline3D.Boolean(ClipType.ctIntersection, polylines, cutters, Plane.WorldXY, 1 / 1e10, true);

            //this.Component.Message = "Boolean Intersection";



            List<Polyline> output = new List<Polyline>();


            List<Polyline> cutters_ = CurvesToPolylines(cutters, dist);

            List<Polyline> innerPolygons = new List<Polyline>();
            List<Polyline> edgePolygons = new List<Polyline>();
            List<Polyline> edgePolygons_ = new List<Polyline>();



            for (int j = 0; j < curves.Count; j++) {

                Polyline polyline = CurveToPolyline(curves[j]);

                Clipper642.Clipper clipper = new Clipper642.Clipper();

                var cutter = PolylineToIntPoints(cutters_, scale);
                clipper.AddPaths(cutter, PolyType.ptClip, true);

                var input = PolylineToIntPoint(polyline, scale);
                clipper.AddPath(input, PolyType.ptSubject, true);

                /*
                foreach(IntPoint intpt in input){
                  NGonsCore.Clipper642.Clipper.PointInPolygon(intpt, cutter);
                }
           */


                List<List<IntPoint>> solution = new List<List<IntPoint>>();
                clipper.Execute(ClipType.ctIntersection, solution);

                solution = Clipper642.Clipper.SimplifyPolygons(solution, PolyFillType.pftEvenOdd);

                List<Polyline> polys = IntPointToPolylines(solution, scale);
                output.AddRange(polys);



                if (polys.Count > 0) {
                    if (polys.Count == polyline.Count) {
                        edgePolygons.AddRange(polys);
                        edgePolygons_.Add(polyline);
                    } else {
                        if (Math.Abs((polys[0].Length - polyline.Length)) < 0.01 && polys[0].Count == polyline.Count) {
                            innerPolygons.Add(polys[0]);
                            //innerPolygons.Add(j);
                        } else {
                            edgePolygons.AddRange(polys);
                            edgePolygons_.Add(polyline);
                            // edgePolygons.Add(j);
                        }
                    }
                }

            }
            //innerPolylines = innerPolygons;
            //edgePolylinesCut = edgePolygons;
            //edgePolylines = edgePolygons_;

            //   A = cutters_;

            return new Tuple<List<Polyline>, List<Polyline>, List<Polyline>>(innerPolygons, edgePolygons, edgePolygons_);





        }

19 Source : Geometry.cs
with GNU Lesser General Public License v3.0
from 9and3

public static Polyline[] Offset(this IEnumerable<Polyline> polylines, double distance) {

            Polyline[] polylinesOffset = new Polyline[polylines.Count()];




            if (distance != 0) {
                List<Polyline> c0;
                List<Polyline> c1;

                int i = 0;

                foreach(Polyline p in polylines) { 


                    Geometry.Polyline3D.Offset(p, Math.Abs(distance), out c0, out c1);

                    if (distance < 0) {
                        polylinesOffset[i]=(c1[0]);
                    } else {
                        polylinesOffset[i] = (c0[0]);
                    }

                    i++;

                }


                return polylinesOffset;

            }

            return polylines.ToArray();


        }

19 Source : AccelDataXYComponential.cs
with MIT License
from a1xd

public void CalculateDots(double x, double y, double timeInMs)
        {
            var outX = Math.Abs(x) / timeInMs;
            var outY = Math.Abs(y) / timeInMs;

            (var inXVelocity, var xSensitivity, var xGain) = X.FindPointValuesFromOut(outX);
            XPoints.Velocity.Set(inXVelocity, outX);
            XPoints.Sensitivity.Set(inXVelocity, xSensitivity);
            XPoints.Gain.Set(inXVelocity, xGain);

            (var inYVelocity, var ySensitivity, var yGain) = Y.FindPointValuesFromOut(outY);
            YPoints.Velocity.Set(inYVelocity, outY);
            YPoints.Sensitivity.Set(inYVelocity, ySensitivity);
            YPoints.Gain.Set(inYVelocity, yGain);

        }

19 Source : AccelDataXYDirectional.cs
with MIT License
from a1xd

public void CalculateDots(double x, double y, double timeInMs)
        {
            var outVelocity = AccelCalculator.Velocity(x, y, timeInMs);
            var outAngle = Math.Atan2(Math.Abs(y),Math.Abs(x));
            var nearestAngleDivision = AccelCalculator.NearestAngleDivision(outAngle);
            var data = AngleToData[nearestAngleDivision];
            var index = data.GetVelocityIndex(outVelocity);
            var inVelocity = data.VelocityPoints.ElementAt(index).Key;
            var xPoints = X.ValuesAtIndex(index);
            var yPoints = Y.ValuesAtIndex(index);
            XPoints.Sensitivity.Set(inVelocity, xPoints.Item1);
            XPoints.Velocity.Set(inVelocity, xPoints.Item2);
            XPoints.Gain.Set(inVelocity, xPoints.Item3);
            YPoints.Sensitivity.Set(inVelocity, yPoints.Item1);
            YPoints.Velocity.Set(inVelocity, yPoints.Item2);
            YPoints.Gain.Set(inVelocity, yPoints.Item3);
        }

19 Source : AccelCalculator.cs
with MIT License
from a1xd

public static double Magnitude(double x, double y)
        {
            if (x == 0)
            {
                return Math.Abs(y);
            }

            if (y == 0)
            {
                return Math.Abs(x);
            }

            return Math.Sqrt(x * x + y * y);
        }

19 Source : AccelCalculator.cs
with MIT License
from a1xd

private SimulatedMouseInput SimulateAngledInput(double angle, double magnitude)
        {
            SimulatedMouseInput mouseInputData;

            var moveX = Math.Round(magnitude * Math.Cos(angle), 4);
            var moveY = Math.Round(magnitude * Math.Sin(angle), 4);

            if (moveX == 0)
            {
                mouseInputData.x = 0;
                mouseInputData.y = (int)Math.Ceiling(moveY);
                mouseInputData.time = mouseInputData.y / moveY;
            }
            else if (moveY == 0)
            {
                mouseInputData.x = (int)Math.Ceiling(moveX);
                mouseInputData.y = 0;
                mouseInputData.time = mouseInputData.x / moveX;
            }
            else
            {
                var ratio =  moveY / moveX;
                int ceilX = 0;
                int ceilY = 0;
                double biggerX = 0;
                double biggerY = 0;
                double roundedBiggerX = 0;
                double roundedBiggerY = 0;
                double roundedRatio = -1;
                double factor = 10;

                while (Math.Abs(roundedRatio - ratio) > 0.01 &&
                    biggerX < 25000 &&
                    biggerY < 25000)
                {
                    roundedBiggerX = Math.Floor(biggerX);
                    roundedBiggerY = Math.Floor(biggerY);
                    ceilX = Convert.ToInt32(roundedBiggerX);
                    ceilY = Convert.ToInt32(roundedBiggerY);
                    roundedRatio =  ceilX > 0 ? ceilY / ceilX : -1;
                    biggerX = moveX * factor;
                    biggerY = moveY * factor;
                    factor *= 10;
                }

                var ceilMagnitude = Magnitude(ceilX, ceilY);
                var timeFactor = ceilMagnitude / magnitude;

                mouseInputData.x = ceilX;
                mouseInputData.y = ceilY;
                mouseInputData.time = timeFactor;

                if (mouseInputData.x == 1 && mouseInputData.time == 1)
                {
                    Console.WriteLine("Oops");
                }

            }

            mouseInputData.velocity = DecimalCheck(Velocity(mouseInputData.x, mouseInputData.y, mouseInputData.time));

            if (double.IsNaN(mouseInputData.velocity))
            {
                Console.WriteLine("oopsie");
            }

            mouseInputData.angle = angle;
            return mouseInputData;
        }

19 Source : ExtensionMethods.cs
with MIT License
from Abdesol

public static bool IsClose(this double d1, double d2)
		{
			if (d1 == d2) // required for infinities
				return true;
			return Math.Abs(d1 - d2) < Epsilon;
		}

19 Source : BackgroundGeometryBuilder.cs
with MIT License
from Abdesol

static IEnumerable<Rect> ProcessTextLines(TextView textView, VisualLine visualLine, int segmentStartVC, int segmentEndVC)
		{
			TextLine lastTextLine = visualLine.TextLines.Last();
			Vector scrollOffset = textView.ScrollOffset;

			for (int i = 0; i < visualLine.TextLines.Count; i++) {
				TextLine line = visualLine.TextLines[i];
				double y = visualLine.GetTextLineVisualYPosition(line, VisualYPosition.LineTop);
				int visualStartCol = visualLine.GetTextLineVisualStartColumn(line);
				int visualEndCol = visualStartCol + line.Length;
				if (line == lastTextLine)
					visualEndCol -= 1; // 1 position for the TextEndOfParagraph
				else
					visualEndCol -= line.TrailingWhitespaceLength;

				if (segmentEndVC < visualStartCol)
					break;
				if (lastTextLine != line && segmentStartVC > visualEndCol)
					continue;
				int segmentStartVCInLine = Math.Max(segmentStartVC, visualStartCol);
				int segmentEndVCInLine = Math.Min(segmentEndVC, visualEndCol);
				y -= scrollOffset.Y;
				Rect lastRect = Rect.Empty;
				if (segmentStartVCInLine == segmentEndVCInLine) {
					// GetTextBounds crashes for length=0, so we'll handle this case with GetDistanceFromCharacterHit
					// We need to return a rectangle to ensure empty lines are still visible
					double pos = visualLine.GetTextLineVisualXPosition(line, segmentStartVCInLine);
					pos -= scrollOffset.X;
					// The following special cases are necessary to get rid of empty rectangles at the end of a TextLine if "Show Spaces" is active.
					// If not excluded once, the same rectangle is calculated (and added) twice (since the offset could be mapped to two visual positions; end/start of line), if there is no trailing whitespace.
					// Skip this TextLine segment, if it is at the end of this line and this line is not the last line of the VisualLine and the selection continues and there is no trailing whitespace.
					if (segmentEndVCInLine == visualEndCol && i < visualLine.TextLines.Count - 1 && segmentEndVC > segmentEndVCInLine && line.TrailingWhitespaceLength == 0)
						continue;
					if (segmentStartVCInLine == visualStartCol && i > 0 && segmentStartVC < segmentStartVCInLine && visualLine.TextLines[i - 1].TrailingWhitespaceLength == 0)
						continue;
					lastRect = new Rect(pos, y, textView.EmptyLineSelectionWidth, line.Height);
				} else {
					if (segmentStartVCInLine <= visualEndCol) {
						foreach (TextBounds b in line.GetTextBounds(segmentStartVCInLine, segmentEndVCInLine - segmentStartVCInLine)) {
							double left = b.Rectangle.Left - scrollOffset.X;
							double right = b.Rectangle.Right - scrollOffset.X;
							if (!lastRect.IsEmpty)
								yield return lastRect;
							// left>right is possible in RTL languages
							lastRect = new Rect(Math.Min(left, right), y, Math.Abs(right - left), line.Height);
						}
					}
				}
				// If the segment ends in virtual space, extend the last rectangle with the rectangle the portion of the selection
				// after the line end.
				// Also, when word-wrap is enabled and the segment continues into the next line, extend lastRect up to the end of the line.
				if (segmentEndVC > visualEndCol) {
					double left, right;
					if (segmentStartVC > visualLine.VisualLengthWithEndOfLineMarker) {
						// segmentStartVC is in virtual space
						left = visualLine.GetTextLineVisualXPosition(lastTextLine, segmentStartVC);
					} else {
						// Otherwise, we already processed the rects from segmentStartVC up to visualEndCol,
						// so we only need to do the remainder starting at visualEndCol.
						// For word-wrapped lines, visualEndCol doesn't include the whitespace hidden by the wrap,
						// so we'll need to include it here.
						// For the last line, visualEndCol already includes the whitespace.
						left = (line == lastTextLine ? line.WidthIncludingTrailingWhitespace : line.Width);
					}
					if (line != lastTextLine || segmentEndVC == int.MaxValue) {
						// If word-wrap is enabled and the segment continues into the next line,
						// or if the extendToFullWidthAtLineEnd option is used (segmentEndVC == int.MaxValue),
						// we select the full width of the viewport.
						right = Math.Max(((IScrollInfo)textView).ExtentWidth, ((IScrollInfo)textView).ViewportWidth);
					} else {
						right = visualLine.GetTextLineVisualXPosition(lastTextLine, segmentEndVC);
					}
					Rect extendSelection = new Rect(Math.Min(left, right), y, Math.Abs(right - left), line.Height);
					if (!lastRect.IsEmpty) {
						if (extendSelection.IntersectsWith(lastRect)) {
							lastRect.Union(extendSelection);
							yield return lastRect;
						} else {
							// If the end of the line is in an RTL segment, keep lastRect and extendSelection separate.
							yield return lastRect;
							yield return extendSelection;
						}
					} else
						yield return extendSelection;
				} else
					yield return lastRect;
			}
		}

19 Source : BackgroundGeometryBuilder.cs
with MIT License
from Abdesol

public void AddRectangle(double left, double top, double right, double bottom)
		{
			if (!top.IsClose(lastBottom)) {
				CloseFigure();
			}
			if (figure == null) {
				figure = new PathFigure();
				figure.StartPoint = new Point(left, top + cornerRadius);
				if (Math.Abs(left - right) > cornerRadius) {
					figure.Segments.Add(MakeArc(left + cornerRadius, top, SweepDirection.Clockwise));
					figure.Segments.Add(MakeLineSegment(right - cornerRadius, top));
					figure.Segments.Add(MakeArc(right, top + cornerRadius, SweepDirection.Clockwise));
				}
				figure.Segments.Add(MakeLineSegment(right, bottom - cornerRadius));
				insertionIndex = figure.Segments.Count;
				//figure.Segments.Add(MakeArc(left, bottom - cornerRadius, SweepDirection.Clockwise));
			} else {
				if (!lastRight.IsClose(right)) {
					double cr = right < lastRight ? -cornerRadius : cornerRadius;
					SweepDirection dir1 = right < lastRight ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
					SweepDirection dir2 = right < lastRight ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
					figure.Segments.Insert(insertionIndex++, MakeArc(lastRight + cr, lastBottom, dir1));
					figure.Segments.Insert(insertionIndex++, MakeLineSegment(right - cr, top));
					figure.Segments.Insert(insertionIndex++, MakeArc(right, top + cornerRadius, dir2));
				}
				figure.Segments.Insert(insertionIndex++, MakeLineSegment(right, bottom - cornerRadius));
				figure.Segments.Insert(insertionIndex, MakeLineSegment(lastLeft, lastTop + cornerRadius));
				if (!lastLeft.IsClose(left)) {
					double cr = left < lastLeft ? cornerRadius : -cornerRadius;
					SweepDirection dir1 = left < lastLeft ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
					SweepDirection dir2 = left < lastLeft ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
					figure.Segments.Insert(insertionIndex, MakeArc(lastLeft, lastBottom - cornerRadius, dir1));
					figure.Segments.Insert(insertionIndex, MakeLineSegment(lastLeft - cr, lastBottom));
					figure.Segments.Insert(insertionIndex, MakeArc(left + cr, lastBottom, dir2));
				}
			}
			this.lastTop = top;
			this.lastBottom = bottom;
			this.lastLeft = left;
			this.lastRight = right;
		}

19 Source : BackgroundGeometryBuilder.cs
with MIT License
from Abdesol

public void CloseFigure()
		{
			if (figure != null) {
				figure.Segments.Insert(insertionIndex, MakeLineSegment(lastLeft, lastTop + cornerRadius));
				if (Math.Abs(lastLeft - lastRight) > cornerRadius) {
					figure.Segments.Insert(insertionIndex, MakeArc(lastLeft, lastBottom - cornerRadius, SweepDirection.Clockwise));
					figure.Segments.Insert(insertionIndex, MakeLineSegment(lastLeft + cornerRadius, lastBottom));
					figure.Segments.Insert(insertionIndex, MakeArc(lastRight - cornerRadius, lastBottom, SweepDirection.Clockwise));
				}

				figure.IsClosed = true;
				figures.Add(figure);
				figure = null;
			}
		}

19 Source : LoginInformationValidator.cs
with MIT License
from Abdulrhman5

public (bool IsSuccess, LoginInformationDto? LoginInformation) ValidateLoginInfo(ResourceOwnerPreplacedwordValidationContext context)
        {
            var loginInfo = context?.Request?.Raw?["loginInfo"];

            if (context.Request?.Client?.ClientId == "AdminBff")
                return (true, new LoginInformationDto
                {
                    Imei = null,
                    Lareplacedude = null,
                    Longitude = null
                });

            if(loginInfo == null)
            {
                return (false, null);
            }
            var query = HttpUtility.ParseQueryString(loginInfo);
            var lon = query.Get("lon");
            double dLon;
            if (lon.IsNullOrEmpty())
            {
                return (false, null);
            }

            if (!double.TryParse(lon, out dLon))
            {
                return (false, null);
            }

            var lat = query.Get("lat");
            double dLat;
            if (lat.IsNullOrEmpty())
            {
                return (false, null);
            }

            if (!double.TryParse(lat, out dLat))
            {
                return (false, null);
            }

            // if dLon is not in this range -180 <= dLon <= +180
            // or of dLat is not in this range -90 <= dLat <= +90
            // return error
            if (Math.Abs(dLon) > 180 || Math.Abs(dLat) > 90)
            {
                return (false, null);
            }

            var imei = query.Get("Imei");
            if (imei.IsNullOrEmpty())
            {
                return (false, null);
            }

            return (true, new LoginInformationDto
            {
                Imei = imei,
                Lareplacedude = dLat,
                Longitude = dLon
            });
        }

19 Source : DateTimeExtensions.cs
with Apache License 2.0
from abist-co-ltd

public static string GetRelativeTime(this DateTime time)
        {
            var delta = new TimeSpan(DateTime.UtcNow.Ticks - time.Ticks);

            if (Math.Abs(delta.TotalDays) > 1.0)
            {
                return (int)Math.Abs(delta.TotalDays) + " days ago";
            }
            else if (Math.Abs(delta.TotalHours) > 1.0)
            {
                return (int)Math.Abs(delta.TotalHours) + " hours ago";
            }
            else if (Math.Abs(delta.TotalMinutes) > 1.0)
            {
                return (int)Math.Abs(delta.TotalMinutes) + " minutes ago";
            }
            else
            {
                return (int)Math.Abs(delta.TotalSeconds) + " seconds ago";
            }
        }

19 Source : DoubleExtensions.cs
with Apache License 2.0
from abist-co-ltd

public static bool Approximately(this double number, double other, double tolerance)
        {
            return Math.Abs(number - other) <= tolerance;
        }

19 Source : CustomWaterfallRubberBandXyZoomModifier.cs
with MIT License
from ABTSoftware

public override void OnModifierMouseUp(ModifierMouseArgs e)
        {
            ModifierSurface.ReleaseMouseCapture();
            endPoint = GetPointRelativeTo(e.MousePoint, ModifierSurface);
            OnAttached();

            if (Math.Abs(startPoint.X - endPoint.X) > 10)
            {
                int i = 0;
                foreach (CustomWaterfallNumericAxis YAxis in ParentSurface.XAxes)
                {

                    YAxis.Zoom(startPoint.X + i * 2, endPoint.X + i * 2, TimeSpan.FromMilliseconds(1000));
                    i++;
                }
            }
        }

19 Source : RealTimePerformanceDemoView.xaml.cs
with MIT License
from ABTSoftware

private void OnSciChartRendered(object sender, EventArgs e)
        {
            // Compute the render time
            double frameTime = _stopWatch.ElapsedMilliseconds;
            double delta = frameTime - _lastFrameTime;
            double fps = 1000.0 / delta;
            double fpsAverageBefore = _fpsAverage.Current;

            // Push the fps to the movingaverage, we want to average the FPS to get a more reliable reading
            if (!double.IsInfinity(fps))
            {
                _fpsAverage.Push(fps);
            }

            double fpsAverageAfter = _fpsAverage.Current;

            // Render the fps to the screen
            if (Math.Abs(fpsAverageAfter - fpsAverageBefore) >= 0.1)
                FpsCounter.Text = double.IsNaN(_fpsAverage.Current) ? "-" : string.Format("{0:0}", _fpsAverage.Current);

            // Render the total point count (all series) to the screen
            int numPoints = 3 * _mainSeries.Count;
            PointCount.Text = string.Format("{0:n0}", numPoints);

            if (numPoints > MaxCount)
            {
                this.PauseButton_Click(this, null);
            }

            _lastFrameTime = frameTime;
        }

19 Source : ObjectExtensions.cs
with MIT License
from Accelerider

public static bool EqualsWithinTolerance(this double @this, double other)
        {
            return Math.Abs(@this - other) < Tolerance;
        }

19 Source : LandblockGroup.cs
with GNU Affero General Public License v3.0
from ACEmulator

public int BoundaryDistance(LandblockGroup landblockGroup)
        {
            return (int)Math.Max(
                Math.Abs(xCenter - landblockGroup.xCenter) - (width + landblockGroup.width) / 2.0,
                Math.Abs(yCenter - landblockGroup.yCenter) - (height + landblockGroup.height) / 2.0);
        }

19 Source : NetworkSession.cs
with GNU Affero General Public License v3.0
from ACEmulator

private void VerifyEcho(float clientTime)
        {
            if (session.Player == null || session.logOffRequestTime != DateTime.MinValue)
                return;

            var serverTime = DateTime.UtcNow;

            if (lastClientTime == 0)
            {
                lastClientTime = clientTime;
                lastServerTime = serverTime;
                return;
            }

            var serverTimeDiff = serverTime - lastServerTime;
            var clientTimeDiff = clientTime - lastClientTime;

            var diff = Math.Abs(serverTimeDiff.TotalSeconds - clientTimeDiff);

            if (diff > EchoThreshold && diff - lastDiff > DiffThreshold)
            {
                lastDiff = diff;
                echoDiff++;

                if (echoDiff >= EchoLogInterval)
                    log.Warn($"{session.Player.Name} - TimeSync error: {echoDiff} (diff: {diff})");

                if (echoDiff >= EchoInterval)
                {
                    log.Error($"{session.Player.Name} - disconnected for speedhacking");

                    var actionChain = new ActionChain();
                    actionChain.AddAction(session.Player, () =>
                    {
                        //session.Network.EnqueueSend(new GameMessageBootAccount(session));
                        session.Network.EnqueueSend(new GameMessageSystemChat($"TimeSync: client speed error", ChatMessageType.Broadcast));
                        session.LogOffPlayer();

                        echoDiff = 0;
                        lastDiff = 0;
                        lastClientTime = 0;

                    });
                    actionChain.EnqueueChain();
                }
            }
            else if (echoDiff > 0)
            {
                if (echoDiff > EchoLogInterval)
                    log.Warn($"{session.Player.Name} - Diff: {diff}");

                lastDiff = 0;
                echoDiff = 0;
            }
        }

19 Source : DoubleUtils.cs
with MIT License
from Acorisoft

public static bool AreClose(double value1 , double value2)
		{
			if (value1 == value2)
			{
				return true;
			}
			double num = (Math.Abs(value1) + Math.Abs(value2) + 10.0) * 2.2204460492503131E-16;
			double num2 = value1 - value2;
			if (0.0 - num < num2)
			{
				return num > num2;
			}
			return false;
		}

19 Source : DoubleUtils.cs
with MIT License
from Acorisoft

public static bool IsOne(double value)
		{
			return Math.Abs(value - 1.0) < 2.2204460492503131E-15;
		}

19 Source : DoubleUtils.cs
with MIT License
from Acorisoft

public static bool IsZero(double value)
		{
			return Math.Abs(value) < 2.2204460492503131E-15;
		}

19 Source : HatchCanvas.cs
with GNU Lesser General Public License v3.0
from acnicholas

private DrawingVisual CreateDrawingVisualHatch(Hatch hatch)
        {
            DrawingVisual drawingVisual = new DrawingVisual();
            if (hatch == null) {
                return drawingVisual;
            }

            DrawingContext drawingContext = drawingVisual.RenderOpen();

            double dx = 0;
            double dy = 0;

            var scale = hatch.IsDrafting ? 10 : 1;

            drawingContext.PushClip(new RectangleGeometry(new Rect(0, 0, width, height)));
            drawingContext.DrawRectangle(Brushes.White, null, new Rect(0, 0, width, height));
            drawingContext.PushTransform(new TranslateTransform(width / 2, height / 2));
            drawingContext.DrawEllipse(null, new Pen(Brushes.LightBlue, 1), new Point(0, 0), 10, 10);
            drawingContext.DrawLine(new Pen(Brushes.LightBlue, 1), new Point(-20, 0), new Point(20, 0));
            drawingContext.DrawLine(new Pen(Brushes.LightBlue, 1), new Point(0, -20), new Point(0, 20));
            drawingContext.PushTransform(new ScaleTransform(canvreplacedcale, canvreplacedcale));

            double maxLength = width > height ? width / canvreplacedcale * 2 : height / canvreplacedcale * 2;

            foreach (var fillGrid in hatch.HatchPattern.GetFillGrids()) {
                double scaledSequenceLength = GetDashedLineLength(fillGrid, 1, scale);
                double initialShiftOffset = scaledSequenceLength > 0 ? (int)Math.Floor(maxLength / scaledSequenceLength) * scaledSequenceLength : maxLength;
                if (scaledSequenceLength > maxLength / 4) {
                    initialShiftOffset = scaledSequenceLength * 16;
                }

                var segsInMM = new List<double>();
                foreach (var s in fillGrid.GetSegments()) {
                    segsInMM.Add(s.ToMM(scale));
                }

                if (Math.Abs(fillGrid.Offset) < 0.001) {
                    continue;
                }

                int b = 0;

                var pen = new Pen(Brushes.Black, 1);
                pen.DashStyle = new DashStyle(segsInMM, initialShiftOffset);

                double a = fillGrid.Angle.ToDeg();
                drawingContext.PushTransform(new RotateTransform(-a, fillGrid.Origin.U.ToMM(scale), -fillGrid.Origin.V.ToMM(scale)));

                double replacedulativeShift = 0;

                while (Math.Abs(dy) < maxLength * 2) {
                    b++;
                    if (b > 100) {
                        break;
                    }
                    double x = fillGrid.Origin.U.ToMM(scale) - initialShiftOffset;
                    double y = -fillGrid.Origin.V.ToMM(scale);
                    drawingContext.PushTransform(new TranslateTransform(x + dx, y - dy));
                    drawingContext.DrawLine(pen, new Point(0, 0), new Point(initialShiftOffset * 2, 0));
                    drawingContext.Pop();
                    drawingContext.PushTransform(new TranslateTransform(x - dx, y + dy));
                    drawingContext.DrawLine(pen, new Point(0, 0), new Point(initialShiftOffset * 2, 0));
                    drawingContext.Pop();
                    dx += fillGrid.Shift.ToMM(scale);
                    replacedulativeShift += fillGrid.Shift.ToMM(scale);
                    if (Math.Abs(replacedulativeShift) > scaledSequenceLength) {
                        dx -= scaledSequenceLength;
                        replacedulativeShift = 0;
                    }
                    dy += fillGrid.Offset.ToMM(scale);
                }
                drawingContext.Pop();
                dx = 0;
                dy = 0;
            }
            drawingContext.Pop();
            drawingContext.Pop();
            drawingContext.Pop();

            drawingContext.DrawText(
                new FormattedText(
                    string.Format(System.Globalization.CultureInfo.InvariantCulture, "Scale: {0}", scale * canvreplacedcale),
                    System.Globalization.CultureInfo.InvariantCulture,
                    FlowDirection.LeftToRight,
                    new Typeface("arial"),
                    10,
                    Brushes.LightBlue,
                    1),
                new Point(10, 10));

            drawingContext.Close();
            return drawingVisual;
        }

19 Source : MainControl.xaml.cs
with MIT License
from Actipro

private void OnProductListBoxItemMouseMove(object sender, MouseEventArgs e) {
			ProductListBoxItem item = (ProductListBoxItem)sender;
			if (this.dragPoint != null && item.IsMouseCaptured) {
				// Get the current point and the difference with the drag point
				Point currentPoint = e.GetPosition(item.Parent as Panel);
				double diffX = currentPoint.X - this.dragPoint.Value.X;
				double diffY = currentPoint.Y - this.dragPoint.Value.Y;

				// Ensure the mouse has moved a minimum distance
				if (Math.Abs(diffX) >= 3 || Math.Abs(diffY) >= 3) {
					AnimatedCanvas.SetLeft(item, this.dragLeft + diffX);
					AnimatedCanvas.SetTop(item, this.dragTop + diffY);
					e.Handled = true;
				}
			}
		}

19 Source : HouseholderBase.cs
with BSD 3-Clause "New" or "Revised" License
from ActuarialIntelligence

public double Sign(double value)
        {
            return value / (Math.Abs(value));
        }

19 Source : TestSoftsign.cs
with MIT License
from adamtiger

private double SoftsignFunc(double x)
        {
            return x / (1 + Math.Abs(x));
        }

19 Source : Helper.cs
with MIT License
from adamped

public static double abs(this double value) => Math.Abs(value);

See More Examples