System.Math.Max(double, double)

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

2249 Examples 7

19 View Source File : bdsvd.cs
License : MIT License
Project Creator : 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 View Source File : bdsvd.cs
License : MIT License
Project Creator : 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 View Source File : reflections.cs
License : MIT License
Project Creator : 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 View Source File : reflections.cs
License : MIT License
Project Creator : 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 View Source File : rotations.cs
License : MIT License
Project Creator : 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 View Source File : blas.cs
License : MIT License
Project Creator : 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 View Source File : blas.cs
License : MIT License
Project Creator : 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 View Source File : HSVUtil.cs
License : MIT License
Project Creator : 734843327

public static HsvColor ConvertRgbToHsv(double r, double b, double g)
    {
        double delta, min;
        double h = 0, s, v;

        min = Math.Min(Math.Min(r, g), b);
        v = Math.Max(Math.Max(r, g), b);
        delta = v - min;

        if (v == 0.0)
            s = 0;
        else
            s = delta / v;

        if (s == 0)
            h = 360;
        else
        {
            if (r == v)
                h = (g - b) / delta;
            else if (g == v)
                h = 2 + (b - r) / delta;
            else if (b == v)
                h = 4 + (r - g) / delta;

            h *= 60;
            if (h <= 0.0)
                h += 360;
        }

        HsvColor hsvColor = new HsvColor();
        hsvColor.H = 360 - h;
        hsvColor.S = s;
        hsvColor.V = v / 255;

        return hsvColor;

    }

19 View Source File : ElasticWrapPanel.cs
License : MIT License
Project Creator : 944095635

protected override Size ArrangeOverride(Size finalSize)
        {
            if (_columns == 0) return base.ArrangeOverride(finalSize);
            var columnWidth = Math.Floor(finalSize.Width/_columns);
            var totalHeight = 0d;
            var top = 0d;
            var rowHeight = 0d;
            var overflow = 0d;
            var column = 0;
            var index = 0;
            var overflowAlreadyCount = false;

            foreach (UIElement child in Children)
            {
                // Compute the tile size and position
                child.Arrange(new Rect(columnWidth*column, top, columnWidth, child.DesiredSize.Height));
                column++;
                rowHeight = Children.Count >= _columns
                    ? Math.Max(rowHeight, child.DesiredSize.Height)
                    : Math.Min(rowHeight, child.DesiredSize.Height);
                index++;

                // Check if the current element is at the end of a row and add an height overflow to get enough space for the next elements of the second row
                if (column == _columns && Children.Count != index && (Children.Count - index + 1) <= _columns &&
                    !overflowAlreadyCount)
                {
                    overflow = rowHeight;
                    totalHeight += rowHeight;
                    overflowAlreadyCount = true;
                }
                else
                {
                    if (!overflowAlreadyCount)
                        totalHeight += rowHeight;
                }

                if (column != _columns) continue;
                column = 0;
                top += rowHeight;
                rowHeight = 0;
            }

            if (Children.Count >= _columns)
                totalHeight = totalHeight/_columns + overflow;

            Height = totalHeight;
            finalSize.Height = totalHeight;
            return base.ArrangeOverride(finalSize);
        }

19 View Source File : VirtualizingWrapPanel .cs
License : MIT License
Project Creator : 944095635

private ExtentInfo GetExtentInfo(Size viewPortSize)
        {
            if (_itemsControl == null)
            {
                return new ExtentInfo();
            }

            var itemsPerLine = Math.Max((int)Math.Floor(viewPortSize.Width / ItemWidth), 1);
            var totalLines = (int)Math.Ceiling((double)_itemsControl.Items.Count / itemsPerLine);
            var extentHeight = Math.Max(totalLines * ItemHeight, viewPortSize.Height);

            return new ExtentInfo
            {
                ItemsPerLine = itemsPerLine,
                TotalLines = totalLines,
                ExtentHeight = extentHeight,
                MaxVerticalOffset = extentHeight - viewPortSize.Height,
            };
        }

19 View Source File : VirtualizingWrapPanel .cs
License : MIT License
Project Creator : 944095635

private double Clamp(double value, double min, double max)
        {
            return Math.Min(Math.Max(value, min), max);
        }

19 View Source File : ConsoleProgressBar.cs
License : MIT License
Project Creator : a-luna

public void Report(double value)
        {
            // Make sure value is in [0..1] range
            value = Math.Max(0, Math.Min(1, value));
            Interlocked.Exchange(ref CurrentProgress, value);
        }

19 View Source File : FileTransferProgressBar.cs
License : MIT License
Project Creator : a-luna

public new void Report(double value)
		{
			var ticks = DateTime.Now.Ticks;
			Interlocked.Exchange(ref _lastReportTicks, ticks);

			// Make sure value is in [0..1] range
			value = Math.Max(0, Math.Min(1, value));
			Interlocked.Exchange(ref CurrentProgress, value);
		}

19 View Source File : RecordStream.cs
License : MIT License
Project Creator : a1q123456

[RpcMethod("play")]
        public async Task Play(
     [FromOptionalArgument] string streamName,
     [FromOptionalArgument] double start = -1,
     [FromOptionalArgument] double duration = -1,
     [FromOptionalArgument] bool reset = false)
        {
            _recordFile = new FileStream(_recordService.GetRecordFilename(streamName) + ".flv", FileMode.Open, FileAccess.Read);
            await FlvDemuxer.AttachStream(_recordFile);

            var resetData = new AmfObject
            {
                {"level", "status" },
                {"code", "NetStream.Play.Reset" },
                {"description", "Resetting and playing stream." },
                {"details", streamName }
            };
            var resetStatus = RtmpSession.CreateCommandMessage<OnStatusCommandMessage>();
            resetStatus.InfoObject = resetData;
            await MessageStream.SendMessageAsync(ChunkStream, resetStatus);

            var startData = new AmfObject
            {
                {"level", "status" },
                {"code", "NetStream.Play.Start" },
                {"description", "Started playing." },
                {"details", streamName }
            };

            var startStatus = RtmpSession.CreateCommandMessage<OnStatusCommandMessage>();
            startStatus.InfoObject = startData;
            await MessageStream.SendMessageAsync(ChunkStream, startStatus);
            var bandwidthLimit = new WindowAcknowledgementSizeMessage()
            {
                WindowSize = 500 * 1024
            };
            await RtmpSession.ControlMessageStream.SendMessageAsync(RtmpSession.ControlChunkStream, bandwidthLimit);
            VideoChunkStream = RtmpSession.CreateChunkStream();
            AudioChunkStream = RtmpSession.CreateChunkStream();

            var cts = new CancellationTokenSource();
            _playCts?.Dispose();
            _playCts = cts;
            start = Math.Max(start, 0);
            await SeekAndPlay(start / 1000, cts.Token);
        }

19 View Source File : TextEditor.cs
License : MIT License
Project Creator : Abdesol

public void ScrollTo(int line, int column, VisualYPosition yPositionMode, double referencedVerticalViewPortOffset, double minimumScrollFraction)
		{
			TextView textView = textArea.TextView;
			TextDoreplacedent doreplacedent = textView.Doreplacedent;
			if (scrollViewer != null && doreplacedent != null) {
				if (line < 1)
					line = 1;
				if (line > doreplacedent.LineCount)
					line = doreplacedent.LineCount;

				IScrollInfo scrollInfo = textView;
				if (!scrollInfo.CanHorizontallyScroll) {
					// Word wrap is enabled. Ensure that we have up-to-date info about line height so that we scroll
					// to the correct position.
					// This avoids that the user has to repeat the ScrollTo() call several times when there are very long lines.
					VisualLine vl = textView.GetOrConstructVisualLine(doreplacedent.GetLineByNumber(line));
					double remainingHeight = referencedVerticalViewPortOffset;

					while (remainingHeight > 0) {
						DoreplacedentLine prevLine = vl.FirstDoreplacedentLine.PreviousLine;
						if (prevLine == null)
							break;
						vl = textView.GetOrConstructVisualLine(prevLine);
						remainingHeight -= vl.Height;
					}
				}
				
				Point p = textArea.TextView.GetVisualPosition(new TextViewPosition(line, Math.Max(1, column)), yPositionMode);
				double verticalPos = p.Y - referencedVerticalViewPortOffset;
				if (Math.Abs(verticalPos - scrollViewer.VerticalOffset) > minimumScrollFraction * scrollViewer.ViewportHeight) {
					scrollViewer.ScrollToVerticalOffset(Math.Max(0, verticalPos));
				}
				if (column > 0) {
					if (p.X > scrollViewer.ViewportWidth - Caret.MinimumDistanceToViewBorder * 2) {
						double horizontalPos = Math.Max(0, p.X - scrollViewer.ViewportWidth / 2);
						if (Math.Abs(horizontalPos - scrollViewer.HorizontalOffset) > minimumScrollFraction * scrollViewer.ViewportWidth) {
							scrollViewer.ScrollToHorizontalOffset(horizontalPos);
						}
					} else {
						scrollViewer.ScrollToHorizontalOffset(0);
					}
				}
			}
		}

19 View Source File : ExtensionMethods.cs
License : MIT License
Project Creator : Abdesol

public static double CoerceValue(this double value, double minimum, double maximum)
		{
			return Math.Max(Math.Min(value, maximum), minimum);
		}

19 View Source File : SurfaceMeshContours.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private IDataSeries3D FillSeries(int index, int width, int height)
        {
            double angle = Math.PI*2*index/30;

            int w = width, h = height;

            var dataSeries = new UniformGridDataSeries3D<double>(w, h)
            {
                StepX = 0.01,
                StepZ = 0.01,
            };

            for (int x = 0; x < 200; x++)
            {
                for (int y = 0; y < 200; y++)
                {
                    var v = (1 + Math.Sin(x*0.04 + angle))*50 + (1 + Math.Sin(y*0.1 + angle))*50*(1 + Math.Sin(angle*2));
                    var cx = w/2;
                    var cy = h/2;
                    var r = Math.Sqrt((x - cx)*(x - cx) + (y - cy)*(y - cy));
                    var exp = Math.Max(0, 1 - r*0.008);
                    var zValue = v*exp;

                    dataSeries[y, x] = zValue;
                }
            }

            return dataSeries;
        }

19 View Source File : ContoursExampleView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private IDataSeries CreateSeries(int index, int width, int height, double cpMax)
        {
            var w = width;
            var h = height;

            var angle = Math.PI * 2 * index / 30;
            var data = new double[h, w];
            var smallValue = 0d;
            
            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    var v = (1 + Math.Sin(x * 0.04 + angle)) * 50 +
                            (1 + Math.Sin(y * 0.1 + angle)) * 50 * (1 + Math.Sin(angle * 2));
                    
                    var cx = w / 2;
                    var cy = h / 2;
                    
                    var r = Math.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
                    var exp = Math.Max(0, 1 - r * 0.008);
                    var zValue = (v * exp);
                    
                    data[y, x] = (zValue > cpMax) ? cpMax : zValue;
                    data[y, x] += smallValue;
                }

                smallValue += 0.001;
            }

            return new UniformHeatmapDataSeries<int, int, double>(data, 0, 1, 0, 1);
        }

19 View Source File : RealTimeGhostedTraces.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private static double Constrain(double value, double noLowerThan, double noBiggerThan)
        {
            return Math.Max(Math.Min(value, noBiggerThan), noLowerThan);
        }

19 View Source File : UniformHeatmapAndPaletteProvider.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private IDataSeries CreateSeries()
        {
            double angle = Math.Round(Math.PI * 2 * 1 / 30, 3);
            int w = 300, h = 200;
            var data = new double[h, w];
            for (int x = 0; x < w; x++)
                for (int y = 0; y < h; y++)
                {
                    var v = (1 + Math.Round(Math.Sin(x * 0.04 + angle), 3)) * 50 + (1 + Math.Round(Math.Sin(y * 0.1 + angle), 3)) * 50 * (1 + Math.Round(Math.Sin(angle * 2), 3));
                    var cx = 150; var cy = 100;
                    var r = Math.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
                    var exp = Math.Max(0, 1 - r * 0.008);
                    data[y, x] = (v * exp + _random.NextDouble() * 50);
                }

            var xStart = new DateTime(2017, 1, 13, 0, 0, 0);
            var xStep = DateTime.MinValue.AddDays(1).AddHours(6).AddMinutes(30);
            return new UniformHeatmapDataSeries<DateTime, int, double>(data, xStart, xStep, 0, 2) { SeriesName = "UniformHeatmap" };
        }

19 View Source File : HeatMapExampleView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private IDataSeries CreateSeries(int index, int width, int height, double cpMin, double cpMax)
        {
            var seed = SeriesAnimationBase.GlobalEnableAnimations ? (Environment.TickCount << index) : 0;
            var random = new Random(seed);
            double angle = Math.Round(Math.PI * 2 * index, 3) / seriesPerPeriod;
            int w = width, h = height;
            var data = new double[h, w];
            for (int x = 0; x < w; x++)
                for (int y = 0; y < h; y++)
                {
                    var v = (1 + Math.Round(Math.Sin(x * 0.04 + angle), 3)) * 50 + (1 + Math.Round(Math.Sin(y * 0.1 + angle), 3)) * 50 * (1 + Math.Round(Math.Sin(angle * 2), 3));
                    var cx = w / 2; var cy = h / 2;
                    var r = Math.Sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
                    var exp = Math.Max(0, 1 - r * 0.008);
                    var zValue = (v * exp + random.NextDouble() * 50);
                    data[y, x] = (zValue > cpMax) ? cpMax : zValue;
                }
            return new UniformHeatmapDataSeries<int, int, double>(data, 0, 1, 0, 1);
        }

19 View Source File : AutomationTestBase.cs
License : MIT License
Project Creator : ABTSoftware

public bool CompareBitmaps(string resourceName, WriteableBitmap actual, WriteableBitmap expected, double allowableErrorPercent = 1)
        {
            try
            {
                double averageError = 0.0, maxError = double.MinValue;

                replacedert.That(new Size(actual.PixelWidth, actual.PixelHeight), Is.EqualTo(new Size(expected.PixelWidth, expected.PixelHeight)), "Image sizes are different!");

                var px1 = actual.ToByteArray();
                var px2 = expected.ToByteArray();

                replacedert.That(px1.Length, Is.EqualTo(px2.Length), "Image pixel counts are different sizes!");

                var areEqual = true;

                for (int i = 0; i < px1.Length; i += 4)
                {
                    var b1 = px1[i];
                    var g1 = px1[i + 1];
                    var r1 = px1[i + 2];
                    var a1 = px1[i + 3];

                    var b2 = px2[i];
                    var g2 = px2[i + 1];
                    var r2 = px2[i + 2];
                    var a2 = px2[i + 3];

                    // Use Euclidean distance to find the difference
                    var error = Math.Sqrt((a1 - a2) * (a1 - a2) + (r1 - r2) * (r1 - r2) + (g1 - g2) * (g1 - g2) + (b1 - b2) * (b1 - b2));

                    averageError += error;
                    maxError = Math.Max(error, maxError);
                }

                // Compute average Euclidean distance
                averageError /= (actual.PixelWidth * actual.PixelHeight * 5.10);
                maxError /= 5.10;
                if (averageError > allowableErrorPercent)
                {
                    // Error threshold exceeded 
                    areEqual = false;
                }

                /*
                 * Image comparison by comparing hash-codes. Taken from 
                 * http://www.codeproject.com/Articles/9299/Comparing-Images-using-GDI
                 * 
                    SHA256Managed shaM = new SHA256Managed();
                    byte[] hash1 = shaM.ComputeHash(px1);
                    byte[] hash2 = shaM.ComputeHash(px2);

                    //Compare the hash values
                    for (int i = 0; i < hash1.Length && i < hash2.Length
                                      && cr == CompareResult.ciCompareOk; i++)
                    {
                        if (hash1[i] != hash2[i])
                            cr = CompareResult.ciPixelMismatch;
                    }
                 */
                string message = $"Resource: {resourceName}, Image AveError: {averageError}%, Allowable AveError: {allowableErrorPercent}%, MaxError: {maxError}%";
                replacedert.That(areEqual, message);
                Console.WriteLine(message);

                return true;
            }
            catch
            {
                // Output diff file 
                SaveDiffImages(resourceName, expected, actual);

                throw;
            }
        }

19 View Source File : RandomPricesDataSource.cs
License : MIT License
Project Creator : ABTSoftware

private PriceBar GetNextRandomPriceBar()
        {
            double close = _lastPriceBar.Close;
            double num = (_random.NextDouble() - 0.9) * _initialPriceBar.Close / 30.0;
            double num2 = _random.NextDouble();
            double num3 = _initialPriceBar.Close + _initialPriceBar.Close / 2.0 * Math.Sin(7.27220521664304E-06 * _currentTime) + _initialPriceBar.Close / 16.0 * Math.Cos(7.27220521664304E-05 * _currentTime) + _initialPriceBar.Close / 32.0 * Math.Sin(7.27220521664304E-05 * (10.0 + num2) * _currentTime) + _initialPriceBar.Close / 64.0 * Math.Cos(7.27220521664304E-05 * (20.0 + num2) * _currentTime) + num;
            double num4 = Math.Max(close, num3);
            double num5 = _random.NextDouble() * _initialPriceBar.Close / 100.0;
            double high = num4 + num5;
            double num6 = Math.Min(close, num3);
            double num7 = _random.NextDouble() * _initialPriceBar.Close / 100.0;
            double low = num6 - num7;
            long volume = (long) (_random.NextDouble()*30000 + 20000);
            DateTime openTime = _simulateDateGap ? EmulateDateGap(_lastPriceBar.DateTime) : _lastPriceBar.DateTime;
            DateTime closeTime = openTime.AddMinutes(_candleIntervalMinutes);
            PriceBar candle = new PriceBar(closeTime, close, high, low, num3, volume);
            _lastPriceBar = new PriceBar(candle.DateTime, candle.Open, candle.High, candle.Low, candle.Close, volume);
            _currentTime += _candleIntervalMinutes * 60;
            return candle;
        }

19 View Source File : DimTracePaletteProvider.cs
License : MIT License
Project Creator : ABTSoftware

public Color? OverrideStrokeColor(IRenderableSeries rSeries, int index, IPointMetadata metadata)
        {
            var defaultColor = rSeries.Stroke;

            if (rSeries.DataSeries == null)
                return defaultColor;

            var xyzSeries = ((XyzDataSeries<double, double, double>)rSeries.DataSeries);

            double actualTime = xyzSeries.ZValues[index];
            double latestTime = (double) xyzSeries.Tag;

            // how old is the sample? 1.0 = New, 0.0 = Oldest
            double sampleAge = (actualTime - latestTime) / 10.0;

            // Clamp in ten steps, e.g.  0.1, 0.2 .... 0.9, 1.0
            // Why? Creating a new Pen for each single sample will slow down SciChart significantly
            sampleAge = Math.Round(sampleAge * 10.0, 0) * 0.1;

            // Ensure in the range 0.3 ... 1.0 always 
            sampleAge = Math.Max(0.3, sampleAge);
            sampleAge = Math.Min(1.0, sampleAge);

            // Compute the Alpha based on sample age
            var modifiedColor = Color.FromArgb((byte)(sampleAge * 0xFF), defaultColor.R, defaultColor.G, defaultColor.B);
            return modifiedColor;
        }

19 View Source File : ThreadSafeRandom.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static double NextInterval(float qualityMod)
        {
            return Math.Max(0.0, random.Value.NextDouble() - qualityMod);
        }

19 View Source File : LandblockGroup.cs
License : GNU Affero General Public License v3.0
Project Creator : 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 View Source File : WorldObject_Weapon.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public float GetIgnoreShieldMod(WorldObject weapon)
        {
            var creatureMod = IgnoreShield ?? 0.0f;
            var weaponMod = weapon?.IgnoreShield ?? 0.0f;

            return 1.0f - (float)Math.Max(creatureMod, weaponMod);
        }

19 View Source File : SkillCheck.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

public static double GetSkillChance(int skill, int difficulty, float factor = 0.03f)
        {
            var chance = 1.0 - (1.0 / (1.0 + Math.Exp(factor * (skill - difficulty))));

            return Math.Min(1.0, Math.Max(0.0, chance));
        }

19 View Source File : MainControl.xaml.cs
License : MIT License
Project Creator : Actipro

private void GenerateNewValue() {
			int minChars = 6;
			int maxChars = 12;
			string value = "";

			// Set min/max chars
			if (barCode.Symbology is Ean13Symbology) {
				value = "2";
				minChars = 11;
				maxChars = 11;
			}
			else if (barCode.Symbology is Ean8Symbology) {
				minChars = 7;
				maxChars = 7;
			}
			else if ((barCode.Symbology is PostnetSymbology) || (barCode.Symbology is UpcASymbology)) {
				minChars = 11;
				maxChars = 11;
			}
			else if (barCode.Symbology is UpcESymbology) {
				minChars = 7;
				maxChars = 7;
			}

			// Randomly generate a value
			DateTime dateTime = DateTime.Now;
			Random random = new Random(dateTime.Millisecond);

			int count = (int)Math.Max(minChars, Math.Min(maxChars, minChars + (random.NextDouble() * (maxChars - minChars))));
			for (int index = 0; index < count; index++)
				value += "0123456789"[(int)Math.Min(9, random.NextDouble() * 10)];

			// Append any necessary pre/post text
			if (barCode.Symbology is CodabarSymbology)
				value = String.Format("A{0}A", value);
			else if (barCode.Symbology is UpcESymbology)
				value = String.Format("0{0}", value);

			// Set the value
			barCode.Symbology.Value = value;
		}

19 View Source File : RichTextBox.cs
License : MIT License
Project Creator : Actipro

protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) {
			// Call the base method
			base.OnRenderSizeChanged(sizeInfo);

			// Adjust the doreplacedent's page width (since there is a WPF bug when used within a parent ScrollViewer with horizontal scroll capabilities)
			if (this.Doreplacedent != null)
				this.Doreplacedent.PageWidth = Math.Max(1, this.ActualWidth - this.BorderThickness.Left - this.Padding.Left - 
					this.BorderThickness.Right - this.Padding.Right - SystemParameters.VerticalScrollBarWidth);
		}

19 View Source File : DropDownGlyphPanel.cs
License : MIT License
Project Creator : Actipro

protected override Size ArrangeOverride(Size finalSize) {
			var internalChildren = base.InternalChildren;
			if (internalChildren.Count == 2) {
				var x = Math.Max(0, Math.Min(internalChildren[0].DesiredSize.Width, finalSize.Width - internalChildren[1].DesiredSize.Width));
				internalChildren[1].Arrange(new Rect(x, 0, internalChildren[1].DesiredSize.Width, finalSize.Height));
				internalChildren[0].Arrange(new Rect(0, 0, x, finalSize.Height));
			}

			return finalSize;
		}

19 View Source File : DropDownGlyphPanel.cs
License : MIT License
Project Creator : Actipro

protected override Size MeasureOverride(Size availableSize) {
			var desiredWidth = 0.0;
			var desiredHeight = 0.0;

			var availableWidth = availableSize.Width;
			var availableHeight = availableSize.Height;

			var internalChildren = base.InternalChildren;
			if (internalChildren.Count == 2) {
				// Glyph
				internalChildren[1].Measure(new Size(availableWidth, availableHeight));
				availableWidth = Math.Max(0, availableWidth - internalChildren[1].DesiredSize.Width);

				// Text
				internalChildren[0].Measure(new Size(availableWidth, availableHeight));
				
				// Calculate size
				desiredWidth = Math.Ceiling(internalChildren[0].DesiredSize.Width + internalChildren[1].DesiredSize.Width);
				desiredHeight = Math.Max(internalChildren[0].DesiredSize.Height, internalChildren[1].DesiredSize.Height).Round(RoundMode.CeilingToEven);
			}

			return new Size(desiredWidth, desiredHeight);
		}

19 View Source File : RichTextBox.cs
License : MIT License
Project Creator : Actipro

protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) {
			// Call the base method
			base.OnRenderSizeChanged(sizeInfo);

			// Adjust the doreplacedent's page width
			if (this.Doreplacedent != null)
				this.Doreplacedent.PageWidth = Math.Max(1, this.ActualWidth - this.BorderThickness.Left - this.Padding.Left -
					this.BorderThickness.Right - this.Padding.Right - SystemParameters.VerticalScrollBarWidth);
		}

19 View Source File : SimpleFlowDocumentReader.cs
License : MIT License
Project Creator : Actipro

protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) {
			// Call the base methods
			base.OnRenderSizeChanged(sizeInfo);

			// Dynamically adjust the page width and viewing mode based on the available width
			this.Doreplacedent.PageWidth = Math.Max(0.0, Math.Min(this.Doreplacedent.MaxPageWidth, sizeInfo.NewSize.Width) - SystemParameters.VerticalScrollBarWidth);
			this.ViewingMode = (sizeInfo.NewSize.Width > this.Doreplacedent.MaxPageWidth ? FlowDoreplacedentReaderViewingMode.Page : FlowDoreplacedentReaderViewingMode.Scroll);
		}

19 View Source File : CustomMargin.cs
License : MIT License
Project Creator : Actipro

private void OnViewTextAreaLayout(object sender, TextViewTextAreaLayoutEventArgs e) {
			if (this.Visibility == Visibility.Visible) {
				// Determine min width
				int digitCount = view.CurrentSnapshot.Length.ToString(CultureInfo.CurrentCulture).Length;

				// Get typeface
				Typeface typeface = new Typeface(this.FontFamily, this.FontStyle, this.FontWeight, this.FontStretch);
				double fontSize = this.FontSize;

				// Get the formatted text
				FormattedText text = new FormattedText(new string('0', digitCount) + " chars", CultureInfo.CurrentCulture, 
					FlowDirection.LeftToRight, typeface, fontSize, this.Foreground, VisualTreeHelper.GetDpi(view.VisualElement).PixelsPerDip);

				// Update the min width to ensure all digits will fit when on the last line
				double minWidth = Math.Max(42, Math.Ceiling(text.WidthIncludingTrailingWhitespace) + this.Padding.Left + this.Padding.Right);
				if (this.MinWidth != minWidth)
					this.MinWidth = minWidth;
			}
		}

19 View Source File : CustomIndicatorTag.cs
License : MIT License
Project Creator : Actipro

public override void DrawGlyph(TextViewDrawContext context, ITextViewLine viewLine, TagSnapshotRange<IIndicatorTag> tagRange, Rect bounds) {
			var diameter = Math.Max(8.0, Math.Min(13, Math.Round(Math.Min(bounds.Width, bounds.Height) - 2.0)));
			var x = bounds.X + (bounds.Width - diameter) / 2.0;
			var y = bounds.Y + (bounds.Height - diameter) / 2.0;

			context.FillEllipse(new Rect(x, y, diameter, diameter), Color.FromArgb(0xff, 0x8a, 0xf3, 0x82));
			context.DrawEllipse(new Rect(x, y, diameter, diameter), Color.FromArgb(0xff, 0x00, 0x40, 0x00), LineKind.Solid, 1);
		}

19 View Source File : RandomPanel.cs
License : MIT License
Project Creator : Actipro

public override Size ArrangeElements(IList<UIElement> elements, Size finalSize) {
			// Cache and reset layout pending flag
			bool isLayoutUpdatePending = this.IsLayoutUpdatePending;
			this.IsLayoutUpdatePending = false;

			// Iterate over the elements and arrange
			foreach (UIElement element in elements) {
				if (element != null) {
					Size desiredSize = element.DesiredSize;

					// Calculate a random x/y position that keeps the element in the view
					double x = Math.Max(random.NextDouble() * (finalSize.Width - desiredSize.Width), 0);
					double y = Math.Max(random.NextDouble() * (finalSize.Height - desiredSize.Height), 0);

					// Update the arrange state with the new arrange rect, but if there are leaving elements then don't move
					//   the element
					ArrangeState state = new ArrangeState(element, false, isLayoutUpdatePending);
					if (!this.HasLeavingChildren)
						state.ArrangeRect = new Rect(x, y, desiredSize.Width, desiredSize.Height);
					else
						state.ArrangeRect = state.PreviousArrangeRect;

					PanelBase.SetArrangeState(element, state);
				}
			}

			return finalSize;
		}

19 View Source File : RandomPanel.cs
License : MIT License
Project Creator : Actipro

public override Size MeasureElements(IList<UIElement> elements, Size availableSize) {
			// Measure each element, and return the largest width and height needed
			Size desiredSize = new Size();
			foreach (UIElement element in elements) {
				if (null != element) {
					element.Measure(availableSize);

					desiredSize.Width = Math.Max(element.DesiredSize.Width, desiredSize.Width);
					desiredSize.Height = Math.Max(element.DesiredSize.Height, desiredSize.Height);
				}
			}
			return desiredSize;
		}

19 View Source File : PerformanceProfile.cs
License : MIT License
Project Creator : adainrivers

internal void Stop()
        {
            var elapsed = (DateTimeOffset.UtcNow - _startTime).TotalMilliseconds;
            _maxMilliseconds = Math.Max(_maxMilliseconds, elapsed);
            _totalMilliseconds += elapsed;
        }

19 View Source File : TestHardSigmoid.cs
License : MIT License
Project Creator : adamtiger

private double HardSigmoidFunc(double x)
        {
            return Math.Max(0.0, Math.Min(1, 0.2*x+0.5));
        }

19 View Source File : SimpleAudioPlayerImplementation.cs
License : MIT License
Project Creator : adrianstevens

void SetVolume(double volume, double balance)
        {
            volume = Math.Max(0, volume);
            volume = Math.Min(1, volume);

            balance = Math.Max(-1, balance);
            balance = Math.Min(1, balance);

            // Using the "constant power pan rule." See: http://www.rs-met.com/doreplacedents/tutorials/PanRules.pdf
            var left = Math.Cos((Math.PI * (balance + 1)) / 4) * volume;
            var right = Math.Sin((Math.PI * (balance + 1)) / 4) * volume;

            player?.SetVolume((float)left, (float)right);
        }

19 View Source File : SimpleAudioPlayerImplementation.cs
License : MIT License
Project Creator : adrianstevens

void SetVolume(double volume, double balance)
        {
            if (player == null)
                return;

            volume = Math.Max(0, volume);
            volume = Math.Min(1, volume);

            balance = Math.Max(-1, balance);
            balance = Math.Min(1, balance);

            player.Volume = (float)volume;
            player.Pan = (float)balance;
        }

19 View Source File : SimpleAudioPlayerImplementation.cs
License : MIT License
Project Creator : adrianstevens

void SetVolume(double volume, double balance)
		{
			if (player == null || isDisposed)
				return;

			volume = Math.Max(0, volume);
			volume = Math.Min(1, volume);

			//balance = Math.Max(-1, balance);
			//balance = Math.Min(1, balance);

			player.Volume = (float)volume;
		}

19 View Source File : SimpleAudioPlayerImplementation.cs
License : MIT License
Project Creator : adrianstevens

void SetVolume(double volume, double balance)
        {
            if (player == null || isDisposed) return;

            player.Volume = Math.Min(1, Math.Max(0, volume));
            player.AudioBalance = Math.Min(1, Math.Max(-1, balance));
        }

19 View Source File : SimpleAudioPlayerImplementation.cs
License : MIT License
Project Creator : adrianstevens

private void SetVolume(double volume, double balance)
        {
            if (player == null || _isDisposed) return;

            player.Volume = Math.Min(1, Math.Max(0, volume));
            player.Balance = Math.Min(1, Math.Max(-1, balance));
        }

19 View Source File : MetroWaterfallFlow.cs
License : GNU General Public License v3.0
Project Creator : aduskin

private void SetCurHeight(int i, double value)
      {
         _curHeight[i] += value;
         _maxheight = Math.Max(_curHeight[i], _maxheight);
      }

19 View Source File : ConeShape.cs
License : The Unlicense
Project Creator : aeroson

public static ConvexShapeDescription ComputeDescription(float height, float radius, float collisionMargin)
        {
            ConvexShapeDescription description;
            description.EnreplacedyShapeVolume.Volume = (float)(.333333 * Math.PI * radius * radius * height);

            description.EnreplacedyShapeVolume.VolumeDistribution = new Matrix3x3();
            float diagValue = (.1f * height * height + .15f * radius * radius);
            description.EnreplacedyShapeVolume.VolumeDistribution.M11 = diagValue;
            description.EnreplacedyShapeVolume.VolumeDistribution.M22 = .3f * radius * radius;
            description.EnreplacedyShapeVolume.VolumeDistribution.M33 = diagValue;

            description.MaximumRadius = (float)(collisionMargin + Math.Max(.75 * height, Math.Sqrt(.0625f * height * height + radius * radius)));

            double denominator = radius / height;
            denominator = denominator / Math.Sqrt(denominator * denominator + 1);
            description.MinimumRadius = (float)(collisionMargin + Math.Min(.25f * height, denominator * .75 * height));

            description.CollisionMargin = collisionMargin;
            return description;
        }

19 View Source File : Curve.cs
License : The Unlicense
Project Creator : aeroson

public static double ModifyTime(double time, double intervalBegin, double intervalEnd, CurveEndpointBehavior preLoop, CurveEndpointBehavior postLoop)
        {
            if (time < intervalBegin)
            {
                switch (preLoop)
                {
                    case CurveEndpointBehavior.Wrap:
                        double modifiedTime = time - intervalBegin;
                        double intervalLength = intervalEnd - intervalBegin;
                        modifiedTime %= intervalLength;
                        return intervalEnd + modifiedTime;
                    case CurveEndpointBehavior.Clamp:
                        return Math.Max(intervalBegin, time);
                    case CurveEndpointBehavior.Mirror:
                        modifiedTime = time - intervalBegin;
                        intervalLength = intervalEnd - intervalBegin;
                        var numFlips = (int) (modifiedTime / intervalLength);
                        if (numFlips % 2 == 0)
                            return intervalBegin - modifiedTime % intervalLength;
                        return intervalEnd + modifiedTime % intervalLength;
                }
            }
            else if (time >= intervalEnd)
            {
                switch (postLoop)
                {
                    case CurveEndpointBehavior.Wrap:
                        double modifiedTime = time - intervalEnd;
                        double intervalLength = intervalEnd - intervalBegin;
                        modifiedTime %= intervalLength;
                        return intervalBegin + modifiedTime;
                    case CurveEndpointBehavior.Clamp:
                        return Math.Min(intervalEnd, time);
                    case CurveEndpointBehavior.Mirror:
                        modifiedTime = time - intervalEnd;
                        intervalLength = intervalEnd - intervalBegin;
                        var numFlips = (int) (modifiedTime / intervalLength);
                        if (numFlips % 2 == 0)
                            return intervalEnd - modifiedTime % intervalLength;
                        return intervalBegin + modifiedTime % intervalLength;
                }
            }
            return time;
        }

19 View Source File : Color.cs
License : GNU General Public License v3.0
Project Creator : aglab2

public static void RGB2HSL(ColorRGB rgb, out double h, out double s, out double l)
        {
            double r = rgb.R / 255.0;
            double g = rgb.G / 255.0;
            double b = rgb.B / 255.0;
            double v;
            double m;
            double vm;
            double r2, g2, b2;

            h = 0; // default to black
            s = 0;
            l = 0;
            v = Math.Max(r, g);
            v = Math.Max(v, b);
            m = Math.Min(r, g);
            m = Math.Min(m, b);
            l = (m + v) / 2.0;
            if (l <= 0.0)
            {
                return;
            }
            vm = v - m;
            s = vm;
            if (s > 0.0)
            {
                s /= (l <= 0.5) ? (v + m) : (2.0 - v - m);
            }
            else
            {
                return;
            }
            r2 = (v - r) / vm;
            g2 = (v - g) / vm;
            b2 = (v - b) / vm;
            if (r == v)
            {
                h = (g == m ? 5.0 + b2 : 1.0 - g2);
            }
            else if (g == v)
            {
                h = (b == m ? 1.0 + r2 : 3.0 - b2);
            }
            else
            {
                h = (r == m ? 3.0 + g2 : 5.0 - r2);
            }
            h /= 6.0;
        }

19 View Source File : CellScaling.cs
License : GNU General Public License v3.0
Project Creator : AHeroicLlama

public static CellScaling GetCellScaling(Cell cell)
		{
			double xCenter = (Math.Abs(cell.xMax) + Math.Abs(cell.xMin)) / 2;
			double yCenter = (Math.Abs(cell.yMax) + Math.Abs(cell.yMin)) / 2;

			double xRange = Math.Abs(cell.xMax) - Math.Abs(cell.xMin);
			double yRange = Math.Abs(cell.yMax) - Math.Abs(cell.yMin);
			double largestWidth = Math.Max(xRange, yRange);

			// Prevent division by 0 if cell contains a single item
			if (largestWidth == 0)
			{
				largestWidth = 1;
			}

			double bestZoomRatio = (Map.mapDimension - (zoomPadding * 2)) / largestWidth;

			return new CellScaling(-(xCenter - (Map.mapDimension / 2)), -(yCenter - (Map.mapDimension / 2)), bestZoomRatio);
		}

See More Examples