System.Array.Clone()

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

1565 Examples 7

19 Source : IccProfileColorInformation.cs
with MIT License
from 0xC0000054

public byte[] GetProfileBytes()
        {
            return (byte[])this.iccProfile?.Clone();
        }

19 Source : MetadataEntry.cs
with MIT License
from 0xC0000054

public PaintDotNet.Imaging.ExifPropertyItem CreateExifPropertyItem()
        {
            PaintDotNet.Imaging.ExifSection exifSection;
            switch (this.Section)
            {
                case MetadataSection.Image:
                    exifSection = PaintDotNet.Imaging.ExifSection.Image;
                    break;
                case MetadataSection.Exif:
                    exifSection = PaintDotNet.Imaging.ExifSection.Photo;
                    break;
                case MetadataSection.Gps:
                    exifSection = PaintDotNet.Imaging.ExifSection.GpsInfo;
                    break;
                case MetadataSection.Interop:
                    exifSection = PaintDotNet.Imaging.ExifSection.Interop;
                    break;
                default:
                    throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                                      "Unexpected {0} type: {1}",
                                                                      nameof(MetadataSection),
                                                                      (int)this.Section));
            }

            return new PaintDotNet.Imaging.ExifPropertyItem(exifSection,
                                                            this.TagId,
                                                            new PaintDotNet.Imaging.ExifValue((PaintDotNet.Imaging.ExifValueType)this.Type,
                                                                                              (byte[])this.data.Clone()));
        }

19 Source : MetadataEntry.cs
with MIT License
from 0xC0000054

public byte[] GetData()
        {
            return (byte[])this.data.Clone();
        }

19 Source : MetadataEntry.cs
with MIT License
from 0xC0000054

public byte[] GetData()
        {
            return (byte[])data.Clone();
        }

19 Source : MetadataEntry.cs
with MIT License
from 0xC0000054

public PaintDotNet.Imaging.ExifPropertyItem CreateExifPropertyItem()
        {
            PaintDotNet.Imaging.ExifSection exifSection;
            switch (Section)
            {
                case MetadataSection.Image:
                    exifSection = PaintDotNet.Imaging.ExifSection.Image;
                    break;
                case MetadataSection.Exif:
                    exifSection = PaintDotNet.Imaging.ExifSection.Photo;
                    break;
                case MetadataSection.Gps:
                    exifSection = PaintDotNet.Imaging.ExifSection.GpsInfo;
                    break;
                case MetadataSection.Interop:
                    exifSection = PaintDotNet.Imaging.ExifSection.Interop;
                    break;
                default:
                    throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                                      "Unexpected {0} type: {1}",
                                                                      nameof(MetadataSection),
                                                                      (int)Section));
            }

            return new PaintDotNet.Imaging.ExifPropertyItem(exifSection,
                                                            TagId,
                                                            new PaintDotNet.Imaging.ExifValue((PaintDotNet.Imaging.ExifValueType)Type,
                                                                                              (byte[])data.Clone()));
        }

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

public static bool rmatrixbdsvd(ref double[] d, double[] e, int n, bool isupper, bool isfractionalaccuracyrequired, ref double[,] u, int nru, ref double[,] c, int ncc, ref double[,] vt, int ncvt)
  {
    double[] numArray = new double[0];
    double[] e1 = new double[0];
    e = (double[]) e.Clone();
    double[] d1 = new double[n + 1];
    int num1 = -1;
    for (int index = 1; index <= n; ++index)
      d1[index] = d[index + num1];
    if (n > 1)
    {
      e1 = new double[n - 1 + 1];
      int num2 = -1;
      for (int index = 1; index <= n - 1; ++index)
        e1[index] = e[index + num2];
    }
    bool flag = bdsvd.bidiagonalsvddecompositioninternal(ref d1, e1, n, isupper, isfractionalaccuracyrequired, ref u, 0, nru, ref c, 0, ncc, ref vt, 0, ncvt);
    int num3 = 1;
    for (int index = 0; index <= n - 1; ++index)
      d[index] = d1[index + num3];
    return flag;
  }

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

public static void buildlinearspline(double[] x, double[] y, int n, ref double[] c)
  {
    x = (double[]) x.Clone();
    y = (double[]) y.Clone();
    spline3.heapsortpoints(ref x, ref y, n);
    int num = 3 + n + (n - 1) * 4;
    c = new double[num - 1 + 1];
    c[0] = (double) num;
    c[1] = 3.0;
    c[2] = (double) n;
    for (int index = 0; index <= n - 1; ++index)
      c[3 + index] = x[index];
    for (int index = 0; index <= n - 2; ++index)
    {
      c[3 + n + 4 * index] = y[index];
      c[3 + n + 4 * index + 1] = (y[index + 1] - y[index]) / (x[index + 1] - x[index]);
      c[3 + n + 4 * index + 2] = 0.0;
      c[3 + n + 4 * index + 3] = 0.0;
    }
  }

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

public static void buildcubicspline(double[] x, double[] y, int n, int boundltype, double boundl, int boundrtype, double boundr, ref double[] c)
  {
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    double[] numArray3 = new double[0];
    double[] numArray4 = new double[0];
    double[] x1 = new double[0];
    x = (double[]) x.Clone();
    y = (double[]) y.Clone();
    double[] a = new double[n - 1 + 1];
    double[] b = new double[n - 1 + 1];
    double[] c1 = new double[n - 1 + 1];
    double[] d = new double[n - 1 + 1];
    if (n == 2 & boundltype == 0 & boundrtype == 0)
    {
      boundltype = 2;
      boundl = 0.0;
      boundrtype = 2;
      boundr = 0.0;
    }
    spline3.heapsortpoints(ref x, ref y, n);
    if (boundltype == 0)
    {
      a[0] = 0.0;
      b[0] = 1.0;
      c1[0] = 1.0;
      d[0] = 2.0 * (y[1] - y[0]) / (x[1] - x[0]);
    }
    if (boundltype == 1)
    {
      a[0] = 0.0;
      b[0] = 1.0;
      c1[0] = 0.0;
      d[0] = boundl;
    }
    if (boundltype == 2)
    {
      a[0] = 0.0;
      b[0] = 2.0;
      c1[0] = 1.0;
      d[0] = 3.0 * (y[1] - y[0]) / (x[1] - x[0]) - 0.5 * boundl * (x[1] - x[0]);
    }
    for (int index = 1; index <= n - 2; ++index)
    {
      a[index] = x[index + 1] - x[index];
      b[index] = 2.0 * (x[index + 1] - x[index - 1]);
      c1[index] = x[index] - x[index - 1];
      d[index] = 3.0 * (y[index] - y[index - 1]) / (x[index] - x[index - 1]) * (x[index + 1] - x[index]) + 3.0 * (y[index + 1] - y[index]) / (x[index + 1] - x[index]) * (x[index] - x[index - 1]);
    }
    if (boundrtype == 0)
    {
      a[n - 1] = 1.0;
      b[n - 1] = 1.0;
      c1[n - 1] = 0.0;
      d[n - 1] = 2.0 * (y[n - 1] - y[n - 2]) / (x[n - 1] - x[n - 2]);
    }
    if (boundrtype == 1)
    {
      a[n - 1] = 0.0;
      b[n - 1] = 1.0;
      c1[n - 1] = 0.0;
      d[n - 1] = boundr;
    }
    if (boundrtype == 2)
    {
      a[n - 1] = 1.0;
      b[n - 1] = 2.0;
      c1[n - 1] = 0.0;
      d[n - 1] = 3.0 * (y[n - 1] - y[n - 2]) / (x[n - 1] - x[n - 2]) + 0.5 * boundr * (x[n - 1] - x[n - 2]);
    }
    spline3.solvetridiagonal(a, b, c1, d, n, ref x1);
    spline3.buildhermitespline(x, y, x1, n, ref c);
  }

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

public static void buildhermitespline(double[] x, double[] y, double[] d, int n, ref double[] c)
  {
    x = (double[]) x.Clone();
    y = (double[]) y.Clone();
    d = (double[]) d.Clone();
    spline3.heapsortdpoints(ref x, ref y, ref d, n);
    int num1 = 3 + n + (n - 1) * 4;
    c = new double[num1 - 1 + 1];
    c[0] = (double) num1;
    c[1] = 3.0;
    c[2] = (double) n;
    for (int index = 0; index <= n - 1; ++index)
      c[3 + index] = x[index];
    for (int index = 0; index <= n - 2; ++index)
    {
      double X = x[index + 1] - x[index];
      double num2 = AP.Math.Sqr(X);
      double num3 = X * num2;
      c[3 + n + 4 * index] = y[index];
      c[3 + n + 4 * index + 1] = d[index];
      c[3 + n + 4 * index + 2] = (3.0 * (y[index + 1] - y[index]) - 2.0 * d[index] * X - d[index + 1] * X) / num2;
      c[3 + n + 4 * index + 3] = (2.0 * (y[index] - y[index + 1]) + d[index] * X + d[index + 1] * X) / num3;
    }
  }

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 : svd.cs
with MIT License
from 1CM69

public static bool rmatrixsvd(double[,] a, int m, int n, int uneeded, int vtneeded, int additionalmemory, ref double[] w, ref double[,] u, ref double[,] vt)
  {
    double[] tauq = new double[0];
    double[] taup = new double[0];
    double[] tau = new double[0];
    double[] e = new double[0];
    double[] numArray1 = new double[0];
    double[,] numArray2 = new double[0, 0];
    bool isupper = false;
    a = (double[,]) a.Clone();
    bool flag1 = true;
    if (m == 0 | n == 0)
      return flag1;
    int n1 = Math.Min(m, n);
    w = new double[n1 + 1];
    int qcolumns = 0;
    int num1 = 0;
    if (uneeded == 1)
    {
      num1 = m;
      qcolumns = n1;
      u = new double[num1 - 1 + 1, qcolumns - 1 + 1];
    }
    if (uneeded == 2)
    {
      num1 = m;
      qcolumns = m;
      u = new double[num1 - 1 + 1, qcolumns - 1 + 1];
    }
    int num2 = 0;
    int ncvt = 0;
    if (vtneeded == 1)
    {
      num2 = n1;
      ncvt = n;
      vt = new double[num2 - 1 + 1, ncvt - 1 + 1];
    }
    if (vtneeded == 2)
    {
      num2 = n;
      ncvt = n;
      vt = new double[num2 - 1 + 1, ncvt - 1 + 1];
    }
    if ((double) m > 1.6 * (double) n)
    {
      if (uneeded == 0)
      {
        qr.rmatrixqr(ref a, m, n, ref tau);
        for (int index1 = 0; index1 <= n - 1; ++index1)
        {
          for (int index2 = 0; index2 <= index1 - 1; ++index2)
            a[index1, index2] = 0.0;
        }
        bidiagonal.rmatrixbd(ref a, n, n, ref tauq, ref taup);
        bidiagonal.rmatrixbdunpackpt(ref a, n, n, ref taup, num2, ref vt);
        bidiagonal.rmatrixbdunpackdiagonals(ref a, n, n, ref isupper, ref w, ref e);
        return bdsvd.rmatrixbdsvd(ref w, e, n, isupper, false, ref u, 0, ref a, 0, ref vt, ncvt);
      }
      qr.rmatrixqr(ref a, m, n, ref tau);
      qr.rmatrixqrunpackq(ref a, m, n, ref tau, qcolumns, ref u);
      for (int index1 = 0; index1 <= n - 1; ++index1)
      {
        for (int index2 = 0; index2 <= index1 - 1; ++index2)
          a[index1, index2] = 0.0;
      }
      bidiagonal.rmatrixbd(ref a, n, n, ref tauq, ref taup);
      bidiagonal.rmatrixbdunpackpt(ref a, n, n, ref taup, num2, ref vt);
      bidiagonal.rmatrixbdunpackdiagonals(ref a, n, n, ref isupper, ref w, ref e);
      bool flag2;
      if (additionalmemory < 1)
      {
        bidiagonal.rmatrixbdmultiplybyq(ref a, n, n, ref tauq, ref u, m, n, true, false);
        flag2 = bdsvd.rmatrixbdsvd(ref w, e, n, isupper, false, ref u, m, ref a, 0, ref vt, ncvt);
      }
      else
      {
        double[] work = new double[Math.Max(m, n) + 1];
        bidiagonal.rmatrixbdunpackq(ref a, n, n, ref tauq, n, ref numArray2);
        blas.copymatrix(ref u, 0, m - 1, 0, n - 1, ref a, 0, m - 1, 0, n - 1);
        blas.inplacetranspose(ref numArray2, 0, n - 1, 0, n - 1, ref work);
        flag2 = bdsvd.rmatrixbdsvd(ref w, e, n, isupper, false, ref u, 0, ref numArray2, n, ref vt, ncvt);
        blas.matrixmatrixmultiply(ref a, 0, m - 1, 0, n - 1, false, ref numArray2, 0, n - 1, 0, n - 1, true, 1.0, ref u, 0, m - 1, 0, n - 1, 0.0, ref work);
      }
      return flag2;
    }
    if ((double) n > 1.6 * (double) m)
    {
      if (vtneeded == 0)
      {
        lq.rmatrixlq(ref a, m, n, ref tau);
        for (int index1 = 0; index1 <= m - 1; ++index1)
        {
          for (int index2 = index1 + 1; index2 <= m - 1; ++index2)
            a[index1, index2] = 0.0;
        }
        bidiagonal.rmatrixbd(ref a, m, m, ref tauq, ref taup);
        bidiagonal.rmatrixbdunpackq(ref a, m, m, ref tauq, qcolumns, ref u);
        bidiagonal.rmatrixbdunpackdiagonals(ref a, m, m, ref isupper, ref w, ref e);
        double[] work = new double[m + 1];
        blas.inplacetranspose(ref u, 0, num1 - 1, 0, qcolumns - 1, ref work);
        bool flag2 = bdsvd.rmatrixbdsvd(ref w, e, m, isupper, false, ref a, 0, ref u, num1, ref vt, 0);
        blas.inplacetranspose(ref u, 0, num1 - 1, 0, qcolumns - 1, ref work);
        return flag2;
      }
      lq.rmatrixlq(ref a, m, n, ref tau);
      lq.rmatrixlqunpackq(ref a, m, n, ref tau, num2, ref vt);
      for (int index1 = 0; index1 <= m - 1; ++index1)
      {
        for (int index2 = index1 + 1; index2 <= m - 1; ++index2)
          a[index1, index2] = 0.0;
      }
      bidiagonal.rmatrixbd(ref a, m, m, ref tauq, ref taup);
      bidiagonal.rmatrixbdunpackq(ref a, m, m, ref tauq, qcolumns, ref u);
      bidiagonal.rmatrixbdunpackdiagonals(ref a, m, m, ref isupper, ref w, ref e);
      double[] work1 = new double[Math.Max(m, n) + 1];
      blas.inplacetranspose(ref u, 0, num1 - 1, 0, qcolumns - 1, ref work1);
      bool flag3;
      if (additionalmemory < 1)
      {
        bidiagonal.rmatrixbdmultiplybyp(ref a, m, m, ref taup, ref vt, m, n, false, true);
        flag3 = bdsvd.rmatrixbdsvd(ref w, e, m, isupper, false, ref a, 0, ref u, num1, ref vt, n);
      }
      else
      {
        bidiagonal.rmatrixbdunpackpt(ref a, m, m, ref taup, m, ref numArray2);
        flag3 = bdsvd.rmatrixbdsvd(ref w, e, m, isupper, false, ref a, 0, ref u, num1, ref numArray2, m);
        blas.copymatrix(ref vt, 0, m - 1, 0, n - 1, ref a, 0, m - 1, 0, n - 1);
        blas.matrixmatrixmultiply(ref numArray2, 0, m - 1, 0, m - 1, false, ref a, 0, m - 1, 0, n - 1, false, 1.0, ref vt, 0, m - 1, 0, n - 1, 0.0, ref work1);
      }
      blas.inplacetranspose(ref u, 0, num1 - 1, 0, qcolumns - 1, ref work1);
      return flag3;
    }
    if (m <= n)
    {
      bidiagonal.rmatrixbd(ref a, m, n, ref tauq, ref taup);
      bidiagonal.rmatrixbdunpackq(ref a, m, n, ref tauq, qcolumns, ref u);
      bidiagonal.rmatrixbdunpackpt(ref a, m, n, ref taup, num2, ref vt);
      bidiagonal.rmatrixbdunpackdiagonals(ref a, m, n, ref isupper, ref w, ref e);
      double[] work = new double[m + 1];
      blas.inplacetranspose(ref u, 0, num1 - 1, 0, qcolumns - 1, ref work);
      bool flag2 = bdsvd.rmatrixbdsvd(ref w, e, n1, isupper, false, ref a, 0, ref u, num1, ref vt, ncvt);
      blas.inplacetranspose(ref u, 0, num1 - 1, 0, qcolumns - 1, ref work);
      return flag2;
    }
    bidiagonal.rmatrixbd(ref a, m, n, ref tauq, ref taup);
    bidiagonal.rmatrixbdunpackq(ref a, m, n, ref tauq, qcolumns, ref u);
    bidiagonal.rmatrixbdunpackpt(ref a, m, n, ref taup, num2, ref vt);
    bidiagonal.rmatrixbdunpackdiagonals(ref a, m, n, ref isupper, ref w, ref e);
    bool flag4;
    if (additionalmemory < 2 | uneeded == 0)
    {
      flag4 = bdsvd.rmatrixbdsvd(ref w, e, n1, isupper, false, ref u, num1, ref a, 0, ref vt, ncvt);
    }
    else
    {
      double[,] numArray3 = new double[n1 - 1 + 1, m - 1 + 1];
      blas.copyandtranspose(ref u, 0, m - 1, 0, n1 - 1, ref numArray3, 0, n1 - 1, 0, m - 1);
      flag4 = bdsvd.rmatrixbdsvd(ref w, e, n1, isupper, false, ref u, 0, ref numArray3, m, ref vt, ncvt);
      blas.copyandtranspose(ref numArray3, 0, n1 - 1, 0, m - 1, ref u, 0, m - 1, 0, n1 - 1);
    }
    return flag4;
  }

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 : lq.cs
with MIT License
from 1CM69

public static void lqdecompositionunpacked(double[,] a, int m, int n, ref double[,] l, ref double[,] q)
  {
    double[] tau = new double[0];
    a = (double[,]) a.Clone();
    if (n <= 0)
      return;
    q = new double[n + 1, n + 1];
    l = new double[m + 1, n + 1];
    lq.lqdecomposition(ref a, m, n, ref tau);
    for (int index1 = 1; index1 <= m; ++index1)
    {
      for (int index2 = 1; index2 <= n; ++index2)
        l[index1, index2] = index2 <= index1 ? a[index1, index2] : 0.0;
    }
    lq.unpackqfromlq(ref a, m, n, ref tau, n, ref q);
  }

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

public static void qrdecompositionunpacked(double[,] a, int m, int n, ref double[,] q, ref double[,] r)
  {
    double[] tau = new double[0];
    a = (double[,]) a.Clone();
    int num = Math.Min(m, n);
    if (n <= 0)
      return;
    q = new double[m + 1, m + 1];
    r = new double[m + 1, n + 1];
    qr.qrdecomposition(ref a, m, n, ref tau);
    for (int index = 1; index <= n; ++index)
      r[1, index] = 0.0;
    for (int index1 = 2; index1 <= m; ++index1)
    {
      for (int index2 = 1; index2 <= n; ++index2)
        r[index1, index2] = r[1, index2];
    }
    for (int index1 = 1; index1 <= num; ++index1)
    {
      for (int index2 = index1; index2 <= n; ++index2)
        r[index1, index2] = a[index1, index2];
    }
    qr.unpackqfromqr(ref a, m, n, ref tau, m, ref q);
  }

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

public static bool svddecomposition(double[,] a, int m, int n, int uneeded, int vtneeded, int additionalmemory, ref double[] w, ref double[,] u, ref double[,] vt)
  {
    double[] tauq = new double[0];
    double[] taup = new double[0];
    double[] tau = new double[0];
    double[] e = new double[0];
    double[] numArray1 = new double[0];
    double[,] numArray2 = new double[0, 0];
    bool isupper = false;
    a = (double[,]) a.Clone();
    bool flag1 = true;
    if (m == 0 | n == 0)
      return flag1;
    int num1 = Math.Min(m, n);
    w = new double[num1 + 1];
    int num2 = 0;
    int num3 = 0;
    if (uneeded == 1)
    {
      num3 = m;
      num2 = num1;
      u = new double[num3 + 1, num2 + 1];
    }
    if (uneeded == 2)
    {
      num3 = m;
      num2 = m;
      u = new double[num3 + 1, num2 + 1];
    }
    int num4 = 0;
    int ncvt = 0;
    if (vtneeded == 1)
    {
      num4 = num1;
      ncvt = n;
      vt = new double[num4 + 1, ncvt + 1];
    }
    if (vtneeded == 2)
    {
      num4 = n;
      ncvt = n;
      vt = new double[num4 + 1, ncvt + 1];
    }
    if ((double) m > 1.6 * (double) n)
    {
      if (uneeded == 0)
      {
        qr.qrdecomposition(ref a, m, n, ref tau);
        for (int index1 = 2; index1 <= n; ++index1)
        {
          for (int index2 = 1; index2 <= index1 - 1; ++index2)
            a[index1, index2] = 0.0;
        }
        bidiagonal.tobidiagonal(ref a, n, n, ref tauq, ref taup);
        bidiagonal.unpackptfrombidiagonal(ref a, n, n, ref taup, num4, ref vt);
        bidiagonal.unpackdiagonalsfrombidiagonal(ref a, n, n, ref isupper, ref w, ref e);
        return bdsvd.bidiagonalsvddecomposition(ref w, e, n, isupper, false, ref u, 0, ref a, 0, ref vt, ncvt);
      }
      qr.qrdecomposition(ref a, m, n, ref tau);
      qr.unpackqfromqr(ref a, m, n, ref tau, num2, ref u);
      for (int index1 = 2; index1 <= n; ++index1)
      {
        for (int index2 = 1; index2 <= index1 - 1; ++index2)
          a[index1, index2] = 0.0;
      }
      bidiagonal.tobidiagonal(ref a, n, n, ref tauq, ref taup);
      bidiagonal.unpackptfrombidiagonal(ref a, n, n, ref taup, num4, ref vt);
      bidiagonal.unpackdiagonalsfrombidiagonal(ref a, n, n, ref isupper, ref w, ref e);
      bool flag2;
      if (additionalmemory < 1)
      {
        bidiagonal.multiplybyqfrombidiagonal(ref a, n, n, ref tauq, ref u, m, n, true, false);
        flag2 = bdsvd.bidiagonalsvddecomposition(ref w, e, n, isupper, false, ref u, m, ref a, 0, ref vt, ncvt);
      }
      else
      {
        double[] work = new double[Math.Max(m, n) + 1];
        bidiagonal.unpackqfrombidiagonal(ref a, n, n, ref tauq, n, ref numArray2);
        blas.copymatrix(ref u, 1, m, 1, n, ref a, 1, m, 1, n);
        blas.inplacetranspose(ref numArray2, 1, n, 1, n, ref work);
        flag2 = bdsvd.bidiagonalsvddecomposition(ref w, e, n, isupper, false, ref u, 0, ref numArray2, n, ref vt, ncvt);
        blas.matrixmatrixmultiply(ref a, 1, m, 1, n, false, ref numArray2, 1, n, 1, n, true, 1.0, ref u, 1, m, 1, n, 0.0, ref work);
      }
      return flag2;
    }
    if ((double) n > 1.6 * (double) m)
    {
      if (vtneeded == 0)
      {
        lq.lqdecomposition(ref a, m, n, ref tau);
        for (int index1 = 1; index1 <= m - 1; ++index1)
        {
          for (int index2 = index1 + 1; index2 <= m; ++index2)
            a[index1, index2] = 0.0;
        }
        bidiagonal.tobidiagonal(ref a, m, m, ref tauq, ref taup);
        bidiagonal.unpackqfrombidiagonal(ref a, m, m, ref tauq, num2, ref u);
        bidiagonal.unpackdiagonalsfrombidiagonal(ref a, m, m, ref isupper, ref w, ref e);
        double[] work = new double[m + 1];
        blas.inplacetranspose(ref u, 1, num3, 1, num2, ref work);
        bool flag2 = bdsvd.bidiagonalsvddecomposition(ref w, e, m, isupper, false, ref a, 0, ref u, num3, ref vt, 0);
        blas.inplacetranspose(ref u, 1, num3, 1, num2, ref work);
        return flag2;
      }
      lq.lqdecomposition(ref a, m, n, ref tau);
      lq.unpackqfromlq(ref a, m, n, ref tau, num4, ref vt);
      for (int index1 = 1; index1 <= m - 1; ++index1)
      {
        for (int index2 = index1 + 1; index2 <= m; ++index2)
          a[index1, index2] = 0.0;
      }
      bidiagonal.tobidiagonal(ref a, m, m, ref tauq, ref taup);
      bidiagonal.unpackqfrombidiagonal(ref a, m, m, ref tauq, num2, ref u);
      bidiagonal.unpackdiagonalsfrombidiagonal(ref a, m, m, ref isupper, ref w, ref e);
      double[] work1 = new double[Math.Max(m, n) + 1];
      blas.inplacetranspose(ref u, 1, num3, 1, num2, ref work1);
      bool flag3;
      if (additionalmemory < 1)
      {
        bidiagonal.multiplybypfrombidiagonal(ref a, m, m, ref taup, ref vt, m, n, false, true);
        flag3 = bdsvd.bidiagonalsvddecomposition(ref w, e, m, isupper, false, ref a, 0, ref u, num3, ref vt, n);
      }
      else
      {
        bidiagonal.unpackptfrombidiagonal(ref a, m, m, ref taup, m, ref numArray2);
        flag3 = bdsvd.bidiagonalsvddecomposition(ref w, e, m, isupper, false, ref a, 0, ref u, num3, ref numArray2, m);
        blas.copymatrix(ref vt, 1, m, 1, n, ref a, 1, m, 1, n);
        blas.matrixmatrixmultiply(ref numArray2, 1, m, 1, m, false, ref a, 1, m, 1, n, false, 1.0, ref vt, 1, m, 1, n, 0.0, ref work1);
      }
      blas.inplacetranspose(ref u, 1, num3, 1, num2, ref work1);
      return flag3;
    }
    if (m <= n)
    {
      bidiagonal.tobidiagonal(ref a, m, n, ref tauq, ref taup);
      bidiagonal.unpackqfrombidiagonal(ref a, m, n, ref tauq, num2, ref u);
      bidiagonal.unpackptfrombidiagonal(ref a, m, n, ref taup, num4, ref vt);
      bidiagonal.unpackdiagonalsfrombidiagonal(ref a, m, n, ref isupper, ref w, ref e);
      double[] work = new double[m + 1];
      blas.inplacetranspose(ref u, 1, num3, 1, num2, ref work);
      bool flag2 = bdsvd.bidiagonalsvddecomposition(ref w, e, num1, isupper, false, ref a, 0, ref u, num3, ref vt, ncvt);
      blas.inplacetranspose(ref u, 1, num3, 1, num2, ref work);
      return flag2;
    }
    bidiagonal.tobidiagonal(ref a, m, n, ref tauq, ref taup);
    bidiagonal.unpackqfrombidiagonal(ref a, m, n, ref tauq, num2, ref u);
    bidiagonal.unpackptfrombidiagonal(ref a, m, n, ref taup, num4, ref vt);
    bidiagonal.unpackdiagonalsfrombidiagonal(ref a, m, n, ref isupper, ref w, ref e);
    bool flag4;
    if (additionalmemory < 2 | uneeded == 0)
    {
      flag4 = bdsvd.bidiagonalsvddecomposition(ref w, e, num1, isupper, false, ref u, num3, ref a, 0, ref vt, ncvt);
    }
    else
    {
      double[,] numArray3 = new double[num1 + 1, m + 1];
      blas.copyandtranspose(ref u, 1, m, 1, num1, ref numArray3, 1, num1, 1, m);
      flag4 = bdsvd.bidiagonalsvddecomposition(ref w, e, num1, isupper, false, ref u, 0, ref numArray3, m, ref vt, ncvt);
      blas.copyandtranspose(ref numArray3, 1, num1, 1, m, ref u, 1, m, 1, num1);
    }
    return flag4;
  }

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

public static bool bidiagonalsvddecomposition(ref double[] d, double[] e, int n, bool isupper, bool isfractionalaccuracyrequired, ref double[,] u, int nru, ref double[,] c, int ncc, ref double[,] vt, int ncvt)
  {
    e = (double[]) e.Clone();
    return bdsvd.bidiagonalsvddecompositioninternal(ref d, e, n, isupper, isfractionalaccuracyrequired, ref u, 1, nru, ref c, 1, ncc, ref vt, 1, ncvt);
  }

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

private static void solvetridiagonal(double[] a, double[] b, double[] c, double[] d, int n, ref double[] x)
  {
    a = (double[]) a.Clone();
    b = (double[]) b.Clone();
    c = (double[]) c.Clone();
    d = (double[]) d.Clone();
    x = new double[n - 1 + 1];
    a[0] = 0.0;
    c[n - 1] = 0.0;
    for (int index = 1; index <= n - 1; ++index)
    {
      double num = a[index] / b[index - 1];
      b[index] = b[index] - num * c[index - 1];
      d[index] = d[index] - num * d[index - 1];
    }
    x[n - 1] = d[n - 1] / b[n - 1];
    for (int index = n - 2; index >= 0; --index)
      x[index] = (d[index] - c[index] * x[index + 1]) / b[index];
  }

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

public static void spline3buildtable(int n, int diffn, double[] x, double[] y, double boundl, double boundr, ref double[,] ctbl)
  {
    x = (double[]) x.Clone();
    y = (double[]) y.Clone();
    --n;
    int num1 = (n + 1) / 2;
    do
    {
      int num2 = num1;
      do
      {
        int index = num2 - num1;
        bool flag = true;
        do
        {
          if (x[index] <= x[index + num1])
          {
            flag = false;
          }
          else
          {
            double num3 = x[index];
            x[index] = x[index + num1];
            x[index + num1] = num3;
            double num4 = y[index];
            y[index] = y[index + num1];
            y[index + num1] = num4;
          }
          --index;
        }
        while (index >= 0 & flag);
        ++num2;
      }
      while (num2 <= n);
      num1 /= 2;
    }
    while (num1 > 0);
    ctbl = new double[5, n + 1];
    ++n;
    double num5;
    double num6;
    double num7;
    double num8;
    if (diffn == 1)
    {
      num5 = 1.0;
      num6 = 6.0 / (x[1] - x[0]) * ((y[1] - y[0]) / (x[1] - x[0]) - boundl);
      num7 = 1.0;
      num8 = 6.0 / (x[n - 1] - x[n - 2]) * (boundr - (y[n - 1] - y[n - 2]) / (x[n - 1] - x[n - 2]));
    }
    else
    {
      num5 = 0.0;
      num6 = 2.0 * boundl;
      num7 = 0.0;
      num8 = 2.0 * boundr;
    }
    int num9 = n - 1;
    if (n < 2)
      return;
    if (n > 2)
    {
      double num2 = x[1] - x[0];
      double num3 = y[1] - y[0];
      for (int index = 2; index <= num9; ++index)
      {
        double num4 = x[index] - x[index - 1];
        double num10 = y[index] - y[index - 1];
        double num11 = num2 + num4;
        ctbl[1, index - 1] = num4 / num11;
        ctbl[2, index - 1] = 1.0 - ctbl[1, index - 1];
        ctbl[3, index - 1] = 6.0 * (num10 / num4 - num3 / num2) / num11;
        num2 = num4;
        num3 = num10;
      }
    }
    ctbl[1, 0] = -(num5 / 2.0);
    ctbl[2, 0] = num6 / 2.0;
    if (n != 2)
    {
      for (int index = 2; index <= num9; ++index)
      {
        double num2 = ctbl[2, index - 1] * ctbl[1, index - 2] + 2.0;
        ctbl[1, index - 1] = -(ctbl[1, index - 1] / num2);
        ctbl[2, index - 1] = (ctbl[3, index - 1] - ctbl[2, index - 1] * ctbl[2, index - 2]) / num2;
      }
    }
    double num12 = (num8 - num7 * ctbl[2, num9 - 1]) / (num7 * ctbl[1, num9 - 1] + 2.0);
    for (int index1 = 1; index1 <= num9; ++index1)
    {
      int index2 = n - index1;
      double num2 = ctbl[1, index2 - 1] * num12 + ctbl[2, index2 - 1];
      double num3 = x[index2] - x[index2 - 1];
      ctbl[3, index2 - 1] = (num12 - num2) / num3 / 6.0;
      ctbl[2, index2 - 1] = num2 / 2.0;
      ctbl[1, index2 - 1] = (y[index2] - y[index2 - 1]) / num3 - (ctbl[2, index2 - 1] + ctbl[3, index2 - 1] * num3) * num3;
      num12 = num2;
    }
    for (int index = 1; index <= n; ++index)
    {
      ctbl[0, index - 1] = y[index - 1];
      ctbl[4, index - 1] = x[index - 1];
    }
  }

19 Source : UnityARBuildPostprocessor.cs
with MIT License
from 734843327

static void UpdateDefinesInFile(string file, Dictionary<string, bool> valuesToUpdate)
	{
		string[] src = File.ReadAllLines(file);
		var copy = (string[])src.Clone();

		foreach (var kvp in valuesToUpdate)
			AddOrReplaceCppMacro(ref copy, kvp.Key, kvp.Value ? "1" : "0");

		if (!copy.SequenceEqual(src))
			File.WriteAllLines(file, copy);
	}

19 Source : FdbMemoizedTuple.cs
with MIT License
from abdullin

public FdbMemoizedTuple Copy()
		{
			return new FdbMemoizedTuple(
				(object[])(m_items.Clone()),
				m_packed.Memoize()
			);
		}

19 Source : MD5.cs
with MIT License
from adamfisher

public byte[] ComputeHash(byte[] buffer, int offset, int count)
        {
            Initialize();
            HashCore(buffer, offset, count);
            this.HashValue = HashFinal();
            return (byte[])this.HashValue.Clone();
        }

19 Source : MD5.cs
with MIT License
from adamfisher

public byte[] ComputeHash(Stream inputStream)
        {
            Initialize();
            int count;
            byte[] buffer = new byte[4096];
            while (0 < (count = inputStream.Read(buffer, 0, 4096)))
            {
                HashCore(buffer, 0, count);
            }
            this.HashValue = HashFinal();
            return (byte[])this.HashValue.Clone();
        }

19 Source : TerrainMap.cs
with MIT License
from Adsito

public void Push()
	{
		if (src != dst) return;

		dst = (T[])src.Clone();
	}

19 Source : GenericInstantiation.cs
with GNU General Public License v3.0
from Aekras1a

public bool Instantiate(MethodSpec methodSpec, out MethodDef def)
        {
            if(instantiations.TryGetValue(methodSpec, out def))
                return true;

            var genericArguments = new GenericArguments();
            genericArguments.PushMethodArgs(methodSpec.GenericInstMethodSig.GenericArguments);
            var originDef = methodSpec.Method.ResolveMethodDefThrow();

            var newSig = ResolveMethod(originDef.MethodSig, genericArguments);
            newSig.Generic = false;
            newSig.GenParamCount = 0;

            string newName = originDef.Name;
            foreach(var typeArg in methodSpec.GenericInstMethodSig.GenericArguments)
                newName += ";" + typeArg.TypeName;

            def = new MethodDefUser(newName, newSig, originDef.ImplAttributes, originDef.Attributes);
            var thisParam = originDef.HasThis ? originDef.Parameters[0].Type : null;
            def.DeclaringType2 = originDef.DeclaringType2;
            if(thisParam != null) def.Parameters[0].Type = thisParam;

            foreach(var declSec in originDef.DeclSecurities)
                def.DeclSecurities.Add(declSec);
            def.ImplMap = originDef.ImplMap;
            foreach(var ov in originDef.Overrides)
                def.Overrides.Add(ov);

            def.Body = new CilBody();
            def.Body.InitLocals = originDef.Body.InitLocals;
            def.Body.MaxStack = originDef.Body.MaxStack;
            foreach(var variable in originDef.Body.Variables)
            {
                var newVar = new Local(variable.Type);
                def.Body.Variables.Add(newVar);
            }

            var instrMap = new Dictionary<Instruction, Instruction>();
            foreach(var instr in originDef.Body.Instructions)
            {
                var newInstr = new Instruction(instr.OpCode, ResolveOperand(instr.Operand, genericArguments));
                def.Body.Instructions.Add(newInstr);
                instrMap[instr] = newInstr;
            }
            foreach(var instr in def.Body.Instructions)
                if(instr.Operand is Instruction)
                {
                    instr.Operand = instrMap[(Instruction) instr.Operand];
                }
                else if(instr.Operand is Instruction[])
                {
                    var targets = (Instruction[]) ((Instruction[]) instr.Operand).Clone();
                    for(var i = 0; i < targets.Length; i++)
                        targets[i] = instrMap[targets[i]];
                    instr.Operand = targets;
                }
            def.Body.UpdateInstructionOffsets();

            foreach(var eh in originDef.Body.ExceptionHandlers)
            {
                var newEH = new ExceptionHandler(eh.HandlerType);
                newEH.TryStart = instrMap[eh.TryStart];
                newEH.HandlerStart = instrMap[eh.HandlerStart];
                if(eh.TryEnd != null)
                    newEH.TryEnd = instrMap[eh.TryEnd];
                if(eh.HandlerEnd != null)
                    newEH.HandlerEnd = instrMap[eh.HandlerEnd];
                if(eh.CatchType != null)
                    newEH.CatchType = genericArguments.Resolve(newEH.CatchType.ToTypeSig()).ToTypeDefOrRef();
                else if(eh.FilterStart != null)
                    newEH.FilterStart = instrMap[eh.FilterStart];

                def.Body.ExceptionHandlers.Add(newEH);
            }

            instantiations[methodSpec] = def;
            return false;
        }

19 Source : Password.cs
with MIT License
from AElfProject

public char[] GetPreplacedword()
        {
            return (char[]) _preplacedword.Clone();
        }

19 Source : ManualMap.cs
with Apache License 2.0
from aequabit

private static bool LoadDependencies(JLibrary.PortableExecutable.PortableExecutable image, IntPtr hProcess, int processId)
        {
            List<string> list = new List<string>();
            string lpBuffer = string.Empty;
            bool flag = false;
            foreach (IMAGE_IMPORT_DESCRIPTOR image_import_descriptor in image.EnumImports())
            {
                if ((image.ReadString((long) image.GetPtrFromRVA(image_import_descriptor.Name), SeekOrigin.Begin, out lpBuffer, -1, null) && !string.IsNullOrEmpty(lpBuffer)) && GetRemoteModuleHandle(lpBuffer, processId).IsNull())
                {
                    list.Add(lpBuffer);
                }
            }
            if (list.Count > 0)
            {
                byte[] data = ExtractManifest(image);
                string str2 = string.Empty;
                if (data == null)
                {
                    if (string.IsNullOrEmpty(image.FileLocation) || !File.Exists(Path.Combine(Path.GetDirectoryName(image.FileLocation), Path.GetFileName(image.FileLocation) + ".manifest")))
                    {
                        IntPtr[] ptrArray = InjectionMethod.Create(InjectionMethodType.Standard).InjectAll(list.ToArray(), hProcess);
                        foreach (IntPtr ptr in ptrArray)
                        {
                            if (ptr.IsNull())
                            {
                                return false;
                            }
                        }
                        return true;
                    }
                    str2 = Path.Combine(Path.GetDirectoryName(image.FileLocation), Path.GetFileName(image.FileLocation) + ".manifest");
                }
                else
                {
                    str2 = Utils.WriteTempData(data);
                }
                if (string.IsNullOrEmpty(str2))
                {
                    return false;
                }
                IntPtr ptr2 = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) RESOLVER_STUB.Length, 0x3000, 0x40);
                IntPtr lpAddress = WinAPI.CreateRemotePointer(hProcess, Encoding.ASCII.GetBytes(str2 + "\0"), 4);
                IntPtr ptr4 = WinAPI.CreateRemotePointer(hProcess, Encoding.ASCII.GetBytes(string.Join("\0", list.ToArray()) + "\0"), 4);
                if (!ptr2.IsNull())
                {
                    byte[] array = (byte[]) RESOLVER_STUB.Clone();
                    uint lpNumberOfBytesRead = 0;
                    BitConverter.GetBytes(FN_CREATEACTCTXA.Subtract(ptr2.Add(((long) 0x3fL))).ToInt32()).CopyTo(array, 0x3b);
                    BitConverter.GetBytes(FN_ACTIVATEACTCTX.Subtract(ptr2.Add(((long) 0x58L))).ToInt32()).CopyTo(array, 0x54);
                    BitConverter.GetBytes(FN_GETMODULEHANDLEA.Subtract(ptr2.Add(((long) 0x84L))).ToInt32()).CopyTo(array, 0x80);
                    BitConverter.GetBytes(FN_LOADLIBRARYA.Subtract(ptr2.Add(((long) 0x92L))).ToInt32()).CopyTo(array, 0x8e);
                    BitConverter.GetBytes(FN_DEACTIVATEACTCTX.Subtract(ptr2.Add(((long) 200L))).ToInt32()).CopyTo(array, 0xc4);
                    BitConverter.GetBytes(FN_RELEASEACTCTX.Subtract(ptr2.Add(((long) 0xd1L))).ToInt32()).CopyTo(array, 0xcd);
                    BitConverter.GetBytes(lpAddress.ToInt32()).CopyTo(array, 0x1f);
                    BitConverter.GetBytes(list.Count).CopyTo(array, 40);
                    BitConverter.GetBytes(ptr4.ToInt32()).CopyTo(array, 0x31);
                    if (WinAPI.WriteProcessMemory(hProcess, ptr2, array, array.Length, out lpNumberOfBytesRead) && (lpNumberOfBytesRead == array.Length))
                    {
                        uint num2 = WinAPI.RunThread(hProcess, ptr2, 0, 0x1388);
                        flag = (num2 != uint.MaxValue) && (num2 != 0);
                    }
                    WinAPI.VirtualFreeEx(hProcess, ptr4, 0, 0x8000);
                    WinAPI.VirtualFreeEx(hProcess, lpAddress, 0, 0x8000);
                    WinAPI.VirtualFreeEx(hProcess, ptr2, 0, 0x8000);
                }
            }
            return flag;
        }

19 Source : StandardInjectionMethod.cs
with Apache License 2.0
from aequabit

public override bool[] UnloadAll(IntPtr[] hModules, IntPtr hProcess)
        {
            bool[] flagArray2;
            this.ClearErrors();
            IntPtr zero = IntPtr.Zero;
            IntPtr ptr = IntPtr.Zero;
            IntPtr ptr3 = IntPtr.Zero;
            try
            {
                int num2;
                uint lpNumberOfBytesRead = 0;
                IntPtr procAddress = WinAPI.GetProcAddress(WinAPI.GetModuleHandleA("kernel32.dll"), "FreeLibrary");
                if (procAddress.IsNull())
                {
                    throw new Exception("Unable to find necessary function entry points in the remote process");
                }
                zero = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, ((uint) hModules.Length) << 2, 0x3000, 4);
                ptr = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) ((hModules.Length + 1) << 2), 0x3000, 4);
                ptr3 = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) MULTIUNLOAD_STUB.Length, 0x3000, 0x40);
                if ((zero.IsNull() || ptr.IsNull()) || ptr3.IsNull())
                {
                    throw new InvalidOperationException("Unable to allocate memory in the remote process");
                }
                byte[] array = new byte[(hModules.Length + 1) << 2];
                for (num2 = 0; num2 < hModules.Length; num2++)
                {
                    BitConverter.GetBytes(hModules[num2].ToInt32()).CopyTo(array, (int) (num2 << 2));
                }
                WinAPI.WriteProcessMemory(hProcess, ptr, array, array.Length, out lpNumberOfBytesRead);
                byte[] buffer2 = (byte[]) MULTIUNLOAD_STUB.Clone();
                BitConverter.GetBytes(ptr.ToInt32()).CopyTo(buffer2, 7);
                BitConverter.GetBytes(zero.ToInt32()).CopyTo(buffer2, 15);
                BitConverter.GetBytes(procAddress.Subtract(ptr3.Add(((long) 0x38L))).ToInt32()).CopyTo(buffer2, 0x34);
                if (!(WinAPI.WriteProcessMemory(hProcess, ptr3, buffer2, buffer2.Length, out lpNumberOfBytesRead) && (lpNumberOfBytesRead == buffer2.Length)))
                {
                    throw new InvalidOperationException("Unable to write the function stub to the remote process.");
                }
                if (WinAPI.RunThread(hProcess, ptr3, 0, 0x3e8) == uint.MaxValue)
                {
                    throw new InvalidOperationException("Error occurred when running remote function stub.");
                }
                byte[] buffer3 = WinAPI.ReadRemoteMemory(hProcess, zero, ((uint) hModules.Length) << 2);
                if (buffer3 == null)
                {
                    throw new Exception("Unable to read results from the remote process.");
                }
                bool[] flagArray = new bool[hModules.Length];
                for (num2 = 0; num2 < flagArray.Length; num2++)
                {
                    flagArray[num2] = BitConverter.ToInt32(buffer3, num2 << 2) != 0;
                }
                flagArray2 = flagArray;
            }
            catch (Exception exception)
            {
                this.SetLastError(exception);
                flagArray2 = null;
            }
            finally
            {
                WinAPI.VirtualFreeEx(hProcess, ptr3, 0, 0x8000);
                WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
                WinAPI.VirtualFreeEx(hProcess, ptr, 0, 0x8000);
            }
            return flagArray2;
        }

19 Source : ManualMap.cs
with Apache License 2.0
from aequabit

private static IntPtr MapModule(JLibrary.PortableExecutable.PortableExecutable image, IntPtr hProcess, bool preserveHeaders = false)
        {
            if (hProcess.IsNull() || hProcess.Compare(-1L))
            {
                throw new ArgumentException("Invalid process handle.", "hProcess");
            }
            if (image == null)
            {
                throw new ArgumentException("Cannot map a non-existant PE Image.", "image");
            }
            int processId = WinAPI.GetProcessId(hProcess);
            if (processId == 0)
            {
                throw new ArgumentException("Provided handle doesn't have sufficient permissions to inject", "hProcess");
            }
            IntPtr zero = IntPtr.Zero;
            IntPtr ptr = IntPtr.Zero;
            uint lpNumberOfBytesRead = 0;
            try
            {
                zero = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, image.NTHeader.OptionalHeader.SizeOfImage, 0x3000, 4);
                if (zero.IsNull())
                {
                    throw new InvalidOperationException("Unable to allocate memory in the remote process.");
                }
                PatchRelocations(image, zero);
                LoadDependencies(image, hProcess, processId);
                PatchImports(image, hProcess, processId);
                if (preserveHeaders)
                {
                    long num3 = (long) (((image.DOSHeader.e_lfanew + Marshal.SizeOf(typeof(IMAGE_FILE_HEADER))) + ((long) 4L)) + image.NTHeader.FileHeader.SizeOfOptionalHeader);
                    byte[] buffer = new byte[num3];
                    if (image.Read(0L, SeekOrigin.Begin, buffer))
                    {
                        WinAPI.WriteProcessMemory(hProcess, zero, buffer, buffer.Length, out lpNumberOfBytesRead);
                    }
                }
                MapSections(image, hProcess, zero);
                if (image.NTHeader.OptionalHeader.AddressOfEntryPoint <= 0)
                {
                    return zero;
                }
                byte[] array = (byte[]) DLLMAIN_STUB.Clone();
                BitConverter.GetBytes(zero.ToInt32()).CopyTo(array, 11);
                ptr = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) DLLMAIN_STUB.Length, 0x3000, 0x40);
                if (ptr.IsNull() || (!WinAPI.WriteProcessMemory(hProcess, ptr, array, array.Length, out lpNumberOfBytesRead) || (lpNumberOfBytesRead != array.Length)))
                {
                    throw new InvalidOperationException("Unable to write stub to the remote process.");
                }
                IntPtr hObject = WinAPI.CreateRemoteThread(hProcess, 0, 0, ptr, (uint) zero.Add(((long) image.NTHeader.OptionalHeader.AddressOfEntryPoint)).ToInt32(), 0, 0);
                if (WinAPI.WaitForSingleObject(hObject, 0x1388) != 0L)
                {
                    return zero;
                }
                WinAPI.GetExitCodeThread(hObject, out lpNumberOfBytesRead);
                if (lpNumberOfBytesRead == 0)
                {
                    WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
                    throw new Exception("Entry method of module reported a failure " + Marshal.GetLastWin32Error().ToString());
                }
                WinAPI.VirtualFreeEx(hProcess, ptr, 0, 0x8000);
                WinAPI.CloseHandle(hObject);
            }
            catch (Exception exception)
            {
                if (!zero.IsNull())
                {
                    WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
                }
                if (!ptr.IsNull())
                {
                    WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
                }
                zero = IntPtr.Zero;
                throw exception;
            }
            return zero;
        }

19 Source : ManualMap.cs
with Apache License 2.0
from aequabit

public override bool Unload(IntPtr hModule, IntPtr hProcess)
        {
            this.ClearErrors();
            if (hModule.IsNull())
            {
                throw new ArgumentNullException("hModule", "Invalid module handle");
            }
            if (hProcess.IsNull() || hProcess.Compare(-1L))
            {
                throw new ArgumentException("Invalid process handle.", "hProcess");
            }
            IntPtr zero = IntPtr.Zero;
            uint lpNumberOfBytesRead = 0;
            try
            {
                uint num2 = FindEntryPoint(hProcess, hModule);
                if (num2 != 0)
                {
                    byte[] array = (byte[]) DLLMAIN_STUB.Clone();
                    BitConverter.GetBytes(hModule.ToInt32()).CopyTo(array, 11);
                    BitConverter.GetBytes((uint) 0).CopyTo(array, 6);
                    BitConverter.GetBytes((uint) 0x3e8).CopyTo(array, 1);
                    zero = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) DLLMAIN_STUB.Length, 0x3000, 0x40);
                    if (zero.IsNull() || (!WinAPI.WriteProcessMemory(hProcess, zero, array, array.Length, out lpNumberOfBytesRead) || (lpNumberOfBytesRead != array.Length)))
                    {
                        throw new InvalidOperationException("Unable to write stub to the remote process.");
                    }
                    IntPtr hObject = WinAPI.CreateRemoteThread(hProcess, 0, 0, zero, (uint) hModule.Add(((long) num2)).ToInt32(), 0, 0);
                    if (WinAPI.WaitForSingleObject(hObject, 0x1388) == 0L)
                    {
                        WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
                        WinAPI.CloseHandle(hObject);
                        return WinAPI.VirtualFreeEx(hProcess, hModule, 0, 0x8000);
                    }
                    return false;
                }
                return WinAPI.VirtualFreeEx(hProcess, hModule, 0, 0x8000);
            }
            catch (Exception exception)
            {
                this.SetLastError(exception);
                return false;
            }
        }

19 Source : StandardInjectionMethod.cs
with Apache License 2.0
from aequabit

protected virtual IntPtr CreateMultiLoadStub(string[] paths, IntPtr hProcess, out IntPtr pModuleBuffer, uint nullmodule = 0)
        {
            IntPtr ptr6;
            pModuleBuffer = IntPtr.Zero;
            IntPtr zero = IntPtr.Zero;
            try
            {
                IntPtr moduleHandleA = WinAPI.GetModuleHandleA("kernel32.dll");
                IntPtr procAddress = WinAPI.GetProcAddress(moduleHandleA, "LoadLibraryA");
                IntPtr ptr = WinAPI.GetProcAddress(moduleHandleA, "GetModuleHandleA");
                if (procAddress.IsNull() || ptr.IsNull())
                {
                    throw new Exception("Unable to find necessary function entry points in the remote process");
                }
                pModuleBuffer = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, ((uint) paths.Length) << 2, 0x3000, 4);
                IntPtr ptr5 = WinAPI.CreateRemotePointer(hProcess, Encoding.ASCII.GetBytes(string.Join("\0", paths) + "\0"), 4);
                if (pModuleBuffer.IsNull() || ptr5.IsNull())
                {
                    throw new InvalidOperationException("Unable to allocate memory in the remote process");
                }
                try
                {
                    uint lpNumberOfBytesRead = 0;
                    byte[] array = new byte[paths.Length << 2];
                    for (int i = 0; i < (array.Length >> 2); i++)
                    {
                        BitConverter.GetBytes(nullmodule).CopyTo(array, (int) (i << 2));
                    }
                    WinAPI.WriteProcessMemory(hProcess, pModuleBuffer, array, array.Length, out lpNumberOfBytesRead);
                    byte[] buffer2 = (byte[]) MULTILOAD_STUB.Clone();
                    zero = WinAPI.VirtualAllocEx(hProcess, IntPtr.Zero, (uint) buffer2.Length, 0x3000, 0x40);
                    if (zero.IsNull())
                    {
                        throw new InvalidOperationException("Unable to allocate memory in the remote process");
                    }
                    BitConverter.GetBytes(ptr5.ToInt32()).CopyTo(buffer2, 7);
                    BitConverter.GetBytes(paths.Length).CopyTo(buffer2, 15);
                    BitConverter.GetBytes(pModuleBuffer.ToInt32()).CopyTo(buffer2, 0x18);
                    BitConverter.GetBytes(ptr.Subtract(zero.Add(((long) 0x38L))).ToInt32()).CopyTo(buffer2, 0x34);
                    BitConverter.GetBytes(procAddress.Subtract(zero.Add(((long) 0x45L))).ToInt32()).CopyTo(buffer2, 0x41);
                    if (!(WinAPI.WriteProcessMemory(hProcess, zero, buffer2, buffer2.Length, out lpNumberOfBytesRead) && (lpNumberOfBytesRead == buffer2.Length)))
                    {
                        throw new Exception("Error creating the remote function stub.");
                    }
                    ptr6 = zero;
                }
                finally
                {
                    WinAPI.VirtualFreeEx(hProcess, pModuleBuffer, 0, 0x8000);
                    WinAPI.VirtualFreeEx(hProcess, ptr5, 0, 0x8000);
                    if (!zero.IsNull())
                    {
                        WinAPI.VirtualFreeEx(hProcess, zero, 0, 0x8000);
                    }
                    pModuleBuffer = IntPtr.Zero;
                }
            }
            catch (Exception exception)
            {
                this.SetLastError(exception);
                ptr6 = IntPtr.Zero;
            }
            return ptr6;
        }

19 Source : MainForm.cs
with GNU General Public License v3.0
from AgentRev

void InitFovChanger()
        {
            settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), (string)gameMode.GetValue("c_settingsDirName"));
            settingsFile = Path.Combine(settingsPath, (string)gameMode.GetValue("c_settingsFileName"));
            gameModeFile = Path.Combine(settingsPath, "gamemode.ini");

            pFoV = (dword_ptr)gameMode.GetValue("c_pFoV");
            fFoV = c_FoV;
            doBeep = c_doBeep;
            updateNotify = c_updateNotify;
            hotKeys = c_hotKeys;
            catchKeys = (Keys[])c_catchKeys.Clone();

            this.numFoV.Maximum = Convert.ToDecimal(c_FoV_upperLimit);
            this.numFoV.Minimum = Convert.ToDecimal(c_FoV_lowerLimit);

            if (File.Exists(settingsFile)) ReadSettings();

            lblVersion.Text = "v" + c_toolVer;
            lblVersion.Visible = true;

            IsGameInstalled();

            numFoV.Value = Convert.ToDecimal(fFoV);
            numFoV.Enabled = true;
            ToggleButton(!isRunning(false));
        }

19 Source : MemoryManager.cs
with GNU General Public License v3.0
from aglab2

public void WriteToFile(int maxShown)
        {
            byte[] stars = (byte[]) Stars.Clone();
            if (stars == null) return;

            FixStarCount(stars, maxShown);

            for (int i = 0; i < FileLength; i += 4)
                Array.Reverse(stars, i, 4);

            Process.WriteBytes(filePtr, stars);
        }

19 Source : MainForm.cs
with GNU General Public License v3.0
from AgentRev

void InitFovChanger()
        {
            settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), (string)gameMode.GetValue("c_settingsDirName"));
            settingsFile = Path.Combine(settingsPath, (string)gameMode.GetValue("c_settingsFileName"));
            gameModeFile = Path.Combine(settingsPath, "gamemode.ini");

            pFoV = (int)gameMode.GetValue("c_pFoV");
            fFoV = c_FoV;
            doBeep = c_doBeep;
            updateChk = c_updateChk;
            hotKeys = c_hotKeys;
            catchKeys = (Keys[])c_catchKeys.Clone();

            this.numFoV.Maximum = Convert.ToDecimal(c_FoV_upperLimit);
            this.numFoV.Minimum = Convert.ToDecimal(c_FoV_lowerLimit);

            if (File.Exists(settingsFile)) ReadSettings();

            lblVersion.Text = "v" + c_toolVer;
            lblVersion.Visible = true;

            IsGameInstalled();

            numFoV.Value = Convert.ToDecimal(fFoV);
            numFoV.Enabled = true;
            ToggleButton(!isRunning(false));
        }

19 Source : MD5.cs
with MIT License
from AlaricGilbert

public byte[] ComputeHash(Stream inputStream)
        {
            int num;
            this.Initialize();
            byte[] buffer = new byte[0x1000];
            while (0 < (num = inputStream.Read(buffer, 0, 0x1000)))
            {
                this.HashCore(buffer, 0, num);
            }
            this.HashValue = this.HashFinal();
            return (byte[])this.HashValue.Clone();
        }

19 Source : MD5.cs
with MIT License
from AlaricGilbert

public byte[] ComputeHash(byte[] buffer, int offset, int count)
        {
            this.Initialize();
            this.HashCore(buffer, offset, count);
            this.HashValue = this.HashFinal();
            return (byte[])this.HashValue.Clone();
        }

19 Source : SignedRandomResult`2.cs
with MIT License
from alexanderkozlenko

public byte[] GetSignature()
        {
            return (byte[])_signature.Clone();
        }

19 Source : ReadOnlyArray.cs
with MIT License
from AlexGyver

public T[] ToArray() {
      return (T[])array.Clone();
    }

19 Source : TVec.cs
with MIT License
from alexshtf

public Term[] GetTerms()
        {
            return (Term[])terms.Clone();
        }

19 Source : Program.cs
with MIT License
from alexshtf

static double[] GradientDescent(ICompiledTerm func, double[] init, double stepSize, int iterations)
        {
            // clone the initial argument
            var x = (double[])init.Clone();
            var gradient = new double[x.Length];

            // perform the iterations
            for (int i = 0; i < iterations; ++i)
            {
                // compute the gradient - fill the gradient array
                func.Differentiate(x, gradient);

                // perform a descent step
                for (int j = 0; j < x.Length; ++j)
                    x[j] -= stepSize * gradient[j];
            }

            return x;
        }

19 Source : UtilityFunctions.cs
with Apache License 2.0
from allenai

private static IEnumerable<int[]> Combinations(int m, int n) {
        // Enumerate all possible m-size combinations of [0, 1, ..., n-1] array
        // in lexicographic order (first [0, 1, 2, ..., m-1]).
        // Taken from https://codereview.stackexchange.com/questions/194967/get-all-combinations-of-selecting-k-elements-from-an-n-sized-array
        int[] result = new int[m];
        Stack<int> stack = new Stack<int>(m);
        stack.Push(0);
        while (stack.Count > 0) {
            int index = stack.Count - 1;
            int value = stack.Pop();
            while (value < n) {
                result[index++] = value++;
                stack.Push(value);
                if (index != m) {
                    continue;
                }

                yield return (int[])result.Clone(); // thanks to @xanatos
                // yield return result;
                break;
            }
        }
    }

19 Source : BoundingFrustum.cs
with MIT License
from allenwp

public Vector3[] GetCorners()
        {
            return (Vector3[])this._corners.Clone();
        }

19 Source : DefaultCachingKeyGenerator.cs
with MIT License
from AlphaYu

public string[] GetCacheKeys(MethodInfo methodInfo, object[] args, string prefix)
        {
            var cacheKeys = new List<string>();
            if (args?.Any() == true && args[0].GetType().IsArray)
            {
                foreach (var arg0 in (Array)args[0])
                {
                    var cloneArgs = (object[])args.Clone();
                    cloneArgs[0] = arg0;
                    cacheKeys.Add(GetCacheKey(methodInfo, cloneArgs, prefix));
                }
            }
            else
            {
                cacheKeys.Add(GetCacheKey(methodInfo, args, prefix));
            }

            return cacheKeys.ToArray();
        }

19 Source : Tools.cs
with MIT License
from AmigoCap

public static List<int[]> Bresenham(int[] start, int[] end) {
            List<int[]> results = new List<int[]> {
                (int[])start.Clone()
            };

            int Dx = Math.Abs(end[0] - start[0]), Dy = Math.Abs(end[1] - start[1]), Dz = Math.Abs(end[2] - start[2]);
            int xs = end[0] > start[0] ? 1 : -1, ys = end[1] > start[1] ? 1 : -1, zs = end[2] > start[2] ? 1 : -1;

            if (Dx >= Dy && Dx >= Dz) {
                int p1 = 2 * Dy - Dx, p2 = 2 * Dz - Dx;
                while (start[0] != end[0]) {
                    start[0] += xs;
                    if (p1 >= 0) {
                        start[1] += ys;
                        p1 -= 2 * Dx;
                    }
                    if (p2 >= 0) {
                        start[2] += zs;
                        p2 -= 2 * Dx;
                    }
                    p1 += 2 * Dy;
                    p2 += 2 * Dz;
                    results.Add((int[])start.Clone());
                }
            }
            else if (Dy >= Dx && Dy >= Dz) {
                int p1 = 2 * Dx - Dy, p2 = 2 * Dz - Dy;
                while (start[1] != end[1]) {
                    start[1] += ys;
                    if (p1 >= 0) {
                        start[0] += xs;
                        p1 -= 2 * Dy;
                    }
                    if (p2 >= 0) {
                        start[2] += zs;
                        p2 -= 2 * Dy;
                    }
                    p1 += 2 * Dx;
                    p2 += 2 * Dz;
                    results.Add((int[])start.Clone());
                }
            }
            else {
                int p1 = 2 * Dy - Dz, p2 = 2 * Dx - Dz;
                while (start[2] != end[2]) {
                    start[2] += zs;
                    if (p1 >= 0) {
                        start[1] += ys;
                        p1 -= 2 * Dz;
                    }
                    if (p2 >= 0) {
                        start[0] += xs;
                        p2 -= 2 * Dz;
                    }
                    p1 += 2 * Dy;
                    p2 += 2 * Dx;
                    results.Add((int[])start.Clone());
                }
            }

            return results;
        }

19 Source : Tools.cs
with MIT License
from AmigoCap

public static List<int[]> Amanatides(Vector3 start, Vector3 end) {
            List<int[]> L = new List<int[]>();
            int[] startD = Visualization.Instance.FindDistrictCoords(start);
            int[] endD = Visualization.Instance.FindDistrictCoords(end);
            L.Add((int[])startD.Clone());

            Vector3 v = (end - start).normalized;
            ref Vector3 dSize = ref Visualization.Instance.districtSize;
            Vector3 delta = new Vector3(Mathf.Abs(dSize.x / v.x), Mathf.Abs(dSize.y / v.y), Mathf.Abs(dSize.z / v.z));
            int[] stepD = { v.x < 0 ? -1 : 1, v.y < 0 ? -1 : 1, v.z < 0 ? -1 : 1 };

            Vector3 max = new Vector3(
                Mathf.Abs(((v.x < 0 ? 0 : dSize.x) - FMod(start.x, dSize.x)) / v.x),
                Mathf.Abs(((v.y < 0 ? 0 : dSize.y) - FMod(start.y, dSize.y)) / v.y),
                Mathf.Abs(((v.z < 0 ? 0 : dSize.z) - FMod(start.z, dSize.z)) / v.z));

            CoordsEqualityComparer comparer = new CoordsEqualityComparer();

            while (!comparer.Equals(startD, endD) && L.Count < 50) {
                if (Math.Abs(startD[0] - endD[0]) + Math.Abs(startD[1] - endD[1]) + Math.Abs(startD[2] - endD[2]) == 1) //Adjacent à la fin : utile pour contrer les imprécisions flottantes
                    endD.CopyTo(startD, 0);
                else if (max.x < max.y) {
                    if (max.x < max.z) {
                        startD[0] += stepD[0];
                        max.x += delta.x;
                    }
                    else {
                        startD[2] += stepD[2];
                        max.z += delta.z;
                    }
                }
                else {
                    if (max.y < max.z) {
                        startD[1] += stepD[1];
                        max.y += delta.y;
                    }
                    else {
                        startD[2] += stepD[2];
                        max.z += delta.z;
                    }
                }

                L.Add((int[])startD.Clone());
            }

            return L;
        }

19 Source : Tools.cs
with MIT License
from AmigoCap

public static HashSet<int[]> Amanatides(Vector3 start, Vector3 end, float lineThickness) {
            CoordsEqualityComparer comparer = new CoordsEqualityComparer();
            HashSet<int[]> H = new HashSet<int[]>(comparer);
            int[] startD = Visualization.Instance.FindDistrictCoords(start);
            int[] endD = Visualization.Instance.FindDistrictCoords(end);
            H.Add((int[])startD.Clone());

            Vector3 v = (end - start).normalized;
            Vector3 dSize = Visualization.Instance.districtSize;
            Vector3 delta = new Vector3(Mathf.Abs(dSize.x / v.x), Mathf.Abs(dSize.y / v.y), Mathf.Abs(dSize.z / v.z));
            int[] stepD = { v.x < 0 ? -1 : 1, v.y < 0 ? -1 : 1, v.z < 0 ? -1 : 1 };

            Vector3 max = new Vector3(
                Mathf.Abs(((v.x < 0 ? 0 : dSize.x) - FMod(start.x, dSize.x)) / v.x),
                Mathf.Abs(((v.y < 0 ? 0 : dSize.y) - FMod(start.y, dSize.y)) / v.y),
                Mathf.Abs(((v.z < 0 ? 0 : dSize.z) - FMod(start.z, dSize.z)) / v.z));

            void addByThickness(int dir, ref Vector3 inter) {
                if (dir == 0) {
                    float interX = FMod(inter.x, dSize.x);
                    if (interX < lineThickness) {
                        H.Add(new int[] { startD[0] - 1, startD[1], startD[2] });
                    }
                    if (interX > dSize.x - lineThickness) {
                        H.Add(new int[] { startD[0] + 1, startD[1], startD[2] });
                    }
                }
                else if (dir == 1) {
                    float interY = FMod(inter.y, dSize.y);
                    if (interY < lineThickness) {
                        H.Add(new int[] { startD[0], startD[1] - 1, startD[2] });
                    }
                    if (interY > dSize.y - lineThickness) {
                        H.Add(new int[] { startD[0], startD[1] + 1, startD[2] });
                    }
                }
                else if (dir == 2) {
                    float interZ = FMod(inter.z, dSize.z);
                    if (interZ < lineThickness) {
                        H.Add(new int[] { startD[0], startD[1], startD[2] - 1 });
                    }
                    if (interZ > dSize.z - lineThickness) {
                        H.Add(new int[] { startD[0], startD[1], startD[2] + 1 });
                    }
                }
            }

            while (!comparer.Equals(startD, endD)) {
                if (Math.Abs(startD[0] - endD[0]) + Math.Abs(startD[1] - endD[1]) + Math.Abs(startD[2] - endD[2]) == 1) //Adjacent à la fin : utile pour contrer les imprécisions flottantes
                    endD.CopyTo(startD, 0);
                else if (max.x < max.y) {
                    if (max.x < max.z) {
                        Vector3 inter = start + v * max.x;
                        addByThickness(1, ref inter);
                        addByThickness(2, ref inter);
                        startD[0] += stepD[0];
                        max.x += delta.x;
                    }
                    else {
                        Vector3 inter = start + v * max.z;
                        addByThickness(0, ref inter);
                        addByThickness(1, ref inter);
                        startD[2] += stepD[2];
                        max.z += delta.z;
                    }
                }
                else {
                    if (max.y < max.z) {
                        Vector3 inter = start + v * max.y;
                        addByThickness(0, ref inter);
                        addByThickness(2, ref inter);
                        startD[1] += stepD[1];
                        max.y += delta.y;
                    }
                    else {
                        Vector3 inter = start + v * max.z;
                        addByThickness(0, ref inter);
                        addByThickness(1, ref inter);
                        startD[2] += stepD[2];
                        max.z += delta.z;
                    }
                }

                H.Add((int[])startD.Clone());
            }

            return H;
        }

19 Source : SelectorPart.cs
with MIT License
from AmigoCap

private void FindRibbonsToCheck() {

            Visualization viz = Visualization.Instance;

            BoxCollider districtCollider = gameObject.AddComponent<BoxCollider>();
            districtCollider.size = Vector3.Scale(viz.districtSize, viz.transform.lossyScale);

            districtCollider.center = Vector3.zero;
            Collider primitiveCollider = primitive.GetComponent<Collider>();

            int[] seedDistrict = viz.FindDistrictCoords(viz.transform.InverseTransformPoint(primitive.transform.position));
            Vector3 trueDistrictSize = viz.transform.TransformVector(viz.districtSize);
            float districtDiagLength = trueDistrictSize.magnitude;
            float districtMinSideLength = Mathf.Abs(trueDistrictSize[0]);
            districtMinSideLength = Mathf.Min(districtMinSideLength, Mathf.Abs(trueDistrictSize[1]));
            districtMinSideLength = Mathf.Min(districtMinSideLength, Mathf.Abs(trueDistrictSize[2]));

            Vector3 seedPos = viz.transform.TransformPoint(viz.getDistrictCenter(seedDistrict));
            Vector3 districtUnitTranslation = viz.transform.TransformVector(viz.districtSize);

            CoordsEqualityComparer comparer = new CoordsEqualityComparer();
            Dictionary<int[], byte> districtMap = new Dictionary<int[], byte>(comparer);
            const byte outside = 0;
            const byte border_done = 1;
            const byte border = 2;
            const byte border_or_inside = 3;
            const byte inside_done = 4;
            const byte inside = 5;

            byte getDepth(int[] coords) {
                if (!districtMap.TryGetValue(coords, out byte depth)) {
                    if (Physics.ComputePenetration(districtCollider, seedPos + Vector3.Scale(districtUnitTranslation, new Vector3(coords[0], coords[1], coords[2])), viz.transform.rotation,
                                                   primitiveCollider, primitive.transform.position, primitive.transform.rotation, out _, out float exitDist)) {
                        if (exitDist > districtDiagLength)
                            depth = inside;
                        else if (exitDist < districtMinSideLength)
                            depth = border;
                        else
                            depth = border_or_inside;
                    }
                    else {
                        depth = outside;
                    }
                    districtMap.Add(coords, depth); //getDepth does not clone coordinates, make sure they aren't modified afterwards (preplaced a clone if need be)
                }
                return depth;
            }

            Tools.AddClockStop("Initialized district checking");

            //PHASE 1: starting from the center, find a "border" district

            int[] start = new int[] { 0, 0, 0 };
            while (getDepth((int[])start.Clone()) != outside) {
                start[0] += 1;
            }
            start[0] -= 1;
            districtMap[(int[])start.Clone()] = border;

            Tools.AddClockStop("End of phase 1");

            //PHASE 2: starting from the border district found, create a "shell" of border districts around the (convex) primitive

            HashSet<int[]> districtsToSpreadFrom = new HashSet<int[]>(comparer);
            HashSet<int[]> nextDistrictsToSpreadFrom = new HashSet<int[]>(comparer);
            districtsToSpreadFrom.Add(start);
            int cycle = 0;
            while (districtsToSpreadFrom.Count > 0) {
                foreach (int[] c in districtsToSpreadFrom) {
                    byte depth = getDepth(c);

                    if (depth == inside || depth == border_done) {
                        continue;
                    }

                    int[][] adjacentNeighbours = new int[6][];
                    byte[] adjacentNeighboursDepth = new byte[6];

                    for (int i = 0; i < 6; i++) {
                        adjacentNeighbours[i] = (int[])c.Clone();
                        adjacentNeighbours[i][i / 2] += (i % 2 == 0 ? 1 : -1);
                        adjacentNeighboursDepth[i] = getDepth(adjacentNeighbours[i]);
                    }

                    if (depth == border_or_inside) {
                        //Acertain the depth of the district by looking at all its neighbours' (including diagonal neighbours) depths

                        //First look at the already-obtained adjacent neighbours
                        for (int i = 0; i < 6; i++) {
                            if (adjacentNeighboursDepth[i] == outside) {
                                depth = border;
                                break;
                            }
                        }

                        //If still unknown, look at diagonal neighbours
                        if (depth == border_or_inside) {
                            for (int i = -1; i <= 1; i++) {
                                for (int j = -1; j <= 1; j++) {
                                    for (int k = -1; k <= 1; k++) {
                                        if (Math.Abs(i) + Math.Abs(j) + Math.Abs(k) < 2)
                                            continue;
                                        if (getDepth(new int[] { c[0] + i, c[1] + j, c[2] + k }) == outside) {
                                            depth = border;
                                            break;
                                        }
                                    }
                                    if (depth == border)
                                        break;
                                }
                                if (depth == border)
                                    break;
                            }

                            //If none of the neighbours was outside, then we know the district is inside.
                            if (depth == border_or_inside)
                                depth = inside;
                        }
                    }

                    if (depth == border) {
                        for (int i = 0; i < 6; i++) {
                            if (adjacentNeighboursDepth[i] == border || adjacentNeighboursDepth[i] == border_or_inside)
                                nextDistrictsToSpreadFrom.Add(adjacentNeighbours[i]);
                        }

                        int[] true_c = new int[] { c[0] + seedDistrict[0], c[1] + seedDistrict[1], c[2] + seedDistrict[2] };
                        if (viz.districts.TryGetValue(true_c, out Visualization.District d)) {
                            if (viz.debugMode)
                                viz.districtsToHighlight[0].Add(true_c); //DEBUG

                            foreach (Atom a in d.atoms) {
                                if (a.ShouldDisplay) {
                                    ribbonsToCheck.Add(a);
                                }
                            }
                        }

                        depth = border_done;
                    }

                    districtMap[c] = depth;
                }

                Tools.AddSubClockStop("End of cycle 2." + cycle.ToString() + "; " + districtsToSpreadFrom.Count.ToString() + " districts treated");

                HashSet<int[]> temp = districtsToSpreadFrom;
                districtsToSpreadFrom.Clear();
                districtsToSpreadFrom = nextDistrictsToSpreadFrom;
                nextDistrictsToSpreadFrom = temp;

                cycle++;
            }

            Tools.AddClockStop("End of phase 2");

            //PHASE 3: starting from the center, flood the created shell

            districtsToSpreadFrom.Clear();
            nextDistrictsToSpreadFrom.Clear();
            int[] center = new int[] { 0, 0, 0 };
            if (districtMap.ContainsKey(center) && districtMap[center] != inside) {
                Tools.AddClockStop("Skipping phase 3: center district is not an inside district");
            }
            else {
                districtsToSpreadFrom.Add(center);
            }
            cycle = 0;
            while (districtsToSpreadFrom.Count > 0) {
                foreach (int[] c in districtsToSpreadFrom) {
                    for (int i = 0; i < 3; i++) {
                        for (int j = -1; j <= 1; j += 2) {
                            if (c[i] == 0 || c[i] > 0 == j > 0) { //Only flood towards the exterior (the selector part is convex)
                                int[] neighbour = (int[])c.Clone();
                                neighbour[i] += j;
                                if (!districtMap.TryGetValue(neighbour, out byte neighbourDepth)) {
                                    neighbourDepth = inside;
                                    districtMap[neighbour] = neighbourDepth;
                                }
                                if (neighbourDepth == inside)
                                    nextDistrictsToSpreadFrom.Add(neighbour);
                            }
                        }
                    }

                    int[] true_c = new int[] { c[0] + seedDistrict[0], c[1] + seedDistrict[1], c[2] + seedDistrict[2] }; //True coordinates of the district in the visualization dictionary

                    if (viz.districts.TryGetValue(true_c, out Visualization.District d)) {
                        if (viz.debugMode)
                            viz.districtsToHighlight[1].Add(true_c); //DEBUG

                        foreach (Atom a in d.atoms) {
                            if (a.ShouldDisplay) {
                                TouchedRibbons.Add(a);
                            }
                        }
                    }

                    districtMap[c] = inside_done;
                }

                Tools.AddSubClockStop("End of cycle 3." + cycle.ToString() + "; " + districtsToSpreadFrom.Count.ToString() + " districts treated");

                HashSet<int[]> temp = districtsToSpreadFrom;
                districtsToSpreadFrom.Clear();
                districtsToSpreadFrom = nextDistrictsToSpreadFrom;
                nextDistrictsToSpreadFrom = temp;

                cycle++;
            }

            Tools.AddClockStop("End of phase 3");

            ribbonsToCheck.ExceptWith(touchedRibbons);

            Tools.AddClockStop("Removed obvious touchedRibbons from ribbonsToCheck");

            Destroy(districtCollider);
        }

19 Source : Visualization.cs
with MIT License
from AmigoCap

void FindDistrictBoundaries() {
            if (districts.Count == 0) {
                _lowerDistrict = new int[] { 0, 0, 0 };
                _upperDistrict = new int[] { 0, 0, 0 };
                return;
            }

            var e = districts.GetEnumerator();
            e.MoveNext();
            _lowerDistrict = (int[])e.Current.Key.Clone();
            _upperDistrict = (int[])e.Current.Key.Clone();

            while (e.MoveNext()) {
                for (int i = 0; i < 3; i++) {
                    _lowerDistrict[i] = Math.Min(_lowerDistrict[i], e.Current.Key[i]);
                    _upperDistrict[i] = Math.Max(_upperDistrict[i], e.Current.Key[i]);
                }
            }
        }

19 Source : EmbedBorder.cs
with MIT License
from AngeloCresta

public override void DrawBorder(
			ChartGraphics graph, 
			BorderSkin borderSkin,
			RectangleF rect, 
			Color backColor, 
			ChartHatchStyle backHatchStyle, 
			string backImage, 
			ChartImageWrapMode backImageWrapMode, 
			Color backImageTransparentColor,
			ChartImageAlignmentStyle backImageAlign,
			GradientStyle backGradientStyle, 
			Color backSecondaryColor, 
			Color borderColor, 
			int borderWidth, 
			ChartDashStyle borderDashStyle)	
		{
			drawBottomShadow = true;
			sunken = false;
			outsideShadowRate = .9f;
			drawOutsideTopLeftShadow = false;
			bool oldScrewsFlag = this.drawScrews;
			this.drawScrews = false;
			base.DrawBorder(
				graph, 
				borderSkin, 
				rect, 
				borderSkin.BackColor, 
				borderSkin.BackHatchStyle, 
				borderSkin.BackImage, 
				borderSkin.BackImageWrapMode, 
				borderSkin.BackImageTransparentColor, 
				borderSkin.BackImageAlignment, 
				borderSkin.BackGradientStyle, 
				borderSkin.BackSecondaryColor, 
				borderSkin.BorderColor, 
				borderSkin.BorderWidth, 
				borderSkin.BorderDashStyle);

			this.drawScrews = oldScrewsFlag;
			rect.X += sizeLeftTop.Width;
			rect.Y += sizeLeftTop.Height;
			rect.Width -= sizeRightBottom.Width + sizeLeftTop.Width;
			rect.Height -= sizeRightBottom.Height + sizeLeftTop.Height;
			if(rect.Width > 0 && rect.Height > 0 )
			{
				float[] oldCorners = new float[8];
				oldCorners = (float[])cornerRadius.Clone();
				cornerRadius = innerCorners;
				drawBottomShadow = false;
				sunken = true;
				drawOutsideTopLeftShadow = true;
				outsideShadowRate = 1.4f;
				Color oldPageColor = borderSkin.PageColor;
				borderSkin.PageColor = Color.Transparent;
				base.DrawBorder(
					graph, 
					borderSkin,
					rect, 
					backColor, 
					backHatchStyle, 
					backImage, 
					backImageWrapMode, 
					backImageTransparentColor, 
					backImageAlign, 
					backGradientStyle, 
					backSecondaryColor, 
					borderColor, 
					borderWidth, 
					borderDashStyle	);
				borderSkin.PageColor = oldPageColor;
				cornerRadius = oldCorners;
			}
		}

19 Source : Linedef.cs
with GNU General Public License v3.0
from anotak

public void CopyPropertiesTo(Linedef l)
		{
			l.BeforePropsChange();
			
			// Copy properties
			l.action = action;
			l.args = (int[])args.Clone();
			l.flags = new Dictionary<string, bool>(flags);
			l.tag = tag;
			l.updateneeded = true;
			l.activate = activate;
			l.impreplacedableflag = impreplacedableflag;
			l.blocksoundflag = blocksoundflag;
			base.CopyPropertiesTo(l);
		}

19 Source : Thing.cs
with GNU General Public License v3.0
from anotak

public void CopyPropertiesTo(Thing t)
		{
			t.BeforePropsChange();
			
			// Copy properties
			t.type = type;
			t.anglerad = anglerad;
			t.angledoom = angledoom;
			t.pos = pos;
			t.flags = new Dictionary<string,bool>(flags);
			t.tag = tag;
			t.action = action;
			t.args = (int[])args.Clone();
			t.size = size;
			t.color = color;
			t.iconoffset = iconoffset;
			t.fixedsize = fixedsize;
			base.CopyPropertiesTo(t);
		}

See More Examples