Skip to content
Snippets Groups Projects
Commit a9b9014d authored by MaZiFAU's avatar MaZiFAU
Browse files

Some refactoring and minor bug fixes

parent 74a8996a
Branches
No related tags found
No related merge requests found
Showing
with 254 additions and 3 deletions

/// <summary>
/// Source: https://www.geeksforgeeks.org/topological-sorting/
/// </summary>
namespace geeksforgeeks
{
// A C# program to print topological
// sorting of a DAG
using System;
using System.Collections.Generic;
// This class represents a directed graph
// using adjacency list representation
class Graph
{
// No. of vertices
private readonly int V;
// Adjacency List as ArrayList
// of ArrayList's
private List<List<int>> adj;
// Constructor
Graph(int v)
{
V = v;
adj = new List<List<int>>(v);
for (int i = 0; i < v; i++)
adj.Add(new List<int>());
}
// Function to add an edge into the graph
public void AddEdge(int v, int w) { adj[v].Add(w); }
// A recursive function used by topologicalSort
void TopologicalSortUtil(int v, bool[] visited,
Stack<int> stack)
{
// Mark the current node as visited.
visited[v] = true;
// Recur for all the vertices
// adjacent to this vertex
foreach (var vertex in adj[v])
{
if (!visited[vertex])
TopologicalSortUtil(vertex, visited, stack);
}
// Push current vertex to
// stack which stores result
stack.Push(v);
}
// The function to do Topological Sort.
// It uses recursive topologicalSortUtil()
void TopologicalSort()
{
Stack<int> stack = new Stack<int>();
// Mark all the vertices as not visited
var visited = new bool[V];
// Call the recursive helper function
// to store Topological Sort starting
// from all vertices one by one
for (int i = 0; i < V; i++)
{
if (visited[i] == false)
TopologicalSortUtil(i, visited, stack);
}
// Print contents of stack
foreach (var vertex in stack)
{
Console.Write(vertex + " ");
}
}
// Driver code
public static void Main(string[] args)
{
// Create a graph given
// in the above diagram
Graph g = new Graph(6);
g.AddEdge(5, 2);
g.AddEdge(5, 0);
g.AddEdge(4, 0);
g.AddEdge(4, 1);
g.AddEdge(2, 3);
g.AddEdge(3, 1);
Console.WriteLine("Following is a Topological "
+ "sort of the given graph");
// Function Call
g.TopologicalSort();
}
}
// This code is contributed by Abhinav Galodha
}
fileFormatVersion: 2
guid: d87236740cbbf894fbeb2129ea06eccc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -538,13 +538,12 @@ public static bool IsPointOnLine(Vector3 linePoint, Vector3 lineVec, Vector3 poi ...@@ -538,13 +538,12 @@ public static bool IsPointOnLine(Vector3 linePoint, Vector3 lineVec, Vector3 poi
//The line is regarded as being infinite. //The line is regarded as being infinite.
public static bool IsPointApproximatelyOnLine(Vector3 linePoint, Vector3 lineVec, Vector3 point, double precission = Math3d.vectorPrecission) public static bool IsPointApproximatelyOnLine(Vector3 linePoint, Vector3 lineVec, Vector3 point, double precission = Math3d.vectorPrecission)
{ {
//get vector from point on line to point in space //get vector from point on line to point in space
Vector3 linePointToPoint = point - linePoint; Vector3 linePointToPoint = point - linePoint;
double t = Vector3.Dot(linePointToPoint.normalized, lineVec); double t = Math.Abs(Vector3.Dot(linePointToPoint.normalized, lineVec)); // expected to be ~1
return Math.Abs(Math.Abs(t) - 1d) < precission || Math.Abs(t) < precission; return Math.Cos(precission) < t;
} }
//This function returns true if two Vector3s are approximately parallel //This function returns true if two Vector3s are approximately parallel
......
{
"MonoBehaviour": {
"Version": 4,
"EnableBurstCompilation": true,
"EnableOptimisations": true,
"EnableSafetyChecks": false,
"EnableDebugInAllBuilds": false,
"CpuMinTargetX32": 0,
"CpuMaxTargetX32": 0,
"CpuMinTargetX64": 0,
"CpuMaxTargetX64": 0,
"OptimizeFor": 0
}
}
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/
# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/
# Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta
# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*
# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*
# Visual Studio cache directory
.vs/
# Gradle cache directory
.gradle/
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db
# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta
# Unity3D generated file on crash reports
sysinfo.txt
# Builds
*.apk
*.aab
*.unitypackage
# Crashlytics generated file
crashlytics-build.properties
# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment