System.Math.Max(int, int)

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

5061 Examples 7

19 View Source File : TestLIBIGL.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

public static Mesh CreateLIBIGLMeshBoolean(Mesh m1_, Mesh m2_, int Difference_Union_Intersection = 0) {
            // return Unsafe.LIBIGL_MeshBoolean_Create(n);


            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Clean Mesh
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            m1_.Vertices.UseDoublePrecisionVertices = true;
            m2_.Vertices.UseDoublePrecisionVertices = true;
            Mesh m1 = m1_.DuplicateMesh();
            Mesh m2 = m2_.DuplicateMesh();
            m1.Vertices.UseDoublePrecisionVertices = true;
            m2.Vertices.UseDoublePrecisionVertices = true;
            m1.Faces.ConvertQuadsToTriangles();
            m2.Faces.ConvertQuadsToTriangles();

            m1.Vertices.CombineIdentical(true, true);
            m1.Vertices.CullUnused();
            m1.Weld(3.14159265358979);
            m1.FillHoles();
            m1.RebuildNormals();

            m2.Vertices.CombineIdentical(true, true);
            m2.Vertices.CullUnused();
            m2.Weld(3.14159265358979);
            m2.FillHoles();
            m2.RebuildNormals();


            if (!m1.IsValid || !m1.IsClosed || !m2.IsValid || !m2.IsClosed)
                return null;


            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Send Vertices and Faces to C++
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            double[] ptCoordArr1 = new double[m1.Vertices.Count * 3];
            for (int i = 0; i < m1.Vertices.Count; i++) {
                ptCoordArr1[i * 3 + 0] = m1.Vertices.Point3dAt(i).X;
                ptCoordArr1[i * 3 + 1] = m1.Vertices.Point3dAt(i).Y;
                ptCoordArr1[i * 3 + 2] = m1.Vertices.Point3dAt(i).Z;
            }
            var ptCount1 = (ulong)m1.Vertices.Count;


            int[] facesArr1 = m1.Faces.ToIntArray(true);
            var facesCount1 = (ulong)m1.Faces.Count;


            double[] ptCoordArr2 = new double[m2.Vertices.Count * 3];
            for (int i = 0; i < m2.Vertices.Count; i++) {
                ptCoordArr2[i * 3 + 0] = m2.Vertices.Point3dAt(i).X;
                ptCoordArr2[i * 3 + 1] = m2.Vertices.Point3dAt(i).Y;
                ptCoordArr2[i * 3 + 2] = m2.Vertices.Point3dAt(i).Z;
            }
            var ptCount2 = (ulong)m2.Vertices.Count;

            int[] facesArr2 = m2.Faces.ToIntArray(true);
            var facesCount2 = (ulong)m2.Faces.Count;

            ////Rhino.RhinoApp.WriteLine(ptCoordArr1.Length.ToString() + " " + ptCount1.ToString());
            ////Rhino.RhinoApp.WriteLine(facesArr1.Length.ToString() + " " + facesCount1.ToString());
            ////Rhino.RhinoApp.WriteLine(ptCoordArr2.Length.ToString() + " " + ptCount2.ToString());
            ////Rhino.RhinoApp.WriteLine(facesArr2.Length.ToString() + " " + facesCount2.ToString());



            ////Inputs
            IntPtr vertexCoordPointer = IntPtr.Zero;
            int nVertices = 0;
            IntPtr faceIndicesPointer = IntPtr.Zero;
            int nFaces = 0;

            //Call C++ method
            UnsafeLIBIGL.LIBIGL_MeshBoolean_Create(ptCoordArr1, ptCount1, facesArr1, facesCount1, ptCoordArr2, ptCount2, facesArr2, facesCount2, (ulong)Math.Max(0, Math.Min(Difference_Union_Intersection, 4)), ref vertexCoordPointer, ref nVertices, ref faceIndicesPointer, ref nFaces);




            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Get Vertices and Faces from C++
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //Convert faceIndicesPointer to C# int[]
            double[] verticesCoordinates = new double[nVertices * 3];
            Marshal.Copy(vertexCoordPointer, verticesCoordinates, 0, verticesCoordinates.Length);

            int[] faceIndices = new int[nFaces * 3];
            Marshal.Copy(faceIndicesPointer, faceIndices, 0, faceIndices.Length);

            ////Rhino.RhinoApp.WriteLine(verticesCoordinates.Length.ToString()  + " " + nVertices.ToString());
            ////Rhino.RhinoApp.WriteLine(faceIndices.Length.ToString() + " " + nFaces.ToString());



            //Create mesh
            Mesh mesh = new Mesh();
            for (int i = 0; i < verticesCoordinates.Length; i += 3)
                mesh.Vertices.Add(new Point3d(verticesCoordinates[i + 0], verticesCoordinates[i + 1], verticesCoordinates[i + 2]));

            for (int i = 0; i < faceIndices.Length; i += 3) {
                mesh.Faces.AddFace(faceIndices[i + 0], faceIndices[i + 1], faceIndices[i + 2]);
            }

            //mesh.Vertices.Align(0.01);
            mesh.Vertices.CombineIdentical(true, true);
            mesh.Vertices.CullUnused();
            mesh.Weld(3.14159265358979);
            mesh.FillHoles();
            mesh.RebuildNormals();


            //Release memory from output
            UnsafeLIBIGL.ReleaseDouble(vertexCoordPointer, true);
            UnsafeLIBIGL.ReleaseInt(faceIndicesPointer, true);


            return mesh;
        }

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

public int GetNextCaretPosition(int visualColumn, LogicalDirection direction, CaretPositioningMode mode, bool allowVirtualSpace)
		{
			if (!HreplacedtopsInVirtualSpace(mode))
				allowVirtualSpace = false;

			if (elements.Count == 0) {
				// special handling for empty visual lines:
				if (allowVirtualSpace) {
					if (direction == LogicalDirection.Forward)
						return Math.Max(0, visualColumn + 1);
					else if (visualColumn > 0)
						return visualColumn - 1;
					else
						return -1;
				} else {
					// even though we don't have any elements,
					// there's a single caret stop at visualColumn 0
					if (visualColumn < 0 && direction == LogicalDirection.Forward)
						return 0;
					else if (visualColumn > 0 && direction == LogicalDirection.Backward)
						return 0;
					else
						return -1;
				}
			}

			int i;
			if (direction == LogicalDirection.Backward) {
				// Search Backwards:
				// If the last element doesn't handle line borders, return the line end as caret stop

				if (visualColumn > this.VisualLength && !elements[elements.Count - 1].HandlesLineBorders && HasImplicitStopAtLineEnd(mode)) {
					if (allowVirtualSpace)
						return visualColumn - 1;
					else
						return this.VisualLength;
				}
				// skip elements that start after or at visualColumn
				for (i = elements.Count - 1; i >= 0; i--) {
					if (elements[i].VisualColumn < visualColumn)
						break;
				}
				// search last element that has a caret stop
				for (; i >= 0; i--) {
					int pos = elements[i].GetNextCaretPosition(
						Math.Min(visualColumn, elements[i].VisualColumn + elements[i].VisualLength + 1),
						direction, mode);
					if (pos >= 0)
						return pos;
				}
				// If we've found nothing, and the first element doesn't handle line borders,
				// return the line start as normal caret stop.
				if (visualColumn > 0 && !elements[0].HandlesLineBorders && HasImplicitStopAtLineStart(mode))
					return 0;
			} else {
				// Search Forwards:
				// If the first element doesn't handle line borders, return the line start as caret stop
				if (visualColumn < 0 && !elements[0].HandlesLineBorders && HasImplicitStopAtLineStart(mode))
					return 0;
				// skip elements that end before or at visualColumn
				for (i = 0; i < elements.Count; i++) {
					if (elements[i].VisualColumn + elements[i].VisualLength > visualColumn)
						break;
				}
				// search first element that has a caret stop
				for (; i < elements.Count; i++) {
					int pos = elements[i].GetNextCaretPosition(
						Math.Max(visualColumn, elements[i].VisualColumn - 1),
						direction, mode);
					if (pos >= 0)
						return pos;
				}
				// if we've found nothing, and the last element doesn't handle line borders,
				// return the line end as caret stop
				if ((allowVirtualSpace || !elements[elements.Count - 1].HandlesLineBorders) && HasImplicitStopAtLineEnd(mode)) {
					if (visualColumn < this.VisualLength)
						return this.VisualLength;
					else if (allowVirtualSpace)
						return visualColumn + 1;
				}
			}
			// we've found nothing, return -1 and let the caret search continue in the next line
			return -1;
		}

19 View Source File : blas.cs
License : MIT License
Project Creator : 1CM69

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

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

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

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

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

19 View Source File : BuildWindow.cs
License : MIT License
Project Creator : 1ZouLTReX1

void DrawQuickStart()
    {
        GUILayout.BeginVertical();

        GUILayout.Label("Quick Start", EditorStyles.boldLabel);

        var entryCount = quickstartData.clientCount + 1;
        // Make sure we have enough entries
        var minEntryCount = Math.Max(entryCount, 2);
        while (minEntryCount > quickstartData.entries.Count())
            quickstartData.entries.Add(new QuickstartEntry());

        string str = "Starting Game - Server (Headless) & " + quickstartData.clientCount.ToString() + " clients";
        GUILayout.Label(str, EditorStyles.boldLabel);

        Color defaultGUIBackgrounColor = GUI.backgroundColor;
        // Quick start buttons
        GUILayout.BeginHorizontal();
        {
            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("Start"))
            {
                for (int i = 0; i < entryCount; i++)
                {
                    if (quickstartData.entries[i].runInEditor)
                        continue;
                        //EditorLevelManager.StartGameInEditor();
                    else
                    {
                        RunBuild(quickstartData.entries[i].gameLoopMode);
                    }
                }
            }
            GUI.backgroundColor = defaultGUIBackgrounColor;

            GUI.backgroundColor = Color.red;
            if (GUILayout.Button("Stop All"))
            {
                StopAll();
            }
            GUI.backgroundColor = defaultGUIBackgrounColor;
        }
        GUILayout.EndHorizontal();

        // Settings
        EditorGUI.BeginChangeCheck();

        quickstartData.clientCount = EditorGUILayout.IntField("Clients", quickstartData.clientCount);

        quickstartData.editorRole = (EditorRole)EditorGUILayout.EnumPopup("Use Editor as", quickstartData.editorRole);

        quickstartData.entries[0].gameLoopMode = GameLoopMode.Server;
        quickstartData.entries[0].headless = quickstartData.headlessServer;

        quickstartData.entries[0].runInEditor = quickstartData.editorRole == EditorRole.Server;
        quickstartData.entries[1].runInEditor = quickstartData.editorRole == EditorRole.Client;

        for (var i = 1; i < entryCount; i++)
        {
            quickstartData.entries[i].gameLoopMode = GameLoopMode.Client;
            quickstartData.entries[i].headless = false;
        }

        // Draw entries
        GUILayout.Label("Started processes:");
        for (var i = 0; i < entryCount; i++)
        {
            var entry = quickstartData.entries[i];
            GUILayout.BeginVertical();
            {
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(20);

                    GUILayout.Label("- Stand Alone Build", GUILayout.Width(130));

                    EditorGUILayout.SelectableLabel(entry.gameLoopMode.ToString(), EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
        }

        GUILayout.EndVertical();
    }

19 View Source File : Tunneler.cs
License : MIT License
Project Creator : 1upD

public override void Step(AlifeMap map)
        {
            try {
                int seed = this.X + this.Y + this.Z + (int)this.Direction + this.Height + this.Width + (int)System.DateTime.Now.Ticks;

                // Get random number
                Random random = new Random(seed);
                double sample = random.NextDouble();

                // Check turn probability. If turning, change direction 90 degrees
                if (sample < this.ProbTurn)
                {
                    sample = random.NextDouble();
                    int polarity = sample > 0.5 ? 1 : -1;
                    this.Direction = AlifeDirectionOperations.Add(this.Direction, polarity);
                }

                // Get new random seed
                sample = random.NextDouble();

                // Check reproduction probability
                if (sample < this.ProbReproduce)
                {
                    sample = random.NextDouble();
                    int polarity = sample > 0.5 ? 1 : -1;
                    AlifeDirection childDirection = AlifeDirectionOperations.Add(this.Direction, polarity);
                    int widthDecay = random.Next(this.MinWidthDecayRate, this.MaxWidthDecayRate);
                    int heightDecay = random.Next(this.MinHeightDecayRate, this.MaxHeightDecayRate);
                    Tunneler child = new Tunneler(this.Style, this.X, this.Y, this.Z, this.Width - widthDecay, this.Height - heightDecay, this.MaxLifetime - this.LifetimeDecayRate, this.MaxLifetime - this.LifetimeDecayRate, this.ProbReproduce, this.ProbTurn, this.ProbAscend, childDirection);
                    map.Agents.Add(child);
                }
                else
                {
                    sample = random.NextDouble();
                    if (sample < this.ProbSpawnRoomer)
                    {
                        Roomer child = new Roomer(x: this.X, y: this.Y, z: this.Z, style: this.Style, height: Math.Max(this.Height, 2), maxWidth: Math.Min(this.Width * 2, 3), mustDeploy: false);
                        map.Agents.Add(child);
                        }
                }

                // Get new random seed
                sample = random.NextDouble();

                // Check a s c e n d probability
                if (sample < this.ProbAscend)
                {
                    sample = random.NextDouble();
                        int verticalDistance = random.Next(1, Math.Min(this.Height, this.MaxVerticalDrop));
                    int polarity = sample > 0.5 ? verticalDistance : -verticalDistance;
                    this.Z += polarity;
                }
                else
                {
                    // Update location
                    switch (this.Direction)
                    {
                        case AlifeDirection.East:
                            this.X++;
                            break;
                        case AlifeDirection.North:
                            this.Y++;
                            break;
                        case AlifeDirection.West:
                            this.X--;
                            break;
                        case AlifeDirection.South:
                            this.Y--;
                            break;
                        case AlifeDirection.Up:
                            this.Z++;
                            break;
                        case AlifeDirection.Down:
                            this.Z--;
                            break;
                    }

                }


                // Mark location
                // Nasty nested four loop to handle the added spaces from the height and width
                bool vertical = this.Direction == AlifeDirection.North || this.Direction == AlifeDirection.South;
                for (int x = this.X; x <= (vertical ? this.X + this.Width : this.X); x++)
                {
                    for (int y = this.Y; y <= (vertical ? this.Y : this.Y + this.Width); y++)
                    {
                        for (int z = this.Z; z <= this.Z + this.Height; z++)
                        {
                            map.MarkLocation(this.Style, x, y, z);
                        }
                    }
                }

            if (this.Lifetime == 1 && this.SpawnRoomerOnDeath)
            {
                    log.Debug(string.Format("Tunneler died at {0}, {1}, {2}.", this.X, this.Y, this.Z));

                    // Add a roomer
                    Roomer child = new Roomer(x: this.X, y: this.Y, z: this.Z, style: this.Style, height: Math.Max(this.Height, 2), maxWidth: Math.Min(this.Width * 2, 3));
                    map.Agents.Add(child);
                }

            this.Lifetime--;
            }
            catch (Exception e){
                log.Error("Error in Tunneler Step function: ", e);
            }
        }

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

internal void WriteTo(RichTextWriter writer, int startOffset, int endOffset)
		{
			if (writer == null)
				throw new ArgumentNullException("writer");
			int doreplacedentLineStartOffset = this.DoreplacedentLine.Offset;
			int doreplacedentLineEndOffset = doreplacedentLineStartOffset + this.DoreplacedentLine.Length;
			if (startOffset < doreplacedentLineStartOffset || startOffset > doreplacedentLineEndOffset)
				throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be between " + doreplacedentLineStartOffset + " and " + doreplacedentLineEndOffset);
			if (endOffset < startOffset || endOffset > doreplacedentLineEndOffset)
				throw new ArgumentOutOfRangeException("endOffset", endOffset, "Value must be between startOffset and " + doreplacedentLineEndOffset);
			ISegment requestedSegment = new SimpleSegment(startOffset, endOffset - startOffset);

			List<HtmlElement> elements = new List<HtmlElement>();
			for (int i = 0; i < this.Sections.Count; i++) {
				HighlightedSection s = this.Sections[i];
				if (SimpleSegment.GetOverlap(s, requestedSegment).Length > 0) {
					elements.Add(new HtmlElement(s.Offset, i, false, s.Color));
					elements.Add(new HtmlElement(s.Offset + s.Length, i, true, s.Color));
				}
			}
			elements.Sort();

			IDoreplacedent doreplacedent = this.Doreplacedent;
			int textOffset = startOffset;
			foreach (HtmlElement e in elements) {
				int newOffset = Math.Min(e.Offset, endOffset);
				if (newOffset > startOffset) {
					doreplacedent.WriteTextTo(writer, textOffset, newOffset - textOffset);
				}
				textOffset = Math.Max(textOffset, newOffset);
				if (e.IsEnd)
					writer.EndSpan();
				else
					writer.BeginSpan(e.Color);
			}
			doreplacedent.WriteTextTo(writer, textOffset, endOffset - textOffset);
		}

19 View Source File : leastsquares.cs
License : MIT License
Project Creator : 1CM69

public static void buildgeneralleastsquares(ref double[] y, ref double[] w, ref double[,] fmatrix, int n, int m, ref double[] c)
  {
    double[,] numArray1 = new double[0, 0];
    double[,] numArray2 = new double[0, 0];
    double[,] numArray3 = new double[0, 0];
    double[] numArray4 = new double[0];
    double[] tau = new double[0];
    double[,] numArray5 = new double[0, 0];
    double[] tauq = new double[0];
    double[] taup = new double[0];
    double[] d = new double[0];
    double[] e = new double[0];
    bool isupper = false;
    int val1 = n;
    int num1 = m;
    c = new double[num1 - 1 + 1];
    double[,] numArray6 = new double[num1 + 1, System.Math.Max(val1, num1) + 1];
    double[] numArray7 = new double[System.Math.Max(val1, num1) + 1];
    for (int index = 1; index <= val1; ++index)
      numArray7[index] = w[index - 1] * y[index - 1];
    for (int index = val1 + 1; index <= num1; ++index)
      numArray7[index] = 0.0;
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      int num2 = -1;
      for (int index2 = 1; index2 <= val1; ++index2)
        numArray6[index1, index2] = fmatrix[index2 + num2, index1 - 1];
    }
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      for (int index2 = val1 + 1; index2 <= num1; ++index2)
        numArray6[index1, index2] = 0.0;
    }
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      for (int index2 = 1; index2 <= val1; ++index2)
        numArray6[index1, index2] = numArray6[index1, index2] * w[index2 - 1];
    }
    int n1 = System.Math.Max(val1, num1);
    lq.lqdecomposition(ref numArray6, num1, n1, ref tau);
    lq.unpackqfromlq(ref numArray6, num1, n1, ref tau, num1, ref numArray2);
    double[,] numArray8 = new double[2, num1 + 1];
    for (int index = 1; index <= num1; ++index)
      numArray8[1, index] = 0.0;
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      double num2 = 0.0;
      for (int index2 = 1; index2 <= n1; ++index2)
        num2 += numArray7[index2] * numArray2[index1, index2];
      numArray8[1, index1] = num2;
    }
    for (int index1 = 1; index1 <= num1 - 1; ++index1)
    {
      for (int index2 = index1 + 1; index2 <= num1; ++index2)
        numArray6[index1, index2] = numArray6[index2, index1];
    }
    for (int index1 = 2; index1 <= num1; ++index1)
    {
      for (int index2 = 1; index2 <= index1 - 1; ++index2)
        numArray6[index1, index2] = 0.0;
    }
    bidiagonal.tobidiagonal(ref numArray6, num1, num1, ref tauq, ref taup);
    bidiagonal.multiplybyqfrombidiagonal(ref numArray6, num1, num1, ref tauq, ref numArray8, 1, num1, true, false);
    bidiagonal.unpackptfrombidiagonal(ref numArray6, num1, num1, ref taup, num1, ref numArray3);
    bidiagonal.unpackdiagonalsfrombidiagonal(ref numArray6, num1, num1, ref isupper, ref d, ref e);
    if (!bdsvd.bidiagonalsvddecomposition(ref d, e, num1, isupper, false, ref numArray8, 1, ref numArray2, 0, ref numArray3, num1))
    {
      for (int index = 0; index <= num1 - 1; ++index)
        c[index] = 0.0;
    }
    else
    {
      if (d[1] != 0.0)
      {
        for (int index = 1; index <= num1; ++index)
          numArray8[1, index] = d[index] <= 5E-15 * System.Math.Sqrt((double) num1) * d[1] ? 0.0 : numArray8[1, index] / d[index];
      }
      for (int index = 1; index <= num1; ++index)
        numArray7[index] = 0.0;
      for (int index1 = 1; index1 <= num1; ++index1)
      {
        double num2 = numArray8[1, index1];
        for (int index2 = 1; index2 <= num1; ++index2)
          numArray7[index2] = numArray7[index2] + num2 * numArray3[index1, index2];
      }
      for (int index = 1; index <= num1; ++index)
        c[index - 1] = numArray7[index];
    }
  }

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

public override void ReplaceSelectionWithText(string newText)
		{
			if (newText == null)
				throw new ArgumentNullException("newText");
			using (textArea.Doreplacedent.RunUpdate()) {
				TextViewPosition start = new TextViewPosition(doreplacedent.GetLocation(topLeftOffset), GetVisualColumnFromXPos(startLine, startXPos));
				TextViewPosition end = new TextViewPosition(doreplacedent.GetLocation(bottomRightOffset), GetVisualColumnFromXPos(endLine, endXPos));
				int insertionLength;
				int totalInsertionLength = 0;
				int firstInsertionLength = 0;
				int editOffset = Math.Min(topLeftOffset, bottomRightOffset);
				TextViewPosition pos;
				if (NewLineFinder.NextNewLine(newText, 0) == SimpleSegment.Invalid) {
					// insert same text into every line
					foreach (SelectionSegment lineSegment in this.Segments.Reverse()) {
						ReplaceSingleLineText(textArea, lineSegment, newText, out insertionLength);
						totalInsertionLength += insertionLength;
						firstInsertionLength = insertionLength;
					}

					int newEndOffset = editOffset + totalInsertionLength;
					pos = new TextViewPosition(doreplacedent.GetLocation(editOffset + firstInsertionLength));

					textArea.Selection = new RectangleSelection(textArea, pos, Math.Max(startLine, endLine), GetXPos(textArea, pos));
				} else {
					string[] lines = newText.Split(NewLineFinder.NewlineStrings, segments.Count, StringSplitOptions.None);
					int line = Math.Min(startLine, endLine);
					for (int i = lines.Length - 1; i >= 0; i--) {
						ReplaceSingleLineText(textArea, segments[i], lines[i], out insertionLength);
						firstInsertionLength = insertionLength;
					}
					pos = new TextViewPosition(doreplacedent.GetLocation(editOffset + firstInsertionLength));
					textArea.ClearSelection();
				}
				textArea.Caret.Position = textArea.TextView.GetPosition(new Point(GetXPos(textArea, pos), textArea.TextView.GetVisualTopByDoreplacedentLine(Math.Max(startLine, endLine)))).GetValueOrDefault();
			}
		}

19 View Source File : reflections.cs
License : MIT License
Project Creator : 1CM69

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

19 View Source File : CloudDownsample - Copy.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

public PointCloud DownsampleUniform(PointCloud cloud, int numberOfPoints) {

            int nOfPoints = numberOfPoints;
            int b = (int)(cloud.Count * (1.0 / numberOfPoints * 1.0));
            int nth = Math.Max(1, b);

            PointCloud cloudNew = new PointCloud();

            int count = 0;
            for(int i = 0; i<cloud.Count; i += nth) {
                cloudNew.Add(cloud[i].Location);
                //cloudNew.AppendNew();
                //cloudNew[count].Location = cloud[i].Location;
                //cloudNew[count].Normal = cloud[i].Normal;
                //cloudNew[count].Color = cloud[i].Color;
                count++;
            }


            return cloudNew;
        }

19 View Source File : ListViewFlickerFree.cs
License : GNU General Public License v3.0
Project Creator : 2dust

public void AutoResizeColumns()
        {
            try
            {
                this.SuspendLayout();
                Graphics graphics = this.CreateGraphics();

                // 原生 ColumnHeaderAutoResizeStyle.ColumnContent 将忽略列头宽度
                this.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

                for (int i = 0; i < this.Columns.Count; i++)
                {
                    ColumnHeader c = this.Columns[i];
                    int cWidth = c.Width;
                    string MaxStr = "";
                    Font font = this.Items[0].SubItems[0].Font;

                    foreach (ListViewItem item in this.Items)
                    {
                        // 整行视作相同字形,不单独计算每个单元格
                        font = item.SubItems[i].Font;
                        string str = item.SubItems[i].Text;
                        if (str.Length > MaxStr.Length) // 未考虑非等宽问题
                            MaxStr = str;
                    }
                    int strWidth = (int)graphics.MeasureString(MaxStr, font).Width;
                    c.Width = System.Math.Max(cWidth, strWidth);
                }
                this.ResumeLayout();
            }
            catch { }
        }

19 View Source File : lq.cs
License : MIT License
Project Creator : 1CM69

public static void rmatrixlq(ref double[,] a, int m, int n, ref double[] tau)
  {
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    double tau1 = 0.0;
    int num1 = Math.Min(m, n);
    Math.Max(m, n);
    double[] work = new double[m + 1];
    double[] numArray3 = new double[n + 1];
    tau = new double[num1 - 1 + 1];
    int num2 = Math.Min(m, n);
    for (int n1 = 0; n1 <= num2 - 1; ++n1)
    {
      int num3 = n1 - 1;
      for (int index = 1; index <= n - n1; ++index)
        numArray3[index] = a[n1, index + num3];
      reflections.generatereflection(ref numArray3, n - n1, ref tau1);
      tau[n1] = tau1;
      int num4 = 1 - n1;
      for (int index = n1; index <= n - 1; ++index)
        a[n1, index] = numArray3[index + num4];
      numArray3[1] = 1.0;
      if (n1 < n)
        reflections.applyreflectionfromtheright(ref a, tau[n1], ref numArray3, n1 + 1, m - 1, n1, n - 1, ref work);
    }
  }

19 View Source File : CloudDownsample - Copy.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

protected override void SolveInstance(IGH_DataAccess DA) {

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

            int n = 50;
            DA.GetData(1, ref n);
            n = Math.Min(cgh.Value.Count, Math.Max(0,n));

            var c = PInvokeCSharp.TestOpen3D.Downsample(cgh.Value, n);
            //var c = PInvokeCSharp.TestOpen3D.DownsampleRhino(cgh.Value, n);
            //this.Message = c.Count.ToString();

            DA.SetData(0, new GH_Cloud(c));


        }

19 View Source File : bidiagonal.cs
License : MIT License
Project Creator : 1CM69

public static void rmatrixbdmultiplybyp(ref double[,] qp, int m, int n, ref double[] taup, ref double[,] z, int zrows, int zcolumns, bool fromtheright, bool dotranspose)
  {
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    if (m <= 0 | n <= 0 | zrows <= 0 | zcolumns <= 0)
      return;
    int num1 = Math.Max(Math.Max(Math.Max(m, n), zrows), zcolumns);
    numArray1 = new double[num1 + 1];
    numArray2 = new double[num1 + 1];
    double[] v = new double[num1 + 1];
    double[] work = new double[num1 + 1];
    if (m >= n)
    {
      int num2;
      int num3;
      int num4;
      if (fromtheright)
      {
        num2 = n - 2;
        num3 = 0;
        num4 = -1;
      }
      else
      {
        num2 = 0;
        num3 = n - 2;
        num4 = 1;
      }
      if (!dotranspose)
      {
        int num5 = num2;
        num2 = num3;
        num3 = num5;
        num4 = -num4;
      }
      if (n - 1 <= 0)
        return;
      int index1 = num2;
      do
      {
        int num5 = index1 + 1 - 1;
        for (int index2 = 1; index2 <= n - 1 - index1; ++index2)
          v[index2] = qp[index1, index2 + num5];
        v[1] = 1.0;
        if (fromtheright)
          reflections.applyreflectionfromtheright(ref z, taup[index1], ref v, 0, zrows - 1, index1 + 1, n - 1, ref work);
        else
          reflections.applyreflectionfromtheleft(ref z, taup[index1], ref v, index1 + 1, n - 1, 0, zcolumns - 1, ref work);
        index1 += num4;
      }
      while (index1 != num3 + num4);
    }
    else
    {
      int num2;
      int num3;
      int num4;
      if (fromtheright)
      {
        num2 = m - 1;
        num3 = 0;
        num4 = -1;
      }
      else
      {
        num2 = 0;
        num3 = m - 1;
        num4 = 1;
      }
      if (!dotranspose)
      {
        int num5 = num2;
        num2 = num3;
        num3 = num5;
        num4 = -num4;
      }
      int index1 = num2;
      do
      {
        int num5 = index1 - 1;
        for (int index2 = 1; index2 <= n - index1; ++index2)
          v[index2] = qp[index1, index2 + num5];
        v[1] = 1.0;
        if (fromtheright)
          reflections.applyreflectionfromtheright(ref z, taup[index1], ref v, 0, zrows - 1, index1, n - 1, ref work);
        else
          reflections.applyreflectionfromtheleft(ref z, taup[index1], ref v, index1, n - 1, 0, zcolumns - 1, ref work);
        index1 += num4;
      }
      while (index1 != num3 + num4);
    }
  }

19 View Source File : DateAndSizeRollingFileAppender.cs
License : MIT License
Project Creator : Abc-Arbitrage

private int FindLastRollingFileNumber(string directory)
        {
            var fileNumber = 0;
            var root = FilenameRoot + ".";
            var extension = FilenameExtension.Length == 0 ? "" : "." + FilenameExtension;
            foreach (var filename in Directory.EnumerateFiles(directory).Select(f => f.ToUpper()))
            {
                if (filename.StartsWith(root, StringComparison.OrdinalIgnoreCase) && filename.EndsWith(extension, StringComparison.OrdinalIgnoreCase))
                {
                    var rootLength = root.Length;
                    var extensionLength = extension.Length;
                    if (filename.Length - rootLength - extensionLength > 0 && int.TryParse(filename.Substring(rootLength, filename.Length - rootLength - extensionLength), out var tempNumber))
                        fileNumber = Math.Max(fileNumber, tempNumber);
                }
            }

            return fileNumber;
        }

19 View Source File : bidiagonal.cs
License : MIT License
Project Creator : 1CM69

public static void multiplybyqfrombidiagonal(ref double[,] qp, int m, int n, ref double[] tauq, ref double[,] z, int zrows, int zcolumns, bool fromtheright, bool dotranspose)
  {
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    if (m <= 0 | n <= 0 | zrows <= 0 | zcolumns <= 0)
      return;
    int num1 = Math.Max(Math.Max(Math.Max(m, n), zrows), zcolumns);
    double[] v = new double[num1 + 1];
    double[] work = new double[num1 + 1];
    if (m >= n)
    {
      int num2;
      int num3;
      int num4;
      if (fromtheright)
      {
        num2 = 1;
        num3 = n;
        num4 = 1;
      }
      else
      {
        num2 = n;
        num3 = 1;
        num4 = -1;
      }
      if (dotranspose)
      {
        int num5 = num2;
        num2 = num3;
        num3 = num5;
        num4 = -num4;
      }
      int index1 = num2;
      do
      {
        int num5 = m - index1 + 1;
        int num6 = index1 - 1;
        for (int index2 = 1; index2 <= num5; ++index2)
          v[index2] = qp[index2 + num6, index1];
        v[1] = 1.0;
        if (fromtheright)
          reflections.applyreflectionfromtheright(ref z, tauq[index1], ref v, 1, zrows, index1, m, ref work);
        else
          reflections.applyreflectionfromtheleft(ref z, tauq[index1], ref v, index1, m, 1, zcolumns, ref work);
        index1 += num4;
      }
      while (index1 != num3 + num4);
    }
    else
    {
      int num2;
      int num3;
      int num4;
      if (fromtheright)
      {
        num2 = 1;
        num3 = m - 1;
        num4 = 1;
      }
      else
      {
        num2 = m - 1;
        num3 = 1;
        num4 = -1;
      }
      if (dotranspose)
      {
        int num5 = num2;
        num2 = num3;
        num3 = num5;
        num4 = -num4;
      }
      if (m - 1 <= 0)
        return;
      int index1 = num2;
      do
      {
        int num5 = m - index1;
        int num6 = index1 + 1 - 1;
        for (int index2 = 1; index2 <= num5; ++index2)
          v[index2] = qp[index2 + num6, index1];
        v[1] = 1.0;
        if (fromtheright)
          reflections.applyreflectionfromtheright(ref z, tauq[index1], ref v, 1, zrows, index1 + 1, m, ref work);
        else
          reflections.applyreflectionfromtheleft(ref z, tauq[index1], ref v, index1 + 1, m, 1, zcolumns, ref work);
        index1 += num4;
      }
      while (index1 != num3 + num4);
    }
  }

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

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

19 View Source File : Program.cs
License : MIT License
Project Creator : 13xforever

internal static async Task Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("Drag .pkg files and/or folders onto this .exe to verify the packages.");
                    var isFirstChar = true;
                    var completedPath = false;
                    var path = new StringBuilder();
                    do
                    {
                        var keyInfo = Console.ReadKey(true);
                        if (isFirstChar)
                        {
                            isFirstChar = false;
                            if (keyInfo.KeyChar != '"')
                                return;
                        }
                        else
                        {
                            if (keyInfo.KeyChar == '"')
                            {
                                completedPath = true;
                                args = new[] {path.ToString()};
                            }
                            else
                                path.Append(keyInfo.KeyChar);
                        }
                    } while (!completedPath);
                    Console.Clear();
                }

                Console.OutputEncoding = new UTF8Encoding(false);
                Console.replacedle = replacedle;
                Console.CursorVisible = false;
                Console.WriteLine("Scanning for PKGs...");
                var pkgList = new List<FileInfo>();
                Console.ForegroundColor = ConsoleColor.Yellow;
                foreach (var item in args)
                {
                    var path = item.Trim('"');
                    if (File.Exists(path))
                        pkgList.Add(new FileInfo(path));
                    else if (Directory.Exists(path))
                        pkgList.AddRange(GetFilePaths(path, "*.pkg", SearchOption.AllDirectories).Select(p => new FileInfo(p)));
                    else
                        Console.WriteLine("Unknown path: " + path);
                }
                Console.ResetColor();
                if (pkgList.Count == 0)
                {
                    Console.WriteLine("No packages were found. Check paths, and try again.");
                    return;
                }

                var longestFilename = Math.Max(pkgList.Max(i => i.Name.Length), HeaderPkgName.Length);
                var sigWidth = Math.Max(HeaderSignature.Length, 8);
                var csumWidth = Math.Max(HeaderChecksum.Length, 5);
                var csumsWidth = 1 + sigWidth + 1 + csumWidth + 1;
                var idealWidth = longestFilename + csumsWidth;
                try
                {
                    if (idealWidth > Console.LargestWindowWidth)
                    {
                        longestFilename = Console.LargestWindowWidth - csumsWidth;
                        idealWidth = Console.LargestWindowWidth;
                    }
                    if (idealWidth > Console.WindowWidth)
                    {
                        Console.BufferWidth = Math.Max(Console.BufferWidth, idealWidth);
                        Console.WindowWidth = idealWidth;
                    }
                    Console.BufferHeight = Math.Max(Console.BufferHeight, Math.Min(9999, pkgList.Count + 10));
                }
                catch (PlatformNotSupportedException) { }
                Console.WriteLine($"{HeaderPkgName.Trim(longestFilename).PadRight(longestFilename)} {HeaderSignature.PadLeft(sigWidth)} {HeaderChecksum.PadLeft(csumWidth)}");
                using var cts = new CancellationTokenSource();
                Console.CancelKeyPress += (sender, eventArgs) => { cts.Cancel(); };
                var t = new Thread(() =>
                                   {
                                       try
                                       {
                                           var indicatorIdx = 0;
                                           while (!cts.Token.IsCancellationRequested)
                                           {
                                               Task.Delay(1000, cts.Token).ConfigureAwait(false).GetAwaiter().GetResult();
                                               if (cts.Token.IsCancellationRequested)
                                                   return;

                                               PkgChecker.Sync.Wait(cts.Token);
                                               try
                                               {
                                                   var frame = Animation[(indicatorIdx++) % Animation.Length];
                                                   var currentProgress = PkgChecker.CurrentFileProcessedBytes;
                                                   Console.replacedle = $"{replacedle} [{(double)(PkgChecker.ProcessedBytes + currentProgress) / PkgChecker.TotalFileSize * 100:0.00}%] {frame}";
                                                   if (PkgChecker.CurrentPadding > 0)
                                                   {
                                                       Console.CursorVisible = false;
                                                       var (top, left) = (Console.CursorTop, Console.CursorLeft);
                                                       Console.Write($"{(double)currentProgress / PkgChecker.CurrentFileSize * 100:0}%".PadLeft(PkgChecker.CurrentPadding));
                                                       Console.CursorTop = top;
                                                       Console.CursorLeft = left;
                                                       Console.CursorVisible = false;
                                                   }
                                               }
                                               finally
                                               {
                                                   PkgChecker.Sync.Release();
                                               }
                                           }
                                       }
                                       catch (TaskCanceledException)
                                       {
                                       }
                                   });
                t.Start();
                await PkgChecker.CheckAsync(pkgList, longestFilename, sigWidth, csumWidth, csumsWidth-2, cts.Token).ConfigureAwait(false);
                cts.Cancel(false);
                t.Join();
            }
            finally
            {
                Console.replacedle = replacedle;
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
                Console.WriteLine();
                Console.CursorVisible = true;
            }
        }

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

void CalculateSegments()
		{
			DoreplacedentLine nextLine = doreplacedent.GetLineByNumber(Math.Min(startLine, endLine));
			do {
				VisualLine vl = textArea.TextView.GetOrConstructVisualLine(nextLine);
				int startVC = vl.GetVisualColumn(new Point(startXPos, 0), true);
				int endVC = vl.GetVisualColumn(new Point(endXPos, 0), true);

				int baseOffset = vl.FirstDoreplacedentLine.Offset;
				int startOffset = baseOffset + vl.GetRelativeOffset(startVC);
				int endOffset = baseOffset + vl.GetRelativeOffset(endVC);
				segments.Add(new SelectionSegment(startOffset, startVC, endOffset, endVC));

				nextLine = vl.LastDoreplacedentLine.NextLine;
			} while (nextLine != null && nextLine.LineNumber <= Math.Max(startLine, endLine));
		}

19 View Source File : rotations.cs
License : MIT License
Project Creator : 1CM69

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

19 View Source File : svd.cs
License : MIT License
Project Creator : 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 View Source File : Utils.cs
License : MIT License
Project Creator : 13xforever

public static int Clamp(this int amount, int low, int high)
        {
            return Math.Min(high, Math.Max(amount, low));
        }

19 View Source File : bidiagonal.cs
License : MIT License
Project Creator : 1CM69

public static void rmatrixbd(ref double[,] a, int m, int n, ref double[] tauq, ref double[] taup)
  {
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    double tau = 0.0;
    if (n <= 0 | m <= 0)
      return;
    Math.Min(m, n);
    int num1 = Math.Max(m, n);
    double[] work = new double[num1 + 1];
    double[] numArray3 = new double[num1 + 1];
    if (m >= n)
    {
      tauq = new double[n - 1 + 1];
      taup = new double[n - 1 + 1];
    }
    else
    {
      tauq = new double[m - 1 + 1];
      taup = new double[m - 1 + 1];
    }
    if (m >= n)
    {
      for (int m1 = 0; m1 <= n - 1; ++m1)
      {
        int num2 = m1 - 1;
        for (int index = 1; index <= m - m1; ++index)
          numArray3[index] = a[index + num2, m1];
        reflections.generatereflection(ref numArray3, m - m1, ref tau);
        tauq[m1] = tau;
        int num3 = 1 - m1;
        for (int index = m1; index <= m - 1; ++index)
          a[index, m1] = numArray3[index + num3];
        numArray3[1] = 1.0;
        reflections.applyreflectionfromtheleft(ref a, tau, ref numArray3, m1, m - 1, m1 + 1, n - 1, ref work);
        if (m1 < n - 1)
        {
          int num4 = m1 + 1 - 1;
          for (int index = 1; index <= n - m1 - 1; ++index)
            numArray3[index] = a[m1, index + num4];
          reflections.generatereflection(ref numArray3, n - 1 - m1, ref tau);
          taup[m1] = tau;
          int num5 = 1 - (m1 + 1);
          for (int index = m1 + 1; index <= n - 1; ++index)
            a[m1, index] = numArray3[index + num5];
          numArray3[1] = 1.0;
          reflections.applyreflectionfromtheright(ref a, tau, ref numArray3, m1 + 1, m - 1, m1 + 1, n - 1, ref work);
        }
        else
          taup[m1] = 0.0;
      }
    }
    else
    {
      for (int n1 = 0; n1 <= m - 1; ++n1)
      {
        int num2 = n1 - 1;
        for (int index = 1; index <= n - n1; ++index)
          numArray3[index] = a[n1, index + num2];
        reflections.generatereflection(ref numArray3, n - n1, ref tau);
        taup[n1] = tau;
        int num3 = 1 - n1;
        for (int index = n1; index <= n - 1; ++index)
          a[n1, index] = numArray3[index + num3];
        numArray3[1] = 1.0;
        reflections.applyreflectionfromtheright(ref a, tau, ref numArray3, n1 + 1, m - 1, n1, n - 1, ref work);
        if (n1 < m - 1)
        {
          int num4 = n1 + 1 - 1;
          for (int index = 1; index <= m - 1 - n1; ++index)
            numArray3[index] = a[index + num4, n1];
          reflections.generatereflection(ref numArray3, m - 1 - n1, ref tau);
          tauq[n1] = tau;
          int num5 = 1 - (n1 + 1);
          for (int index = n1 + 1; index <= m - 1; ++index)
            a[index, n1] = numArray3[index + num5];
          numArray3[1] = 1.0;
          reflections.applyreflectionfromtheleft(ref a, tau, ref numArray3, n1 + 1, m - 1, n1 + 1, n - 1, ref work);
        }
        else
          tauq[n1] = 0.0;
      }
    }
  }

19 View Source File : svd.cs
License : MIT License
Project Creator : 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 View Source File : TestLIBIGL.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

public static Mesh CreateLIBIGLMeshBoolean(Mesh[] m_, int Difference_Union_Intersection = 0) {

            //var watch = new System.Diagnostics.Stopwatch();
            //watch.Start();
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Clean Mesh
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            var meshes = new List<Mesh>(m_.Length);

            for (int i = 0; i < m_.Length; i++) {

                if (!m_[i].IsClosed)
                    continue;

                m_[i].Vertices.UseDoublePrecisionVertices = true;
                Mesh m = m_[i].DuplicateMesh();
                m.Vertices.UseDoublePrecisionVertices = true;
                m.Faces.ConvertQuadsToTriangles();
                m.Vertices.CombineIdentical(true, true);
                m.Vertices.CullUnused();
                m.Weld(3.14159265358979);
                m.FillHoles();
                m.RebuildNormals();
                m.Vertices.UseDoublePrecisionVertices = true;

                if (m.IsValid && m.IsClosed)
                    meshes.Add(m);
            }

            if (meshes.Count < 2)
                return null;

            //watch.Stop();
            //Rhino.RhinoApp.WriteLine($"Execution Time Clean Mesh: {watch.ElapsedMilliseconds} ms");
            //watch.Reset();
            //watch.Start();
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Send Vertices and Faces to C++
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////




            int numberOfVertices = 0;
            int numberOfFaces = 0;
            foreach (Mesh tempMesh in meshes) {
                numberOfVertices += tempMesh.Vertices.Count;
                numberOfFaces += tempMesh.Faces.Count;
            }

            double[] coord = new double[numberOfVertices * 3];
            int[] vertexArrayCount = new int[meshes.Count + 1]; vertexArrayCount[0] = 0;

            int[] faceID = new int[numberOfFaces * 3];
            int[] faceArrayCount = new int[meshes.Count + 1]; faceArrayCount[0] = 0;

            int nMesh = meshes.Count;



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

                vertexArrayCount[i + 1] = vertexArrayCount[i] + meshes[i].Vertices.Count;
                faceArrayCount[i + 1] = faceArrayCount[i] + meshes[i].Faces.Count;

                for (int j = 0; j < meshes[i].Vertices.Count; j++) {
                    int n = vertexArrayCount[i] * 3;
                    coord[n + (j * 3 + 0)] = meshes[i].Vertices.Point3dAt(j).X;
                    coord[n + (j * 3 + 1)] = meshes[i].Vertices.Point3dAt(j).Y;
                    coord[n + (j * 3 + 2)] = meshes[i].Vertices.Point3dAt(j).Z;
                    ////Rhino.RhinoApp.WriteLine((n + (j * 3 + 0).ToString() + " " + meshes[i].Vertices[j].X.ToString()));
                    ////Rhino.RhinoApp.WriteLine((n + (j * 3 + 1).ToString() + " " + meshes[i].Vertices[j].Y.ToString()));
                    ////Rhino.RhinoApp.WriteLine((n + (j * 3 + 2).ToString() + " " + meshes[i].Vertices[j].Z.ToString()));
                }

                for (int j = 0; j < meshes[i].Faces.Count; j++) {
                    int n = faceArrayCount[i] * 3;
                    faceID[n + (j * 3 + 0)] = meshes[i].Faces[j].A;
                    faceID[n + (j * 3 + 1)] = meshes[i].Faces[j].B;
                    faceID[n + (j * 3 + 2)] = meshes[i].Faces[j].C;
                }

            }


            //watch.Stop();
            //Rhino.RhinoApp.WriteLine($"Execution Copy coordinates: {watch.ElapsedMilliseconds} ms");
            //watch.Reset();
            //watch.Start();


            //Rhino.RhinoApp.WriteLine(coord.Length.ToString());
            //foreach(var c in vertexArrayCount)
            //Rhino.RhinoApp.Write(c.ToString()+" ");
            //Rhino.RhinoApp.WriteLine();
            //Rhino.RhinoApp.WriteLine(faceID.Length.ToString());
            // foreach (var c in faceArrayCount)
            //Rhino.RhinoApp.Write(c.ToString() + " ");
            //Rhino.RhinoApp.WriteLine();
            //Rhino.RhinoApp.WriteLine(nMesh.ToString());




            ////Inputs
            IntPtr vertexCoordPointer = IntPtr.Zero;
            int nVertices = 0;
            IntPtr faceIndicesPointer = IntPtr.Zero;
            int nFaces = 0;
            IntPtr facesColorsPointer = IntPtr.Zero;
            int nFaceColors = 0;
            int numberOfValidMeshes = -1;

            //Call C++ method
            UnsafeLIBIGL.LIBIGL_MeshBoolean_CreateArray(
                coord, vertexArrayCount,
                faceID, faceArrayCount,
                (ulong)nMesh,

                (ulong)Math.Max(0, Math.Min(Difference_Union_Intersection, 2)),

                ref vertexCoordPointer, ref nVertices,
                ref faceIndicesPointer, ref nFaces,
                ref facesColorsPointer, ref nFaceColors,
                ref numberOfValidMeshes);//

            //watch.Stop();
            //Rhino.RhinoApp.WriteLine($"Execution LIBIGL_MeshBoolean_CreateArray: {watch.ElapsedMilliseconds} ms");
            //watch.Reset();
            //watch.Start();
            //Rhino.RhinoApp.WriteLine(numberOfValidMeshes.ToString());
            // return null;


            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Get Vertices and Faces from C++
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //Convert faceIndicesPointer to C# int[]
            double[] verticesCoordinates = new double[nVertices * 3];
            Marshal.Copy(vertexCoordPointer, verticesCoordinates, 0, verticesCoordinates.Length);

            int[] faceIndices = new int[nFaces * 3];
            Marshal.Copy(faceIndicesPointer, faceIndices, 0, faceIndices.Length);

            int[] faceColorsIndices = new int[nFaceColors];
            Marshal.Copy(facesColorsPointer, faceColorsIndices, 0, faceColorsIndices.Length);

            //Rhino.RhinoApp.WriteLine(verticesCoordinates.Length.ToString()  + " " + nVertices.ToString());
            //Rhino.RhinoApp.WriteLine(faceIndices.Length.ToString() + " " + nFaces.ToString());



            //Create mesh
            Mesh r_ = new Mesh();
            for (int i = 0; i < verticesCoordinates.Length; i += 3)
                r_.Vertices.Add(new Point3d(verticesCoordinates[i + 0], verticesCoordinates[i + 1], verticesCoordinates[i + 2]));

            for (int i = 0; i < faceIndices.Length; i += 3) {
                r_.Faces.AddFace(faceIndices[i + 0], faceIndices[i + 1], faceIndices[i + 2]);
            }


            //mesh.Vertices.Align(0.01);
            //mesh.Vertices.CombineIdentical(true, true);
            //mesh.Vertices.CullUnused();
            //mesh.Weld(3.14159265358979);
            //mesh.FillHoles();
            r_.RebuildNormals();


            //watch.Stop();
            //Rhino.RhinoApp.WriteLine($"Execution Construct mesh: {watch.ElapsedMilliseconds} ms");
            //watch.Reset();
            //watch.Start();

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Colorize Cuts
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //Mesh r_ = r.DuplicateMesh();
            r_.Unweld(0, true);
            r_.VertexColors.CreateMonotoneMesh(System.Drawing.Color.Black);


            Interval[] domains = new Interval[meshes.Count];

            int count = 0;
            for (int i = 0; i < meshes.Count; i++) {

                domains[i] = new Interval(count, count + meshes[i].Faces.Count);
                count += meshes[i].Faces.Count;
                //if (i == 0)
                //  count += meshes[1].Faces.Count;
                //groups[i] = new List<Mesh>();
            }



            var colorWhite = System.Drawing.Color.FromArgb(200, 200, 200);

            double colorScale = 255.0 / meshes.Count;

            int[] colors = new int[faceColorsIndices.Length];
            for (int i = 0; i < faceColorsIndices.Length; i++) {



                for (int j = 0; j < domains.Length; j++) {
                    if (domains[j].IncludesParameter(faceColorsIndices[i])) {

                        int c = (int)(colorScale * j);

                        if (c == 0) {

                            r_.VertexColors.SetColor(r_.Faces[i].A, colorWhite);
                            r_.VertexColors.SetColor(r_.Faces[i].B, colorWhite);
                            r_.VertexColors.SetColor(r_.Faces[i].C, colorWhite);
                        } else {
                            var colorRed = System.Drawing.Color.FromArgb(255, c, 0);
                            r_.VertexColors.SetColor(r_.Faces[i].A, colorRed);
                            r_.VertexColors.SetColor(r_.Faces[i].B, colorRed);
                            r_.VertexColors.SetColor(r_.Faces[i].C, colorRed);
                        }


                        colors[i] = j;
                    }
                }


            }


            //watch.Stop();
            //Rhino.RhinoApp.WriteLine($"Execution Create Colors: {watch.ElapsedMilliseconds} ms");
            //watch.Reset();
            //watch.Start();


            //Release memory from output
            UnsafeLIBIGL.ReleaseDouble(vertexCoordPointer, true);
            UnsafeLIBIGL.ReleaseInt(faceIndicesPointer, true);
            UnsafeLIBIGL.ReleaseInt(facesColorsPointer, true);

            //watch.Stop();
            //Rhino.RhinoApp.WriteLine($"Execution Release Memory: {watch.ElapsedMilliseconds} ms");
            //watch.Reset();


            return r_;
        }

19 View Source File : ExtendedFingerDetector.cs
License : MIT License
Project Creator : 39M

void OnValidate() {
      int required = 0, forbidden = 0;
      PointingState[] stateArray = { Thumb, Index, Middle, Ring, Pinky };
      for(int i=0; i<stateArray.Length; i++) {
        var state = stateArray[i];
        switch (state) {
          case PointingState.Extended:
            required++;
            break;
          case PointingState.NotExtended:
            forbidden++;
            break;
          default:
            break;
        }
        MinimumExtendedCount = Math.Max(required, MinimumExtendedCount);
        MaximumExtendedCount = Math.Min(5 - forbidden, MaximumExtendedCount);
        MaximumExtendedCount = Math.Max(required, MaximumExtendedCount);
      }
    
    }

19 View Source File : leastsquares.cs
License : MIT License
Project Creator : 1CM69

public static void buildchebyshevleastsquares(ref double[] x, ref double[] y, ref double[] w, double a, double b, int n, int m, ref double[] ctbl)
  {
    double[,] numArray1 = new double[0, 0];
    double[,] numArray2 = new double[0, 0];
    double[,] numArray3 = new double[0, 0];
    double[] numArray4 = new double[0];
    double[] tau = new double[0];
    double[,] numArray5 = new double[0, 0];
    double[] tauq = new double[0];
    double[] taup = new double[0];
    double[] d = new double[0];
    double[] e = new double[0];
    bool isupper = false;
    int val1 = n;
    int index1 = m + 1;
    double[,] numArray6 = new double[index1 + 1, System.Math.Max(val1, index1) + 1];
    double[] numArray7 = new double[System.Math.Max(val1, index1) + 1];
    for (int index2 = 1; index2 <= index1; ++index2)
    {
      for (int index3 = 1; index3 <= val1; ++index3)
      {
        double num = 2.0 * (x[index3 - 1] - a) / (b - a) - 1.0;
        if (index2 == 1)
          numArray6[index2, index3] = 1.0;
        if (index2 == 2)
          numArray6[index2, index3] = num;
        if (index2 > 2)
          numArray6[index2, index3] = 2.0 * num * numArray6[index2 - 1, index3] - numArray6[index2 - 2, index3];
      }
    }
    for (int index2 = 1; index2 <= index1; ++index2)
    {
      for (int index3 = 1; index3 <= val1; ++index3)
        numArray6[index2, index3] = w[index3 - 1] * numArray6[index2, index3];
    }
    for (int index2 = 1; index2 <= index1; ++index2)
    {
      for (int index3 = val1 + 1; index3 <= index1; ++index3)
        numArray6[index2, index3] = 0.0;
    }
    for (int index2 = 0; index2 <= val1 - 1; ++index2)
      numArray7[index2 + 1] = w[index2] * y[index2];
    for (int index2 = val1 + 1; index2 <= index1; ++index2)
      numArray7[index2] = 0.0;
    int n1 = System.Math.Max(val1, index1);
    lq.lqdecomposition(ref numArray6, index1, n1, ref tau);
    lq.unpackqfromlq(ref numArray6, index1, n1, ref tau, index1, ref numArray2);
    double[,] numArray8 = new double[2, index1 + 1];
    for (int index2 = 1; index2 <= index1; ++index2)
      numArray8[1, index2] = 0.0;
    for (int index2 = 1; index2 <= index1; ++index2)
    {
      double num = 0.0;
      for (int index3 = 1; index3 <= n1; ++index3)
        num += numArray7[index3] * numArray2[index2, index3];
      numArray8[1, index2] = num;
    }
    for (int index2 = 1; index2 <= index1 - 1; ++index2)
    {
      for (int index3 = index2 + 1; index3 <= index1; ++index3)
        numArray6[index2, index3] = numArray6[index3, index2];
    }
    for (int index2 = 2; index2 <= index1; ++index2)
    {
      for (int index3 = 1; index3 <= index2 - 1; ++index3)
        numArray6[index2, index3] = 0.0;
    }
    bidiagonal.tobidiagonal(ref numArray6, index1, index1, ref tauq, ref taup);
    bidiagonal.multiplybyqfrombidiagonal(ref numArray6, index1, index1, ref tauq, ref numArray8, 1, index1, true, false);
    bidiagonal.unpackptfrombidiagonal(ref numArray6, index1, index1, ref taup, index1, ref numArray3);
    bidiagonal.unpackdiagonalsfrombidiagonal(ref numArray6, index1, index1, ref isupper, ref d, ref e);
    if (!bdsvd.bidiagonalsvddecomposition(ref d, e, index1, isupper, false, ref numArray8, 1, ref numArray2, 0, ref numArray3, index1))
    {
      for (int index2 = 1; index2 <= index1; ++index2)
      {
        d[index2] = 0.0;
        numArray8[1, index2] = 0.0;
        for (int index3 = 1; index3 <= index1; ++index3)
          numArray3[index2, index3] = index2 != index3 ? 0.0 : 1.0;
      }
      numArray8[1, 1] = 1.0;
    }
    for (int index2 = 1; index2 <= index1; ++index2)
      numArray8[1, index2] = d[index2] <= 5E-15 * System.Math.Sqrt((double) index1) * d[1] ? 0.0 : numArray8[1, index2] / d[index2];
    for (int index2 = 1; index2 <= index1; ++index2)
      numArray7[index2] = 0.0;
    for (int index2 = 1; index2 <= index1; ++index2)
    {
      double num = numArray8[1, index2];
      for (int index3 = 1; index3 <= index1; ++index3)
        numArray7[index3] = numArray7[index3] + num * numArray3[index2, index3];
    }
    ctbl = new double[index1 + 1 + 1];
    for (int index2 = 1; index2 <= index1; ++index2)
      ctbl[index2 - 1] = numArray7[index2];
    ctbl[index1] = a;
    ctbl[index1 + 1] = b;
  }

19 View Source File : CloudDownsample.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

public PointCloud DownsampleUniform(PointCloud cloud, int numberOfPoints) {

            int nOfPoints = numberOfPoints;
            int b = (int)(cloud.Count * (1.0 / numberOfPoints * 1.0));
            int nth = Math.Max(1, b);

            PointCloud cloudNew = new PointCloud();



            int count = 0;
            for (int i = 0; i < cloud.Count; i += nth) {
                count++;
            }

            Point3d[] points = new Point3d[count];
            Vector3d[] normals = new Vector3d[count];
            Color[] colors = new Color[count];


            System.Threading.Tasks.Parallel.For(0, cloud.Count /  nth, k => {

                int ii = nth * k;
                var p = cloud[(int)ii];
                points[k] = p.Location;
                normals[k] = p.Normal;
                colors[k] = p.Color;

            });

            cloudNew.AddRange(points, normals, colors);


            return cloudNew;
        }

19 View Source File : bidiagonal.cs
License : MIT License
Project Creator : 1CM69

public static void rmatrixbdmultiplybyq(ref double[,] qp, int m, int n, ref double[] tauq, ref double[,] z, int zrows, int zcolumns, bool fromtheright, bool dotranspose)
  {
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    if (m <= 0 | n <= 0 | zrows <= 0 | zcolumns <= 0)
      return;
    int num1 = Math.Max(Math.Max(Math.Max(m, n), zrows), zcolumns);
    double[] v = new double[num1 + 1];
    double[] work = new double[num1 + 1];
    if (m >= n)
    {
      int num2;
      int num3;
      int num4;
      if (fromtheright)
      {
        num2 = 0;
        num3 = n - 1;
        num4 = 1;
      }
      else
      {
        num2 = n - 1;
        num3 = 0;
        num4 = -1;
      }
      if (dotranspose)
      {
        int num5 = num2;
        num2 = num3;
        num3 = num5;
        num4 = -num4;
      }
      int index1 = num2;
      do
      {
        int num5 = index1 - 1;
        for (int index2 = 1; index2 <= m - index1; ++index2)
          v[index2] = qp[index2 + num5, index1];
        v[1] = 1.0;
        if (fromtheright)
          reflections.applyreflectionfromtheright(ref z, tauq[index1], ref v, 0, zrows - 1, index1, m - 1, ref work);
        else
          reflections.applyreflectionfromtheleft(ref z, tauq[index1], ref v, index1, m - 1, 0, zcolumns - 1, ref work);
        index1 += num4;
      }
      while (index1 != num3 + num4);
    }
    else
    {
      int num2;
      int num3;
      int num4;
      if (fromtheright)
      {
        num2 = 0;
        num3 = m - 2;
        num4 = 1;
      }
      else
      {
        num2 = m - 2;
        num3 = 0;
        num4 = -1;
      }
      if (dotranspose)
      {
        int num5 = num2;
        num2 = num3;
        num3 = num5;
        num4 = -num4;
      }
      if (m - 1 <= 0)
        return;
      int index1 = num2;
      do
      {
        int num5 = index1 + 1 - 1;
        for (int index2 = 1; index2 <= m - index1 - 1; ++index2)
          v[index2] = qp[index2 + num5, index1];
        v[1] = 1.0;
        if (fromtheright)
          reflections.applyreflectionfromtheright(ref z, tauq[index1], ref v, 0, zrows - 1, index1 + 1, m - 1, ref work);
        else
          reflections.applyreflectionfromtheleft(ref z, tauq[index1], ref v, index1 + 1, m - 1, 0, zcolumns - 1, ref work);
        index1 += num4;
      }
      while (index1 != num3 + num4);
    }
  }

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

private ItemLayoutInfo GetLayoutInfo(Size availableSize, double itemHeight, ExtentInfo extentInfo)
        {
            if (_itemsControl == null)
            {
                return new ItemLayoutInfo();
            }

            // we need to ensure that there is one realized item prior to the first visible item, and one after the last visible item,
            // so that keyboard navigation works properly. For example, when focus is on the first visible item, and the user
            // navigates up, the ListBox selects the previous item, and the scrolls that into view - and this triggers the loading of the rest of the items 
            // in that row

            var firstVisibleLine = (int)Math.Floor(VerticalOffset / itemHeight);

            var firstRealizedIndex = Math.Max(extentInfo.ItemsPerLine * firstVisibleLine - 1, 0);
            var firstRealizedItemLeft = firstRealizedIndex % extentInfo.ItemsPerLine * ItemWidth - HorizontalOffset;
            // ReSharper disable once PossibleLossOfFraction
            var firstRealizedItemTop = firstRealizedIndex / extentInfo.ItemsPerLine * itemHeight - VerticalOffset;

            var firstCompleteLineTop = (firstVisibleLine == 0 ? firstRealizedItemTop : firstRealizedItemTop + ItemHeight);
            var completeRealizedLines = (int)Math.Ceiling((availableSize.Height - firstCompleteLineTop) / itemHeight);

            var lastRealizedIndex = Math.Min(firstRealizedIndex + completeRealizedLines * extentInfo.ItemsPerLine + 2, _itemsControl.Items.Count - 1);

            return new ItemLayoutInfo
            {
                FirstRealizedItemIndex = firstRealizedIndex,
                FirstRealizedItemLeft = firstRealizedItemLeft,
                FirstRealizedLineTop = firstRealizedItemTop,
                LastRealizedItemIndex = lastRealizedIndex,
            };
        }

19 View Source File : lq.cs
License : MIT License
Project Creator : 1CM69

public static void lqdecomposition(ref double[,] a, int m, int n, ref double[] tau)
  {
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    double tau1 = 0.0;
    int num1 = Math.Min(m, n);
    Math.Max(m, n);
    double[] work = new double[m + 1];
    double[] numArray3 = new double[n + 1];
    tau = new double[num1 + 1];
    int num2 = Math.Min(m, n);
    for (int n1 = 1; n1 <= num2; ++n1)
    {
      int n2 = n - n1 + 1;
      int num3 = n1 - 1;
      for (int index = 1; index <= n2; ++index)
        numArray3[index] = a[n1, index + num3];
      reflections.generatereflection(ref numArray3, n2, ref tau1);
      tau[n1] = tau1;
      int num4 = 1 - n1;
      for (int index = n1; index <= n; ++index)
        a[n1, index] = numArray3[index + num4];
      numArray3[1] = 1.0;
      if (n1 < n)
        reflections.applyreflectionfromtheright(ref a, tau[n1], ref numArray3, n1 + 1, m, n1, n, ref work);
    }
  }

19 View Source File : CloudDownsample.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

protected override void SolveInstance(IGH_DataAccess DA) {

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

            int n = 50;
            DA.GetData(1, ref n);
            n = Math.Min(cgh.Value.Count, Math.Max(0,n));


            DA.SetData(0, new GH_Cloud(DownsampleUniform(cgh.Value,n)));


        }

19 View Source File : FScrollBar.cs
License : MIT License
Project Creator : 0xLaileb

private void MouseScroll(MouseEventArgs e)
        {
            int value = Value;

            switch (OrientationValue)
            {
                case Orientation.Vertical:
                    if (e.Y < 0) value -= SmallStep;
                    else if (e.Y > rectangle_region.Height) value += SmallStep;
                    else value = Maximum * (e.Y - ThumbSize / 2) / (rectangle_region.Height - ThumbSize);
                    rectangle_value = new Rectangle(
                    rectangle_region.X,
                    rectangle_region.Y + (Value * (rectangle_region.Height - ThumbSize) / Maximum),
                    rectangle_region.Width,
                    ThumbSize);
                    break;
                case Orientation.Horizontal:
                    if (e.X < 0) value -= SmallStep;
                    else if (e.X > rectangle_region.Width) value += SmallStep;
                    else value = Maximum * (e.X - ThumbSize / 2) / (rectangle_region.Width - ThumbSize);
                    rectangle_value = new Rectangle(
                    rectangle_region.X + (Value * (rectangle_region.Width - ThumbSize) / Maximum),
                    rectangle_region.Y,
                    ThumbSize,
                    rectangle_region.Height);
                    break;
            }
            Value = Math.Max(0, Math.Min(Maximum, value));
        }

19 View Source File : ChangesetConverter.cs
License : MIT License
Project Creator : aabiryukov

private static string ConvertFileExtensionToLowerCase(string fileName)
        {
            var slashIndex = Math.Max(fileName.LastIndexOf('/'), fileName.LastIndexOf('\\'));
            var pointIndex = fileName.LastIndexOf('.');
            if (pointIndex < slashIndex || pointIndex < 1 || pointIndex >= fileName.Length - 1)
                return fileName;

#pragma warning disable CA1308 // Normalize strings to uppercase
            return fileName.Substring(0, pointIndex + 1) + fileName.Substring(pointIndex + 1, fileName.Length - (pointIndex + 1)).ToLowerInvariant();
#pragma warning restore CA1308 // Normalize strings to uppercase
        }

19 View Source File : bidiagonal.cs
License : MIT License
Project Creator : 1CM69

public static void tobidiagonal(ref double[,] a, int m, int n, ref double[] tauq, ref double[] taup)
  {
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    double tau = 0.0;
    int num1 = Math.Min(m, n);
    int num2 = Math.Max(m, n);
    double[] work = new double[num2 + 1];
    double[] numArray3 = new double[num2 + 1];
    taup = new double[num1 + 1];
    tauq = new double[num1 + 1];
    if (m >= n)
    {
      for (int m1 = 1; m1 <= n; ++m1)
      {
        int n1 = m - m1 + 1;
        int num3 = m1 - 1;
        for (int index = 1; index <= n1; ++index)
          numArray3[index] = a[index + num3, m1];
        reflections.generatereflection(ref numArray3, n1, ref tau);
        tauq[m1] = tau;
        int num4 = 1 - m1;
        for (int index = m1; index <= m; ++index)
          a[index, m1] = numArray3[index + num4];
        numArray3[1] = 1.0;
        reflections.applyreflectionfromtheleft(ref a, tau, ref numArray3, m1, m, m1 + 1, n, ref work);
        if (m1 < n)
        {
          int n2 = n - m1;
          int num5 = m1 + 1;
          int num6 = num5 - 1;
          for (int index = 1; index <= n2; ++index)
            numArray3[index] = a[m1, index + num6];
          reflections.generatereflection(ref numArray3, n2, ref tau);
          taup[m1] = tau;
          int num7 = 1 - num5;
          for (int index = num5; index <= n; ++index)
            a[m1, index] = numArray3[index + num7];
          numArray3[1] = 1.0;
          reflections.applyreflectionfromtheright(ref a, tau, ref numArray3, m1 + 1, m, m1 + 1, n, ref work);
        }
        else
          taup[m1] = 0.0;
      }
    }
    else
    {
      for (int n1 = 1; n1 <= m; ++n1)
      {
        int n2 = n - n1 + 1;
        int num3 = n1 - 1;
        for (int index = 1; index <= n2; ++index)
          numArray3[index] = a[n1, index + num3];
        reflections.generatereflection(ref numArray3, n2, ref tau);
        taup[n1] = tau;
        int num4 = 1 - n1;
        for (int index = n1; index <= n; ++index)
          a[n1, index] = numArray3[index + num4];
        numArray3[1] = 1.0;
        reflections.applyreflectionfromtheright(ref a, tau, ref numArray3, n1 + 1, m, n1, n, ref work);
        if (n1 < m)
        {
          int n3 = m - n1;
          int num5 = n1 + 1;
          int num6 = num5 - 1;
          for (int index = 1; index <= n3; ++index)
            numArray3[index] = a[index + num6, n1];
          reflections.generatereflection(ref numArray3, n3, ref tau);
          tauq[n1] = tau;
          int num7 = 1 - num5;
          for (int index = num5; index <= m; ++index)
            a[index, n1] = numArray3[index + num7];
          numArray3[1] = 1.0;
          reflections.applyreflectionfromtheleft(ref a, tau, ref numArray3, n1 + 1, m, n1 + 1, n, ref work);
        }
        else
          tauq[n1] = 0.0;
      }
    }
  }

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

void ReplaceText(OffsetChangeMapEntry change)
		{
			Debug.replacedert(change.RemovalLength > 0);
			int offset = change.Offset;
			foreach (TextSegment segment in FindOverlappingSegments(offset, change.RemovalLength)) {
				if (segment.StartOffset <= offset) {
					if (segment.EndOffset >= offset + change.RemovalLength) {
						// Replacement inside segment: adjust segment length
						segment.Length += change.InsertionLength - change.RemovalLength;
					} else {
						// Replacement starting inside segment and ending after segment end: set segment end to removal position
						//segment.EndOffset = offset;
						segment.Length = offset - segment.StartOffset;
					}
				} else {
					// Replacement starting in front of text segment and running into segment.
					// Keep segment.EndOffset constant and move segment.StartOffset to the end of the replacement
					int remainingLength = segment.EndOffset - (offset + change.RemovalLength);
					RemoveSegment(segment);
					segment.StartOffset = offset + change.RemovalLength;
					segment.Length = Math.Max(0, remainingLength);
					AddSegment(segment);
				}
			}
			// move start offsets of all segments > offset
			TextSegment node = FindFirstSegmentWithStartAfter(offset + 1);
			if (node != null) {
				Debug.replacedert(node.nodeLength >= change.RemovalLength);
				node.nodeLength += change.InsertionLength - change.RemovalLength;
				UpdateAugmentedData(node);
			}
		}

19 View Source File : blas.cs
License : MIT License
Project Creator : 1CM69

public static void matrixmatrixmultiply(ref double[,] a, int ai1, int ai2, int aj1, int aj2, bool transa, ref double[,] b, int bi1, int bi2, int bj1, int bj2, bool transb, double alpha, ref double[,] c, int ci1, int ci2, int cj1, int cj2, double beta, ref double[] work)
  {
    int index1 = 0;
    int val1_1;
    int val2_1;
    if (!transa)
    {
      val1_1 = ai2 - ai1 + 1;
      val2_1 = aj2 - aj1 + 1;
    }
    else
    {
      val1_1 = aj2 - aj1 + 1;
      val2_1 = ai2 - ai1 + 1;
    }
    int val1_2;
    int val2_2;
    if (!transb)
    {
      val1_2 = bi2 - bi1 + 1;
      val2_2 = bj2 - bj1 + 1;
    }
    else
    {
      val1_2 = bj2 - bj1 + 1;
      val2_2 = bi2 - bi1 + 1;
    }
    if (val1_1 <= 0 | val2_1 <= 0 | val1_2 <= 0 | val2_2 <= 0)
      return;
    int num1 = val1_1;
    int val2_3 = System.Math.Max(val1_1, val2_1);
    int index2 = System.Math.Max(System.Math.Max(val1_2, val2_3), val2_2);
    work[1] = 0.0;
    work[index2] = 0.0;
    if (beta == 0.0)
    {
      for (int index3 = ci1; index3 <= ci2; ++index3)
      {
        for (int index4 = cj1; index4 <= cj2; ++index4)
          c[index3, index4] = 0.0;
      }
    }
    else
    {
      for (int index3 = ci1; index3 <= ci2; ++index3)
      {
        for (int index4 = cj1; index4 <= cj2; ++index4)
          c[index3, index4] = beta * c[index3, index4];
      }
    }
    if (!transa & !transb)
    {
      for (int index3 = ai1; index3 <= ai2; ++index3)
      {
        for (int index4 = bi1; index4 <= bi2; ++index4)
        {
          double num2 = alpha * a[index3, aj1 + index4 - bi1];
          int index5 = ci1 + index3 - ai1;
          int num3 = bj1 - cj1;
          for (int index6 = cj1; index6 <= cj2; ++index6)
            c[index5, index6] = c[index5, index6] + num2 * b[index4, index6 + num3];
        }
      }
    }
    else if (!transa & transb)
    {
      if (val1_1 * val2_1 < val1_2 * val2_2)
      {
        for (int index3 = bi1; index3 <= bi2; ++index3)
        {
          for (int index4 = ai1; index4 <= ai2; ++index4)
          {
            int num2 = bj1 - aj1;
            double num3 = 0.0;
            for (int index5 = aj1; index5 <= aj2; ++index5)
              num3 += a[index4, index5] * b[index3, index5 + num2];
            c[ci1 + index4 - ai1, cj1 + index3 - bi1] = c[ci1 + index4 - ai1, cj1 + index3 - bi1] + alpha * num3;
          }
        }
      }
      else
      {
        for (int index3 = ai1; index3 <= ai2; ++index3)
        {
          for (int index4 = bi1; index4 <= bi2; ++index4)
          {
            int num2 = bj1 - aj1;
            double num3 = 0.0;
            for (int index5 = aj1; index5 <= aj2; ++index5)
              num3 += a[index3, index5] * b[index4, index5 + num2];
            c[ci1 + index3 - ai1, cj1 + index4 - bi1] = c[ci1 + index3 - ai1, cj1 + index4 - bi1] + alpha * num3;
          }
        }
      }
    }
    else if (transa & !transb)
    {
      for (int index3 = aj1; index3 <= aj2; ++index3)
      {
        for (int index4 = bi1; index4 <= bi2; ++index4)
        {
          double num2 = alpha * a[ai1 + index4 - bi1, index3];
          int index5 = ci1 + index3 - aj1;
          int num3 = bj1 - cj1;
          for (int index6 = cj1; index6 <= cj2; ++index6)
            c[index5, index6] = c[index5, index6] + num2 * b[index4, index6 + num3];
        }
      }
    }
    else
    {
      if (!(transa & transb))
        return;
      if (val1_1 * val2_1 < val1_2 * val2_2)
      {
        for (int index3 = bi1; index3 <= bi2; ++index3)
        {
          for (int index4 = 1; index4 <= num1; ++index4)
            work[index4] = 0.0;
          for (int index4 = ai1; index4 <= ai2; ++index4)
          {
            double num2 = alpha * b[index3, bj1 + index4 - ai1];
            index1 = cj1 + index3 - bi1;
            int num3 = aj1 - 1;
            for (int index5 = 1; index5 <= num1; ++index5)
              work[index5] = work[index5] + num2 * a[index4, index5 + num3];
          }
          int num4 = 1 - ci1;
          for (int index4 = ci1; index4 <= ci2; ++index4)
            c[index4, index1] = c[index4, index1] + work[index4 + num4];
        }
      }
      else
      {
        for (int index3 = aj1; index3 <= aj2; ++index3)
        {
          int num2 = ai2 - ai1 + 1;
          int num3 = ai1 - 1;
          for (int index4 = 1; index4 <= num2; ++index4)
            work[index4] = a[index4 + num3, index3];
          for (int index4 = bi1; index4 <= bi2; ++index4)
          {
            int num4 = bj1 - 1;
            double num5 = 0.0;
            for (int index5 = 1; index5 <= num2; ++index5)
              num5 += work[index5] * b[index4, index5 + num4];
            c[ci1 + index3 - aj1, cj1 + index4 - bi1] = c[ci1 + index3 - aj1, cj1 + index4 - bi1] + alpha * num5;
          }
        }
      }
    }
  }

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

public void PushFront(T item)
		{
			if (size == arr.Length)
				SetCapacity(Math.Max(4, arr.Length * 2));
			if (head == 0)
				head = arr.Length - 1;
			else
				head--;
			arr[head] = item;
			size++;
		}

19 View Source File : bidiagonal.cs
License : MIT License
Project Creator : 1CM69

public static void multiplybypfrombidiagonal(ref double[,] qp, int m, int n, ref double[] taup, ref double[,] z, int zrows, int zcolumns, bool fromtheright, bool dotranspose)
  {
    double[] numArray1 = new double[0];
    double[] numArray2 = new double[0];
    if (m <= 0 | n <= 0 | zrows <= 0 | zcolumns <= 0)
      return;
    int num1 = Math.Max(Math.Max(Math.Max(m, n), zrows), zcolumns);
    numArray1 = new double[num1 + 1];
    numArray2 = new double[num1 + 1];
    double[] v = new double[num1 + 1];
    double[] work = new double[num1 + 1];
    if (m >= n)
    {
      int num2;
      int num3;
      int num4;
      if (fromtheright)
      {
        num2 = n - 1;
        num3 = 1;
        num4 = -1;
      }
      else
      {
        num2 = 1;
        num3 = n - 1;
        num4 = 1;
      }
      if (!dotranspose)
      {
        int num5 = num2;
        num2 = num3;
        num3 = num5;
        num4 = -num4;
      }
      if (n - 1 <= 0)
        return;
      int index1 = num2;
      do
      {
        int num5 = n - index1;
        int num6 = index1 + 1 - 1;
        for (int index2 = 1; index2 <= num5; ++index2)
          v[index2] = qp[index1, index2 + num6];
        v[1] = 1.0;
        if (fromtheright)
          reflections.applyreflectionfromtheright(ref z, taup[index1], ref v, 1, zrows, index1 + 1, n, ref work);
        else
          reflections.applyreflectionfromtheleft(ref z, taup[index1], ref v, index1 + 1, n, 1, zcolumns, ref work);
        index1 += num4;
      }
      while (index1 != num3 + num4);
    }
    else
    {
      int num2;
      int num3;
      int num4;
      if (fromtheright)
      {
        num2 = m;
        num3 = 1;
        num4 = -1;
      }
      else
      {
        num2 = 1;
        num3 = m;
        num4 = 1;
      }
      if (!dotranspose)
      {
        int num5 = num2;
        num2 = num3;
        num3 = num5;
        num4 = -num4;
      }
      int index1 = num2;
      do
      {
        int num5 = n - index1 + 1;
        int num6 = index1 - 1;
        for (int index2 = 1; index2 <= num5; ++index2)
          v[index2] = qp[index1, index2 + num6];
        v[1] = 1.0;
        if (fromtheright)
          reflections.applyreflectionfromtheright(ref z, taup[index1], ref v, 1, zrows, index1, n, ref work);
        else
          reflections.applyreflectionfromtheleft(ref z, taup[index1], ref v, index1, n, 1, zcolumns, ref work);
        index1 += num4;
      }
      while (index1 != num3 + num4);
    }
  }

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

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

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

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

19 View Source File : Rectangle.cs
License : zlib License
Project Creator : 0x0ade

public static Rectangle Union(Rectangle a, Rectangle b)
            => FromLTRB(
                Math.Min(a.Left, b.Left),
                Math.Min(a.Top, b.Top),
                Math.Max(a.Right, b.Right),
                Math.Max(a.Bottom, b.Bottom)
            );

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

[System.Diagnostics.Codereplacedysis.SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "PushBack")]
		public void PushBack(T item)
		{
			if (size == arr.Length)
				SetCapacity(Math.Max(4, arr.Length * 2));
			arr[tail++] = item;
			if (tail == arr.Length) tail = 0;
			size++;
		}

19 View Source File : leastsquares.cs
License : MIT License
Project Creator : 1CM69

public static bool buildchebyshevleastsquaresconstrained(ref double[] x, ref double[] y, ref double[] w, double a, double b, int n, ref double[] xc, ref double[] yc, ref int[] dc, int nc, int m, ref double[] ctbl)
  {
    double[,] numArray1 = new double[0, 0];
    double[] numArray2 = new double[0];
    double[,] numArray3 = new double[0, 0];
    double[,] numArray4 = new double[0, 0];
    double[,] u = new double[0, 0];
    double[,] vt = new double[0, 0];
    double[] numArray5 = new double[0];
    double[] numArray6 = new double[0];
    double[] w1 = new double[0];
    double[] numArray7 = new double[0];
    double[] numArray8 = new double[0];
    double[] numArray9 = new double[0];
    double[] numArray10 = new double[0];
    double[] numArray11 = new double[0];
    double[,] numArray12 = new double[0, 0];
    bool flag = true;
    double[,] a1 = new double[System.Math.Max(n, m + 1) + 1, m + 1 + 1];
    double[] numArray13 = new double[System.Math.Max(n, m + 1) + 1];
    for (int index1 = 1; index1 <= n; ++index1)
    {
      for (int index2 = 1; index2 <= m + 1; ++index2)
      {
        double num = 2.0 * (x[index1 - 1] - a) / (b - a) - 1.0;
        if (index2 == 1)
          a1[index1, index2] = 1.0;
        if (index2 == 2)
          a1[index1, index2] = num;
        if (index2 > 2)
          a1[index1, index2] = 2.0 * num * a1[index1, index2 - 1] - a1[index1, index2 - 2];
      }
    }
    for (int index1 = 1; index1 <= n; ++index1)
    {
      for (int index2 = 1; index2 <= m + 1; ++index2)
        a1[index1, index2] = w[index1 - 1] * a1[index1, index2];
    }
    for (int index1 = n + 1; index1 <= m + 1; ++index1)
    {
      for (int index2 = 1; index2 <= m + 1; ++index2)
        a1[index1, index2] = 0.0;
    }
    for (int index = 0; index <= n - 1; ++index)
      numArray13[index + 1] = w[index] * y[index];
    for (int index = n + 1; index <= m + 1; ++index)
      numArray13[index] = 0.0;
    n = System.Math.Max(n, m + 1);
    double[,] b1 = new double[m + 1 + 1, m + 1 + 1];
    double[] numArray14 = new double[m + 1 + 1];
    int num1;
    double[] work;
    if (nc == 0)
    {
      for (int index1 = 1; index1 <= m + 1; ++index1)
      {
        for (int index2 = 1; index2 <= m + 1; ++index2)
          b1[index1, index2] = 0.0;
        numArray14[index1] = 0.0;
      }
      for (int index = 1; index <= m + 1; ++index)
        b1[index, index] = 1.0;
      num1 = m + 1;
    }
    else
    {
      double[,] a2 = new double[nc + 1, m + 1 + 1];
      double[] numArray15 = new double[nc + 1];
      double[] numArray16 = new double[m + 1];
      double[] numArray17 = new double[m + 1];
      double[] numArray18 = new double[m + 1];
      for (int index1 = 0; index1 <= nc - 1; ++index1)
      {
        double num2 = 2.0 * (xc[index1] - a) / (b - a) - 1.0;
        for (int index2 = 0; index2 <= m; ++index2)
        {
          if (index2 == 0)
          {
            numArray16[index2] = 1.0;
            numArray17[index2] = 1.0;
            numArray18[index2] = 0.0;
          }
          if (index2 == 1)
          {
            numArray16[index2] = num2;
            numArray17[index2] = 2.0 * num2;
            numArray18[index2] = 1.0;
          }
          if (index2 > 1)
          {
            numArray16[index2] = 2.0 * num2 * numArray16[index2 - 1] - numArray16[index2 - 2];
            numArray17[index2] = 2.0 * num2 * numArray17[index2 - 1] - numArray17[index2 - 2];
            numArray18[index2] = (double) index2 * numArray17[index2 - 1];
          }
          if (dc[index1] == 0)
            a2[index1 + 1, index2 + 1] = numArray16[index2];
          if (dc[index1] == 1)
            a2[index1 + 1, index2 + 1] = numArray18[index2];
        }
        numArray15[index1 + 1] = yc[index1];
      }
      if (!svd.svddecomposition(a2, nc, m + 1, 2, 2, 2, ref w1, ref u, ref vt) || w1[1] == 0.0 | w1[nc] <= 5E-15 * System.Math.Sqrt((double) nc) * w1[1])
        return false;
      b1 = new double[m + 1 + 1, m + 1 - nc + 1];
      numArray14 = new double[m + 1 + 1];
      for (int index1 = 1; index1 <= m + 1 - nc; ++index1)
      {
        for (int index2 = 1; index2 <= m + 1; ++index2)
          b1[index2, index1] = vt[nc + index1, index2];
      }
      double[] numArray19 = new double[nc + 1];
      for (int index1 = 1; index1 <= nc; ++index1)
      {
        double num2 = 0.0;
        for (int index2 = 1; index2 <= nc; ++index2)
          num2 += u[index2, index1] * numArray15[index2];
        numArray19[index1] = num2 / w1[index1];
      }
      for (int index = 1; index <= m + 1; ++index)
        numArray14[index] = 0.0;
      for (int index1 = 1; index1 <= nc; ++index1)
      {
        double num2 = numArray19[index1];
        for (int index2 = 1; index2 <= m + 1; ++index2)
          numArray14[index2] = numArray14[index2] + num2 * vt[index1, index2];
      }
      for (int index1 = 1; index1 <= n; ++index1)
      {
        double num2 = 0.0;
        for (int index2 = 1; index2 <= m + 1; ++index2)
          num2 += a1[index1, index2] * numArray14[index2];
        numArray13[index1] = numArray13[index1] - num2;
      }
      num1 = m + 1 - nc;
      double[,] numArray20 = new double[n + 1, num1 + 1];
      work = new double[n + 1];
      blas.matrixmatrixmultiply(ref a1, 1, n, 1, m + 1, false, ref b1, 1, m + 1, 1, num1, false, 1.0, ref numArray20, 1, n, 1, num1, 0.0, ref work);
      blas.copymatrix(ref numArray20, 1, n, 1, num1, ref a1, 1, n, 1, num1);
    }
    if (!svd.svddecomposition(a1, n, num1, 1, 1, 2, ref w1, ref u, ref vt))
      return false;
    work = new double[num1 + 1];
    double[] numArray21 = new double[num1 + 1];
    for (int index = 1; index <= num1; ++index)
      work[index] = 0.0;
    for (int index1 = 1; index1 <= n; ++index1)
    {
      double num2 = numArray13[index1];
      for (int index2 = 1; index2 <= num1; ++index2)
        work[index2] = work[index2] + num2 * u[index1, index2];
    }
    for (int index = 1; index <= num1; ++index)
      work[index] = !(w1[index] != 0.0 & w1[index] > 5E-15 * System.Math.Sqrt((double) nc) * w1[1]) ? 0.0 : work[index] / w1[index];
    for (int index = 1; index <= num1; ++index)
      numArray21[index] = 0.0;
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      double num2 = work[index1];
      for (int index2 = 1; index2 <= num1; ++index2)
        numArray21[index2] = numArray21[index2] + num2 * vt[index1, index2];
    }
    ctbl = new double[m + 2 + 1];
    for (int index1 = 1; index1 <= m + 1; ++index1)
    {
      double num2 = 0.0;
      for (int index2 = 1; index2 <= num1; ++index2)
        num2 += b1[index1, index2] * numArray21[index2];
      ctbl[index1 - 1] = num2 + numArray14[index1];
    }
    ctbl[m + 1] = a;
    ctbl[m + 2] = b;
    return flag;
  }

19 View Source File : leastsquares.cs
License : MIT License
Project Creator : 1CM69

public static void buildsplineleastsquares(ref double[] x, ref double[] y, ref double[] w, double a, double b, int n, int m, ref double[] ctbl)
  {
    double[,] numArray1 = new double[0, 0];
    double[,] numArray2 = new double[0, 0];
    double[,] numArray3 = new double[0, 0];
    double[] numArray4 = new double[0];
    double[] tau = new double[0];
    double[,] numArray5 = new double[0, 0];
    double[] tauq = new double[0];
    double[] taup = new double[0];
    double[] d = new double[0];
    double[] e = new double[0];
    bool isupper = false;
    double[] numArray6 = new double[0];
    double[] numArray7 = new double[0];
    int val1 = n;
    int num1 = m;
    double[] x1 = new double[num1 - 1 + 1];
    double[] y1 = new double[num1 - 1 + 1];
    double[,] numArray8 = new double[num1 + 1, System.Math.Max(val1, num1) + 1];
    double[] numArray9 = new double[System.Math.Max(val1, num1) + 1];
    for (int index = 0; index <= num1 - 1; ++index)
      x1[index] = a + (b - a) * (double) index / (double) (num1 - 1);
    for (int index1 = 0; index1 <= num1 - 1; ++index1)
    {
      for (int index2 = 0; index2 <= num1 - 1; ++index2)
        y1[index2] = 0.0;
      y1[index1] = 1.0;
      spline3.buildcubicspline(x1, y1, num1, 0, 0.0, 0, 0.0, ref ctbl);
      for (int index2 = 0; index2 <= val1 - 1; ++index2)
        numArray8[index1 + 1, index2 + 1] = w[index2] * spline3.splineinterpolation(ref ctbl, x[index2]);
    }
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      for (int index2 = val1 + 1; index2 <= num1; ++index2)
        numArray8[index1, index2] = 0.0;
    }
    for (int index = 0; index <= val1 - 1; ++index)
      numArray9[index + 1] = w[index] * y[index];
    for (int index = val1 + 1; index <= num1; ++index)
      numArray9[index] = 0.0;
    int n1 = System.Math.Max(val1, num1);
    lq.lqdecomposition(ref numArray8, num1, n1, ref tau);
    lq.unpackqfromlq(ref numArray8, num1, n1, ref tau, num1, ref numArray2);
    double[,] numArray10 = new double[2, num1 + 1];
    for (int index = 1; index <= num1; ++index)
      numArray10[1, index] = 0.0;
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      double num2 = 0.0;
      for (int index2 = 1; index2 <= n1; ++index2)
        num2 += numArray9[index2] * numArray2[index1, index2];
      numArray10[1, index1] = num2;
    }
    for (int index1 = 1; index1 <= num1 - 1; ++index1)
    {
      for (int index2 = index1 + 1; index2 <= num1; ++index2)
        numArray8[index1, index2] = numArray8[index2, index1];
    }
    for (int index1 = 2; index1 <= num1; ++index1)
    {
      for (int index2 = 1; index2 <= index1 - 1; ++index2)
        numArray8[index1, index2] = 0.0;
    }
    bidiagonal.tobidiagonal(ref numArray8, num1, num1, ref tauq, ref taup);
    bidiagonal.multiplybyqfrombidiagonal(ref numArray8, num1, num1, ref tauq, ref numArray10, 1, num1, true, false);
    bidiagonal.unpackptfrombidiagonal(ref numArray8, num1, num1, ref taup, num1, ref numArray3);
    bidiagonal.unpackdiagonalsfrombidiagonal(ref numArray8, num1, num1, ref isupper, ref d, ref e);
    if (!bdsvd.bidiagonalsvddecomposition(ref d, e, num1, isupper, false, ref numArray10, 1, ref numArray2, 0, ref numArray3, num1))
    {
      for (int index1 = 1; index1 <= num1; ++index1)
      {
        d[index1] = 0.0;
        numArray10[1, index1] = 0.0;
        for (int index2 = 1; index2 <= num1; ++index2)
          numArray3[index1, index2] = index1 != index2 ? 0.0 : 1.0;
      }
      numArray10[1, 1] = 1.0;
    }
    for (int index = 1; index <= num1; ++index)
      numArray10[1, index] = d[index] <= 5E-15 * System.Math.Sqrt((double) num1) * d[1] ? 0.0 : numArray10[1, index] / d[index];
    for (int index = 1; index <= num1; ++index)
      numArray9[index] = 0.0;
    for (int index1 = 1; index1 <= num1; ++index1)
    {
      double num2 = numArray10[1, index1];
      for (int index2 = 1; index2 <= num1; ++index2)
        numArray9[index2] = numArray9[index2] + num2 * numArray3[index1, index2];
    }
    for (int index = 0; index <= num1 - 1; ++index)
      y1[index] = numArray9[index + 1];
    spline3.buildcubicspline(x1, y1, num1, 0, 0.0, 0, 0.0, ref ctbl);
  }

19 View Source File : Rectangle.cs
License : zlib License
Project Creator : 0x0ade

public void Intersect(Rectangle rect) {
            if (!IntersectsWithInclusive(rect)) {
                x = y = width = height = 0;
                return;
            }

            x = Math.Max(Left, rect.Left);
            y = Math.Max(Top, rect.Top);
            width = Math.Min(Right, rect.Right) - x;
            height = Math.Min(Bottom, rect.Bottom) - y;
        }

19 View Source File : DdsFile.cs
License : MIT License
Project Creator : 0xC0000054

private static TextureCollection GetTextures(Surface scratchSurface, Size? cubeMapFaceSize, int mipLevels, ResamplingAlgorithm algorithm)
        {
            TextureCollection textures = null;
            TextureCollection tempTextures = null;

            try
            {
                tempTextures = new TextureCollection(mipLevels);

                if (cubeMapFaceSize.HasValue)
                {
                    // DirectX 10+ requires DDS cube maps to have all 6 faces.
                    tempTextures.Capacity *= 6;

                    Size faceSize = cubeMapFaceSize.Value;
                    Point[] cubeMapOffsets = new Point[6];

                    // Split the crossed image into the individual cube map faces.
                    //
                    // The crossed image uses the same layout as the Intel® Texture Works DDS plug-in for Adobe Photoshop®
                    // (https://github.com/GameTechDev/Intel-Texture-Works-Plugin)
                    //
                    // The DirectXTex texreplacedemble utility and Unity® both use different layouts, so there does not appear
                    // to be any common standard for a crossed image.
                    //
                    // The cube map faces in a DDS file are always ordered: +X, -X, +Y, -Y, +Z, -Z.

                    if (scratchSurface.Width > scratchSurface.Height)
                    {
                        // A horizontal crossed image uses the following layout:
                        //
                        //		  [ +Y ]
                        //	[ -X ][ +Z ][ +X ][ -Z ]
                        //		  [ -Y ]
                        //
                        cubeMapOffsets[0] = new Point(faceSize.Width * 2, faceSize.Height);  // +X
                        cubeMapOffsets[1] = new Point(0, faceSize.Height);                   // -X
                        cubeMapOffsets[2] = new Point(faceSize.Width, 0);                    // +Y
                        cubeMapOffsets[3] = new Point(faceSize.Width, faceSize.Height * 2);  // -Y
                        cubeMapOffsets[4] = new Point(faceSize.Width, faceSize.Height);      // +Z
                        cubeMapOffsets[5] = new Point(faceSize.Width * 3, faceSize.Height);  // -Z
                    }
                    else
                    {
                        // A vertical crossed image uses the following layout:
                        //
                        //		  [ +Y ]
                        //	[ -X ][ +Z ][ +X ]
                        //		  [ -Y ]
                        //		  [ -Z ]
                        //
                        cubeMapOffsets[0] = new Point(faceSize.Width * 2, faceSize.Height);  // +X
                        cubeMapOffsets[1] = new Point(0, faceSize.Height);                   // -X
                        cubeMapOffsets[2] = new Point(faceSize.Width, 0);                    // +Y
                        cubeMapOffsets[3] = new Point(faceSize.Width, faceSize.Height * 2);  // -Y
                        cubeMapOffsets[4] = new Point(faceSize.Width, faceSize.Height);      // +Z
                        cubeMapOffsets[5] = new Point(faceSize.Width, faceSize.Height * 3);  // -Z
                    }

                    for (int i = 0; i < 6; ++i)
                    {
                        Point srcStartOffset = cubeMapOffsets[i];

                        tempTextures.Add(new Texture(scratchSurface.CreateWindow(srcStartOffset.X, srcStartOffset.Y, faceSize.Width, faceSize.Height), true));

                        if (mipLevels > 1)
                        {
                            Surface cubeMapSurface = tempTextures[tempTextures.Count - 1].Surface;

                            for (int j = 1; j < mipLevels; ++j)
                            {
                                int mipWidth = Math.Max(1, cubeMapSurface.Width >> j);
                                int mipHeight = Math.Max(1, cubeMapSurface.Height >> j);

                                tempTextures.Add(CreateMipTexture(cubeMapSurface, mipWidth, mipHeight, algorithm));
                            }
                        }
                    }
                }
                else
                {
                    tempTextures.Add(new Texture(scratchSurface, false));

                    if (mipLevels > 1)
                    {
                        for (int j = 1; j < mipLevels; ++j)
                        {
                            int mipWidth = Math.Max(1, scratchSurface.Width >> j);
                            int mipHeight = Math.Max(1, scratchSurface.Height >> j);

                            tempTextures.Add(CreateMipTexture(scratchSurface, mipWidth, mipHeight, algorithm));
                        }
                    }
                }

                textures = tempTextures;
                tempTextures = null;
            }
            finally
            {
                if (tempTextures != null)
                {
                    tempTextures.Dispose();
                }
            }

            return textures;
        }

19 View Source File : bdsvd.cs
License : MIT License
Project Creator : 1CM69

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

19 View Source File : AreaForm.cs
License : MIT License
Project Creator : 1CM69

private void mouse_Move(object sender, MouseEventArgs e)
    {
      int num = 1;

            if (this.LeftButtonDown)
      {
        this.g.DrawRectangle(this.EraserPen, this.CurrentTopLeft.X, this.CurrentTopLeft.Y, this.CurrentBottomRight.X - this.CurrentTopLeft.X, this.CurrentBottomRight.Y - this.CurrentTopLeft.Y);
        num = Math.Max(Math.Abs(Cursor.Position.X - this.ClickPoint.X), Math.Abs(Cursor.Position.Y - this.ClickPoint.Y));
        this.Cursor = Cursors.Hand;
            }
      this.CurrentTopLeft.X = this.ClickPoint.X - num;
      this.CurrentTopLeft.Y = this.ClickPoint.Y - num;
      this.CurrentBottomRight.X = this.ClickPoint.X + num;
      this.CurrentBottomRight.Y = this.ClickPoint.Y + num;
      this.g.DrawRectangle(this.MyPen, this.CurrentTopLeft.X, this.CurrentTopLeft.Y, this.CurrentBottomRight.X - this.CurrentTopLeft.X, this.CurrentBottomRight.Y - this.CurrentTopLeft.Y);
    }

19 View Source File : TestLIBIGL.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

public static Mesh CreateLIBIGLMeshBooleanNoColors(Mesh[] m_, int Difference_Union_Intersection = 0) {

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Clean Mesh
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            var meshes = new List<Mesh>(m_.Length);

            for (int i = 0; i < m_.Length; i++) {

                if (!m_[i].IsClosed)
                    continue;

                m_[i].Vertices.UseDoublePrecisionVertices = true;
                Mesh m = m_[i].DuplicateMesh();
                m.Vertices.UseDoublePrecisionVertices = true;
                m.Faces.ConvertQuadsToTriangles();
                m.Vertices.CombineIdentical(true, true);
                m.Vertices.CullUnused();
                m.Weld(3.14159265358979);
                m.FillHoles();
                m.RebuildNormals();
                m.Vertices.UseDoublePrecisionVertices = true;

                if (m.IsValid && m.IsClosed)
                    meshes.Add(m);
            }

            if (meshes.Count < 2)
                return null;




            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Send Vertices and Faces to C++
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////




            int numberOfVertices = 0;
            int numberOfFaces = 0;
            foreach (Mesh tempMesh in meshes) {
                numberOfVertices += tempMesh.Vertices.Count;
                numberOfFaces += tempMesh.Faces.Count;
            }

            double[] coord = new double[numberOfVertices * 3];
            int[] vertexArrayCount = new int[meshes.Count + 1];
            vertexArrayCount[0] = 0;

            int[] faceID = new int[numberOfFaces * 3];
            int[] faceArrayCount = new int[meshes.Count + 1];
            faceArrayCount[0] = 0;

            int nMesh = meshes.Count;



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

                vertexArrayCount[i + 1] = vertexArrayCount[i] + meshes[i].Vertices.Count;
                faceArrayCount[i + 1] = faceArrayCount[i] + meshes[i].Faces.Count;

                for (int j = 0; j < meshes[i].Vertices.Count; j++) {
                    int n = vertexArrayCount[i] * 3;
                    coord[n + (j * 3 + 0)] = meshes[i].Vertices.Point3dAt(j).X;
                    coord[n + (j * 3 + 1)] = meshes[i].Vertices.Point3dAt(j).Y;
                    coord[n + (j * 3 + 2)] = meshes[i].Vertices.Point3dAt(j).Z;
                    ////Rhino.RhinoApp.WriteLine((n + (j * 3 + 0).ToString() + " " + meshes[i].Vertices[j].X.ToString()));
                    ////Rhino.RhinoApp.WriteLine((n + (j * 3 + 1).ToString() + " " + meshes[i].Vertices[j].Y.ToString()));
                    ////Rhino.RhinoApp.WriteLine((n + (j * 3 + 2).ToString() + " " + meshes[i].Vertices[j].Z.ToString()));
                }

                for (int j = 0; j < meshes[i].Faces.Count; j++) {
                    int n = faceArrayCount[i] * 3;
                    faceID[n + (j * 3 + 0)] = meshes[i].Faces[j].A;
                    faceID[n + (j * 3 + 1)] = meshes[i].Faces[j].B;
                    faceID[n + (j * 3 + 2)] = meshes[i].Faces[j].C;
                }

            }


            //Rhino.RhinoApp.WriteLine(coord.Length.ToString());
            //foreach(var c in vertexArrayCount)
            //Rhino.RhinoApp.Write(c.ToString()+" ");
            //Rhino.RhinoApp.WriteLine();
            //Rhino.RhinoApp.WriteLine(faceID.Length.ToString());
            // foreach (var c in faceArrayCount)
            //Rhino.RhinoApp.Write(c.ToString() + " ");
            //Rhino.RhinoApp.WriteLine();
            //Rhino.RhinoApp.WriteLine(nMesh.ToString());




            ////Inputs
            IntPtr vertexCoordPointer = IntPtr.Zero;
            int nVertices = 0;
            IntPtr faceIndicesPointer = IntPtr.Zero;
            int nFaces = 0;


            //Call C++ method
            UnsafeLIBIGL.LIBIGL_MeshBoolean_CreateArrayNoColors(
                coord, vertexArrayCount,
                faceID, faceArrayCount,
                (ulong)nMesh,

                (ulong)Math.Max(0, Math.Min(Difference_Union_Intersection, 2)),

                ref vertexCoordPointer, ref nVertices,
                ref faceIndicesPointer, ref nFaces);//
                                                    //Rhino.RhinoApp.WriteLine(numberOfValidMeshes.ToString());
                                                    // return null;


            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Get Vertices and Faces from C++
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //Convert faceIndicesPointer to C# int[]
            double[] verticesCoordinates = new double[nVertices * 3];
            Marshal.Copy(vertexCoordPointer, verticesCoordinates, 0, verticesCoordinates.Length);

            int[] faceIndices = new int[nFaces * 3];
            Marshal.Copy(faceIndicesPointer, faceIndices, 0, faceIndices.Length);


            //Rhino.RhinoApp.WriteLine(verticesCoordinates.Length.ToString()  + " " + nVertices.ToString());
            //Rhino.RhinoApp.WriteLine(faceIndices.Length.ToString() + " " + nFaces.ToString());



            //Create mesh
            Mesh r_ = new Mesh();
            for (int i = 0; i < verticesCoordinates.Length; i += 3)
                r_.Vertices.Add(new Point3d(verticesCoordinates[i + 0], verticesCoordinates[i + 1], verticesCoordinates[i + 2]));

            for (int i = 0; i < faceIndices.Length; i += 3) {
                r_.Faces.AddFace(faceIndices[i + 0], faceIndices[i + 1], faceIndices[i + 2]);
            }

            //mesh.Vertices.Align(0.01);
            //mesh.Vertices.CombineIdentical(true, true);
            //mesh.Vertices.CullUnused();
            //mesh.Weld(3.14159265358979);
            //mesh.FillHoles();
            r_.RebuildNormals();


            //Release memory from output
            UnsafeLIBIGL.ReleaseDouble(vertexCoordPointer, true);
            UnsafeLIBIGL.ReleaseInt(faceIndicesPointer, true);



            return r_;
        }

See More Examples