Weapos Rejiggered
Modified weapon scripts to eliminate specialized projectile behavior - allows charged weapons to have projectiles and modify weapon stats when charged Added machine gun weapon & VFX Moved third party code to Plugins folder to improve compile times
This commit is contained in:
parent
2a0fe34611
commit
dbc522a224
2105 changed files with 7033 additions and 1141 deletions
57
Assets/Plugins/MSAGL/GraphmapsWithMesh/Angle.cs
Normal file
57
Assets/Plugins/MSAGL/GraphmapsWithMesh/Angle.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
|
||||
namespace Microsoft.Msagl.GraphmapsWithMesh
|
||||
{
|
||||
class Angle
|
||||
{
|
||||
//compute the angle at A if it is less than pi/2, otherwise return pi/2
|
||||
|
||||
/*TESTS
|
||||
Console.WriteLine("0 0, 1 1, 0 1" +Angle.getAngleIfSmallerThanPIby2(new Vertex(0, 0), new Vertex(1, 1), new Vertex(0, 1)));
|
||||
Console.WriteLine("0 0, -1 1, 0 1" + Angle.getAngleIfSmallerThanPIby2(new Vertex(0, 0), new Vertex(-1, 1), new Vertex(0, 1)));
|
||||
Console.WriteLine("0 0, -1 -1, 0 1" + Angle.getAngleIfSmallerThanPIby2(new Vertex(0, 0), new Vertex(-1, -1), new Vertex(0, 1)));
|
||||
Console.WriteLine("0 0, 1 -1, 0 1" + Angle.getAngleIfSmallerThanPIby2(new Vertex(0, 0), new Vertex(1, -1), new Vertex(0, 1)));
|
||||
Console.WriteLine("0 0, -1 1, 1 1" + Angle.getAngleIfSmallerThanPIby2(new Vertex(0, 0), new Vertex(-1, 1), new Vertex(1, 1)));
|
||||
Console.WriteLine("0 0, -1 -1, 1 1" + Angle.getAngleIfSmallerThanPIby2(new Vertex(0, 0), new Vertex(-1, -1), new Vertex(1, 1)));
|
||||
Console.WriteLine("0 0, 1 -1, 1 1" + Angle.getAngleIfSmallerThanPIby2(new Vertex(0, 0), new Vertex(1, -1), new Vertex(1, 1)));
|
||||
*/
|
||||
public static double getAngleIfSmallerThanPIby2(Vertex A, Vertex B, Vertex C)
|
||||
{
|
||||
|
||||
double xDiff1 = A.XLoc - B.XLoc;
|
||||
double yDiff1 = A.YLoc - B.YLoc;
|
||||
|
||||
double xDiff2 = A.XLoc - C.XLoc;
|
||||
double yDiff2 = A.YLoc - C.YLoc;
|
||||
|
||||
if (B.XLoc >= A.XLoc && C.XLoc >= A.XLoc && B.YLoc >= A.YLoc && C.YLoc >= A.YLoc)
|
||||
return Math.Abs(Math.Atan2(yDiff1, xDiff1) - Math.Atan2(yDiff2, xDiff2));
|
||||
if (B.XLoc >= A.XLoc && C.XLoc <= A.XLoc && B.YLoc >= A.YLoc && C.YLoc <= A.YLoc)
|
||||
return Math.Abs(Math.Atan2(yDiff1, xDiff1) - Math.Atan2(yDiff2, xDiff2));
|
||||
if (B.XLoc <= A.XLoc && C.XLoc >= A.XLoc && B.YLoc <= A.YLoc && C.YLoc >= A.YLoc)
|
||||
return Math.Abs(Math.Atan2(yDiff1, xDiff1) - Math.Atan2(yDiff2, xDiff2));
|
||||
if (B.XLoc <= A.XLoc && C.XLoc <= A.XLoc && B.YLoc <= A.YLoc && C.YLoc <= A.YLoc)
|
||||
return Math.Abs(Math.Atan2(yDiff1, xDiff1) - Math.Atan2(yDiff2, xDiff2));
|
||||
|
||||
|
||||
return Math.PI / 2;//Abs(Math.Atan2(yDiff1, xDiff1) - Math.Atan2(yDiff2, xDiff2));
|
||||
}
|
||||
|
||||
public static double getClockwiseAngle(Vertex A, Vertex B, Vertex C)
|
||||
{
|
||||
|
||||
double xDiff1 = A.XLoc - B.XLoc;
|
||||
double yDiff1 = A.YLoc - B.YLoc;
|
||||
|
||||
double xDiff2 = A.XLoc - C.XLoc;
|
||||
double yDiff2 = A.YLoc - C.YLoc;
|
||||
|
||||
double dot = xDiff1 * xDiff2 + yDiff1 * yDiff2; // dot product
|
||||
double det = xDiff1 * yDiff2 - yDiff1 * xDiff2; // determinant
|
||||
double angle = Math.Atan2(det, dot); // atan2(y, x) or atan2(sin, cos)
|
||||
|
||||
if (angle < 0) angle = 2 * Math.PI + angle;
|
||||
return Math.Abs(angle); // in degree*180/Math.PI;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/Angle.cs.meta
Normal file
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/Angle.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 633fc7d537c7d3340b7bf138758db7a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
|
||||
namespace Microsoft.Msagl.GraphmapsWithMesh
|
||||
{
|
||||
|
||||
/*
|
||||
* This class is not used for the current implementation
|
||||
* This was written in the previous one when we were trying to route with
|
||||
* regular grid and then recursively found the stainer trees for the
|
||||
* components of different zoomlevel
|
||||
*/
|
||||
|
||||
public class ComponentCollection
|
||||
{
|
||||
internal int NumOfComponents;
|
||||
public int NumOfAliveComponents;
|
||||
public Component[] C; //componnent holder
|
||||
|
||||
public ComponentCollection(Vertex[] w, int numOfv, Component givenComponent, int givenLevel)
|
||||
{ //initially every vertex is a single component
|
||||
int k = 0;
|
||||
C = new Component[numOfv + 1];
|
||||
for (int index = 1; index <= numOfv; index++)
|
||||
{
|
||||
|
||||
w[index].CId = 0;
|
||||
if (w[index].Weight == 0 || w[index].ZoomLevel != givenLevel) continue;
|
||||
|
||||
//NODE OVARLAPS WITH THE RAILS// SO IGNORE THE NODE
|
||||
if (givenComponent != null && givenComponent.V.Contains(w[index])) continue;
|
||||
|
||||
k++;
|
||||
C[k] = new Component { CId = k };
|
||||
C[k].V.Add(w[index]);
|
||||
C[k].Dead = false;
|
||||
w[index].CId = C[k].CId;
|
||||
NumOfComponents++;
|
||||
}
|
||||
if (givenComponent != null)
|
||||
{
|
||||
k++;
|
||||
C[k] = givenComponent;
|
||||
C[k].CId = k;
|
||||
C[k].Dist = 0;
|
||||
C[k].Dead = false;
|
||||
foreach (Vertex x in C[k].V)
|
||||
{
|
||||
x.CId = C[k].CId;
|
||||
}
|
||||
NumOfComponents++;
|
||||
}
|
||||
NumOfAliveComponents = NumOfComponents;
|
||||
Console.WriteLine(" Number of components:" + NumOfAliveComponents);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 332e1aa53d9ed1d4daa49cf113969395
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
564
Assets/Plugins/MSAGL/GraphmapsWithMesh/DijkstraAlgo.cs
Normal file
564
Assets/Plugins/MSAGL/GraphmapsWithMesh/DijkstraAlgo.cs
Normal file
|
|
@ -0,0 +1,564 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Msagl.Core.DataStructures;
|
||||
using Microsoft.Msagl.Core.Layout;
|
||||
|
||||
namespace Microsoft.Msagl.GraphmapsWithMesh
|
||||
{
|
||||
class DijkstraAlgo
|
||||
{
|
||||
public List<VertexNeighbor> Edgelist = new List<VertexNeighbor>();
|
||||
public List<int> ShortestPath = new List<int>();
|
||||
public double Distance;
|
||||
public bool PathExists = true;
|
||||
|
||||
|
||||
public Vertex getMin(List<Vertex> q)
|
||||
{
|
||||
double m = double.MaxValue;
|
||||
Vertex temp_vertex = null;
|
||||
foreach (Vertex w in q)
|
||||
{
|
||||
if (m > w.Dist)
|
||||
{
|
||||
m = w.Dist;
|
||||
temp_vertex = w;
|
||||
}
|
||||
}
|
||||
if (temp_vertex == null)
|
||||
{
|
||||
Console.WriteLine("Graph is disconnected");
|
||||
return null;
|
||||
}
|
||||
foreach (Vertex w in q)
|
||||
{
|
||||
if (w.Id == temp_vertex.Id)
|
||||
{
|
||||
q.Remove(temp_vertex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return temp_vertex;
|
||||
}
|
||||
|
||||
public void SelectShortestPath(Vertex[] vList, Edge[,] eList, int[] degList, int source, int target, int n)
|
||||
{
|
||||
|
||||
|
||||
List<Vertex> q = new List<Vertex>();
|
||||
vList[source].Dist = 0;
|
||||
q.Add(vList[source]);
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
if (vList[i].Id != vList[source].Id)
|
||||
{
|
||||
vList[i].Dist = double.MaxValue;
|
||||
q.Add(vList[i]);
|
||||
}
|
||||
vList[i].Parent = null;
|
||||
vList[i].Visited = false;
|
||||
}
|
||||
|
||||
Edgelist.Clear();
|
||||
Distance = 0;
|
||||
|
||||
while (q.Count > 0)
|
||||
{
|
||||
Vertex u = getMin(q);
|
||||
if (u.Visited) continue;
|
||||
else u.Visited = true;
|
||||
for (int neighb = 1; neighb <= degList[u.Id]; neighb++)
|
||||
{
|
||||
var neighbor = eList[u.Id, neighb].NodeId;
|
||||
|
||||
int discourage = 0;
|
||||
if (eList[u.Id, neighb].Selected == 0) discourage = 1000;//continue;
|
||||
if (vList[eList[u.Id, neighb].NodeId].Weight > 0 &&
|
||||
eList[u.Id, neighb].NodeId != vList[target].Id) continue;
|
||||
|
||||
|
||||
var temp = u.Dist + eList[u.Id, neighb].GetEDist(vList, u.Id, eList[u.Id, neighb].NodeId) + discourage;
|
||||
|
||||
if (temp < vList[neighbor].Dist)
|
||||
{
|
||||
vList[neighbor].Dist = temp;
|
||||
vList[neighbor].Parent = u;
|
||||
//Update(q, vList[neighbor]);
|
||||
}
|
||||
}
|
||||
if (u.Id == vList[target].Id)
|
||||
break;
|
||||
}
|
||||
|
||||
Vertex route = vList[target];
|
||||
|
||||
//Console.WriteLine();
|
||||
//Console.WriteLine("Source,Target" + source + " " + target);
|
||||
while (route.Parent != null)
|
||||
{
|
||||
//Console.Write(route.Id+" ");
|
||||
for (int neighb = 1; neighb <= degList[route.Id]; neighb++)
|
||||
if (eList[route.Id, neighb].NodeId == route.Parent.Id)
|
||||
{
|
||||
|
||||
Edgelist.Add(new VertexNeighbor(route.Id, neighb));
|
||||
|
||||
Distance += Math.Sqrt((route.XLoc - route.Parent.XLoc) * (route.XLoc - route.Parent.XLoc) + (route.YLoc - route.Parent.YLoc) * (route.YLoc - route.Parent.YLoc));
|
||||
|
||||
break;
|
||||
}
|
||||
for (int neighb = 1; neighb <= degList[route.Parent.Id]; neighb++)
|
||||
if (eList[route.Parent.Id, neighb].NodeId == route.Id)
|
||||
{
|
||||
|
||||
Edgelist.Add(new VertexNeighbor(route.Parent.Id, neighb));
|
||||
|
||||
break;
|
||||
}
|
||||
route = route.Parent;
|
||||
}
|
||||
//Console.Write(route.Id + " ");
|
||||
if (route.Id != vList[source].Id) Console.WriteLine("path not found");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public List<int> MSAGLAstarShortestPath(Vertex[] vList, Edge[,] eList, int[] degList, int source, int target, int n)
|
||||
{
|
||||
|
||||
var q = new BinaryHeapPriorityQueue(n);
|
||||
|
||||
|
||||
vList[source].Dist = 0;
|
||||
vList[source].Weight = vList[source].Dist +
|
||||
MsaglUtilities.EucledianDistance(
|
||||
vList[source].XLoc, vList[source].YLoc,
|
||||
vList[target].XLoc, vList[target].YLoc);
|
||||
q.Enqueue(source, vList[source].Weight);
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (vList[i].Id != source)
|
||||
{
|
||||
vList[i].Dist = double.MaxValue;
|
||||
vList[i].Weight = double.MaxValue;
|
||||
q.Enqueue(i, vList[i].Weight);
|
||||
}
|
||||
vList[i].Parent = null;
|
||||
vList[i].Visited = false;
|
||||
}
|
||||
|
||||
Edgelist.Clear();
|
||||
ShortestPath.Clear();
|
||||
Distance = 0;
|
||||
|
||||
while (q.Count > 0)
|
||||
{
|
||||
var deq = q.Dequeue();
|
||||
Vertex u = vList[deq];
|
||||
u.Visited = true;
|
||||
if (u == null || u.Invalid) return new List<int>();
|
||||
for (int neighb = 0; neighb < degList[u.Id]; neighb++)
|
||||
{
|
||||
var neighborId = eList[u.Id, neighb].NodeId;
|
||||
int discourage = 0;
|
||||
if (eList[u.Id, neighb].Selected == 1) discourage = 1000;//continue;
|
||||
if (eList[u.Id, neighb].NodeId == source || eList[u.Id, neighb].NodeId == target) discourage = 0;
|
||||
if (u.Id == source || u.Id == target) discourage = 0;
|
||||
|
||||
Vertex neighbor = vList[neighborId];
|
||||
double edist = MsaglUtilities.EucledianDistance(u.XLoc, u.YLoc, neighbor.XLoc, neighbor.YLoc);
|
||||
var tempDist = u.Dist + edist + discourage;
|
||||
if (tempDist >= neighbor.Dist) continue;
|
||||
|
||||
neighbor.Dist = tempDist;
|
||||
var tempWeight = neighbor.Dist + MsaglUtilities.EucledianDistance(vList[target].XLoc, vList[target].YLoc, neighbor.XLoc, neighbor.YLoc);
|
||||
neighbor.Weight = tempWeight;
|
||||
neighbor.Parent = u;
|
||||
if (neighbor.Visited)
|
||||
{
|
||||
neighbor.Visited = false;
|
||||
q.Enqueue(neighbor.Id, neighbor.Weight);
|
||||
}
|
||||
else q.DecreasePriority(neighbor.Id, neighbor.Weight);
|
||||
}
|
||||
if (u.Id == target)
|
||||
break;
|
||||
}
|
||||
|
||||
Vertex route = vList[target];
|
||||
int zoomlevel = Math.Max(vList[source].ZoomLevel, vList[target].ZoomLevel);
|
||||
while (route.Parent != null)
|
||||
{
|
||||
ShortestPath.Add(route.Id);
|
||||
for (int neighb = 0; neighb < degList[route.Id]; neighb++)
|
||||
if (eList[route.Id, neighb].NodeId == route.Parent.Id)
|
||||
{
|
||||
SetUsed(vList, eList, degList, route.Id, eList[route.Id, neighb].NodeId, zoomlevel);
|
||||
Edgelist.Add(new VertexNeighbor(route.Id, neighb));
|
||||
|
||||
Distance += Math.Sqrt((route.XLoc - route.Parent.XLoc) * (route.XLoc - route.Parent.XLoc) + (route.YLoc - route.Parent.YLoc) * (route.YLoc - route.Parent.YLoc));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
route = route.Parent;
|
||||
}
|
||||
ShortestPath.Add(route.Id);
|
||||
if (route.Id != source) Console.WriteLine("path not found");
|
||||
return ShortestPath;
|
||||
}
|
||||
|
||||
|
||||
public void MSAGLGreedy(Vertex[] vList, Edge[,] eList, int[] degList, int source, int target, int n)
|
||||
{
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
vList[i].Parent = null;
|
||||
vList[i].Visited = false;
|
||||
}
|
||||
|
||||
Edgelist.Clear();
|
||||
ShortestPath.Clear();
|
||||
Distance = 0;
|
||||
|
||||
Vertex currentVertex = vList[source];
|
||||
int bestN;
|
||||
double bestD, temp, discourage=0;
|
||||
while (true)
|
||||
{
|
||||
if (currentVertex == null || currentVertex.Invalid) return;
|
||||
currentVertex.Visited = true;
|
||||
bestD = Double.MaxValue;
|
||||
bestN = -1;
|
||||
for (int neighb = 0; neighb < degList[currentVertex.Id]; neighb++)
|
||||
{
|
||||
var neighbor = eList[currentVertex.Id, neighb].NodeId;
|
||||
if (vList[neighbor].Visited) continue;
|
||||
if (eList[currentVertex.Id, neighb].Selected == 1) discourage = 1000; //continue;
|
||||
else discourage = 0;
|
||||
temp = MsaglUtilities.EucledianDistance(vList[neighbor].XLoc, vList[neighbor].YLoc,
|
||||
vList[target].XLoc, vList[target].YLoc) + discourage;
|
||||
if (temp < bestD)
|
||||
{
|
||||
bestD = temp;
|
||||
bestN = neighbor;
|
||||
}
|
||||
|
||||
}
|
||||
if (currentVertex.Id == target)
|
||||
break;
|
||||
if (bestN == -1)
|
||||
{
|
||||
MSAGLAstarShortestPath(vList, eList, degList, source, target, n);
|
||||
//Console.Write('*');
|
||||
return;
|
||||
}
|
||||
vList[bestN].Parent = currentVertex;
|
||||
currentVertex = vList[bestN];
|
||||
}
|
||||
|
||||
Vertex route = vList[target];
|
||||
int zoomlevel = Math.Max(vList[source].ZoomLevel, vList[target].ZoomLevel);
|
||||
while (route.Parent != null)
|
||||
{
|
||||
ShortestPath.Add(route.Id);
|
||||
for (int neighb = 0; neighb < degList[route.Id]; neighb++)
|
||||
if (eList[route.Id, neighb].NodeId == route.Parent.Id)
|
||||
{
|
||||
SetUsed(vList, eList, degList, route.Id, eList[route.Id, neighb].NodeId, zoomlevel);
|
||||
Edgelist.Add(new VertexNeighbor(route.Id, neighb));
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
route = route.Parent;
|
||||
}
|
||||
ShortestPath.Add(route.Id);
|
||||
if (route.Id != source) Console.WriteLine("path not found");
|
||||
return;
|
||||
}
|
||||
|
||||
public void MSAGLAstarSSSP(Vertex[] vList, Edge[,] eList, int[] degList, int source, Dictionary<Node, int> nodeId, GeometryGraph _mainGeometryGraph,
|
||||
int NofNodesBeforeDetour, int n, Tiling g, Tiling g1)
|
||||
{
|
||||
|
||||
var q = new BinaryHeapPriorityQueue(n);
|
||||
|
||||
|
||||
|
||||
vList[source].Dist = 0;
|
||||
q.Enqueue(source, vList[source].Dist);
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (vList[i].Id != source)
|
||||
{
|
||||
vList[i].Dist = double.MaxValue;
|
||||
q.Enqueue(i, vList[i].Dist);
|
||||
}
|
||||
vList[i].Parent = null;
|
||||
vList[i].Visited = false;
|
||||
}
|
||||
|
||||
|
||||
Distance = 0;
|
||||
|
||||
while (q.Count > 0)
|
||||
{
|
||||
var deq = q.Dequeue();
|
||||
Vertex u = vList[deq];
|
||||
u.Visited = true;
|
||||
if (u == null || u.Invalid) return;
|
||||
for (int neighb = 0; neighb < degList[u.Id]; neighb++)
|
||||
{
|
||||
|
||||
var neighborId = eList[u.Id, neighb].NodeId;
|
||||
int discourage = 0;
|
||||
|
||||
if (u.Id < NofNodesBeforeDetour && u.Id != source) discourage = 1000;
|
||||
|
||||
Vertex neighbor = vList[neighborId];
|
||||
double edist = MsaglUtilities.EucledianDistance(u.XLoc, u.YLoc, neighbor.XLoc, neighbor.YLoc);
|
||||
var tempDist = u.Dist + edist + discourage;
|
||||
if (tempDist >= neighbor.Dist) continue;
|
||||
|
||||
neighbor.Dist = tempDist;
|
||||
neighbor.Parent = u;
|
||||
if (neighbor.Visited)
|
||||
{
|
||||
neighbor.Visited = false;
|
||||
q.Enqueue(neighbor.Id, neighbor.Dist);
|
||||
}
|
||||
else q.DecreasePriority(neighbor.Id, neighbor.Dist);
|
||||
}
|
||||
}
|
||||
foreach (var node in _mainGeometryGraph.Nodes)
|
||||
{
|
||||
int target = nodeId[node];
|
||||
if (target == source) continue;
|
||||
Vertex route = vList[target];
|
||||
int zoomlevel = Math.Max(vList[source].ZoomLevel, vList[target].ZoomLevel);
|
||||
Edgelist.Clear();
|
||||
while (route.Parent != null)
|
||||
{
|
||||
ShortestPath.Add(route.Id);
|
||||
for (int neighb = 0; neighb < degList[route.Id]; neighb++)
|
||||
if (eList[route.Id, neighb].NodeId == route.Parent.Id)
|
||||
{
|
||||
SetUsed(vList, eList, degList, route.Id, eList[route.Id, neighb].NodeId, zoomlevel);
|
||||
Edgelist.Add(new VertexNeighbor(route.Id, neighb));
|
||||
break;
|
||||
}
|
||||
|
||||
route = route.Parent;
|
||||
}
|
||||
if (route.Id != source) Console.WriteLine("path not found");
|
||||
foreach (VertexNeighbor vn in Edgelist)
|
||||
g1.AddEdge(vn.A, g.EList[vn.A, vn.Neighbor].NodeId, g.EList[vn.A, vn.Neighbor].Selected, g.EList[vn.A, vn.Neighbor].Used);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public void MSAGLSelectShortestPath(Vertex[] vList, Edge[,] eList, int[] degList, int source, int target, int n)
|
||||
{
|
||||
|
||||
List<Vertex> q = new List<Vertex>();
|
||||
vList[source].Dist = 0;
|
||||
q.Add(vList[source]);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (vList[i].Id != source)
|
||||
{
|
||||
vList[i].Dist = double.MaxValue;
|
||||
q.Add(vList[i]);
|
||||
}
|
||||
vList[i].Parent = null;
|
||||
vList[i].Visited = false;
|
||||
}
|
||||
|
||||
Edgelist.Clear();
|
||||
Distance = 0;
|
||||
|
||||
while (q.Count > 0)
|
||||
{
|
||||
Vertex u = getMin(q);
|
||||
if (u == null) return;
|
||||
if (u.Visited) continue;
|
||||
else u.Visited = true;
|
||||
for (int neighb = 0; neighb < degList[u.Id]; neighb++)
|
||||
{
|
||||
var neighbor = eList[u.Id, neighb].NodeId;
|
||||
if (vList[neighbor].Visited) continue;
|
||||
int discourage = 0;
|
||||
if (eList[u.Id, neighb].Selected == 1) discourage = 1000;//continue;
|
||||
if (eList[u.Id, neighb].NodeId == source || eList[u.Id, neighb].NodeId == target) discourage = 0;
|
||||
if (u.Id == source || u.Id == target) discourage = 0;
|
||||
|
||||
|
||||
var temp = u.Dist + eList[u.Id, neighb].GetEDist(vList, u.Id, eList[u.Id, neighb].NodeId) + discourage;
|
||||
|
||||
if (temp < vList[neighbor].Dist)
|
||||
{
|
||||
vList[neighbor].Dist = temp;
|
||||
vList[neighbor].Parent = u;
|
||||
//Update(q, vList[neighbor]);
|
||||
}
|
||||
}
|
||||
if (u.Id == target)
|
||||
break;
|
||||
}
|
||||
|
||||
Vertex route = vList[target];
|
||||
|
||||
//Console.WriteLine();
|
||||
//Console.WriteLine("Source,Target" + source + " " + target);
|
||||
while (route.Parent != null)
|
||||
{
|
||||
//Console.Write(route.Id+" ");
|
||||
for (int neighb = 0; neighb < degList[route.Id]; neighb++)
|
||||
if (eList[route.Id, neighb].NodeId == route.Parent.Id)
|
||||
{
|
||||
SetUsed(vList, eList, degList, route.Id, eList[route.Id, neighb].NodeId, 1);
|
||||
Edgelist.Add(new VertexNeighbor(route.Id, neighb));
|
||||
|
||||
Distance += Math.Sqrt((route.XLoc - route.Parent.XLoc) * (route.XLoc - route.Parent.XLoc) + (route.YLoc - route.Parent.YLoc) * (route.YLoc - route.Parent.YLoc));
|
||||
|
||||
break;
|
||||
}
|
||||
/*
|
||||
for (int neighb = 0; neighb < degList[route.Parent.Id]; neighb++)
|
||||
if (eList[route.Parent.Id, neighb].NodeId == route.Id)
|
||||
{
|
||||
SetUsed(vList, eList, degList, route.Parent.Id, eList[route.Parent.Id, neighb].NodeId);
|
||||
Edgelist.Add(new VertexNeighbor(route.Parent.Id, neighb));
|
||||
|
||||
break;
|
||||
}
|
||||
* */
|
||||
route = route.Parent;
|
||||
}
|
||||
//Console.Write(route.Id + " ");
|
||||
if (route.Id != source) Console.WriteLine("path not found");
|
||||
|
||||
}
|
||||
|
||||
public void SetUsed(Vertex[] vList, Edge[,] eList, int[] degList, int a, int b, int zoomlevel)
|
||||
{
|
||||
for (int index = 0; index < degList[a]; index++)
|
||||
{
|
||||
if (eList[a, index].NodeId == b)
|
||||
{
|
||||
if (eList[a, index].Used > 0) return;
|
||||
else eList[a, index].Used = zoomlevel;
|
||||
}
|
||||
}
|
||||
for (int index = 0; index < degList[b]; index++)
|
||||
{
|
||||
if (eList[b, index].NodeId == a)
|
||||
{
|
||||
if (eList[b, index].Used > 0) return;
|
||||
else eList[b, index].Used = zoomlevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
public void SelectShortestPath(Vertex [] vList, Edge [,] eList, int [] degList, int source, int target,int n){
|
||||
|
||||
|
||||
PriorityQueue<double, Vertex> q = new PriorityQueue<double, Vertex>();
|
||||
vList[source].Dist = 0;
|
||||
q.Enqueue(vList[source].Dist, vList[source]);
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
if ( vList[i].Id != vList[source].Id)
|
||||
{
|
||||
vList[i].Dist = double.MaxValue;
|
||||
q.Enqueue(vList[i].Dist, vList[i]);
|
||||
}
|
||||
vList[i].Parent = null;
|
||||
vList[i].Visited = false;
|
||||
}
|
||||
|
||||
Edgelist.Clear();
|
||||
Distance = 0;
|
||||
|
||||
while (q.Count > 0)
|
||||
{
|
||||
Vertex u = q.Dequeue().Value;
|
||||
if (u.Visited) continue;
|
||||
else u.Visited = true;
|
||||
for (int neighb = 1; neighb <= degList[u.Id]; neighb++)
|
||||
{
|
||||
var neighbor = eList[u.Id,neighb].NodeId;
|
||||
|
||||
int discourage = 0;
|
||||
if (eList[u.Id, neighb].Selected == 0) discourage = 10000;//continue;
|
||||
if (vList[eList[u.Id, neighb].NodeId].Weight> 0 &&
|
||||
eList[u.Id, neighb].NodeId != target) continue;
|
||||
|
||||
|
||||
var temp = u.Dist + eList[u.Id, neighb].getEDist(vList, u.Id, eList[u.Id, neighb].NodeId) + discourage;
|
||||
|
||||
if (temp < vList[neighbor].Dist)
|
||||
{
|
||||
vList[neighbor].Dist = temp;
|
||||
vList[neighbor].Parent = u;
|
||||
q.Enqueue(vList[neighbor].Dist, vList[neighbor]);
|
||||
}
|
||||
}
|
||||
if (u.Id ==vList[target].Id)
|
||||
break;
|
||||
}
|
||||
|
||||
Vertex route = vList[target];
|
||||
|
||||
while (route.Parent != null)
|
||||
{
|
||||
for (int neighb = 1; neighb <= degList[route.Id]; neighb++)
|
||||
if (eList[route.Id, neighb].NodeId == route.Parent.Id){
|
||||
//eList[route.ID, neighb].selected = 1;
|
||||
|
||||
Edgelist.Add(new VertexNeighbor(route.Id, neighb));
|
||||
|
||||
Distance += Math.Sqrt((route.XLoc - route.Parent.XLoc) * (route.XLoc - route.Parent.XLoc) + (route.YLoc - route.Parent.YLoc) * (route.YLoc - route.Parent.YLoc));
|
||||
|
||||
//encourage reusing of path by decreasing weight
|
||||
//if (eList[route.ID, neighb].weight == 1) eList[route.ID, neighb].weight /= 2;
|
||||
break;
|
||||
}
|
||||
for (int neighb = 1; neighb <= degList[route.Parent.Id]; neighb++)
|
||||
if (eList[route.Parent.Id, neighb].NodeId == route.Id)
|
||||
{
|
||||
//eList[route.parent.ID, neighb].selected = 1;
|
||||
|
||||
Edgelist.Add(new VertexNeighbor(route.Parent.Id, neighb));
|
||||
|
||||
//encourage reusing of path by decreasing weight
|
||||
//if (eList[route.parent.ID, neighb].weight == 1) eList[route.parent.ID, neighb].weight /= 2;
|
||||
break;
|
||||
}
|
||||
route = route.Parent;
|
||||
}
|
||||
if(route.Id != source) Console.WriteLine("path not found");
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
public class VertexNeighbor
|
||||
{
|
||||
public int A;
|
||||
public int Neighbor;
|
||||
public VertexNeighbor(int p, int q)
|
||||
{
|
||||
A = p; Neighbor = q;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/DijkstraAlgo.cs.meta
Normal file
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/DijkstraAlgo.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c320d98fb65975042a12a18532379af8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
356
Assets/Plugins/MSAGL/GraphmapsWithMesh/LocalModifications.cs
Normal file
356
Assets/Plugins/MSAGL/GraphmapsWithMesh/LocalModifications.cs
Normal file
|
|
@ -0,0 +1,356 @@
|
|||
using System;
|
||||
using System.CodeDom;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Msagl.Core.Layout;
|
||||
using Microsoft.Msagl.Layout.LargeGraphLayout;
|
||||
|
||||
namespace Microsoft.Msagl.GraphmapsWithMesh
|
||||
{
|
||||
class LocalModifications
|
||||
{
|
||||
|
||||
public static void MsaglShortcutShortEdges(Tiling g, Dictionary<int, Node> idToNodes,
|
||||
LgLayoutSettings _lgLayoutSettings)
|
||||
{
|
||||
int unit = (int)_lgLayoutSettings.NodeSeparation;
|
||||
|
||||
int shortcutcount = 1;
|
||||
int iteration = 10;
|
||||
|
||||
//Console.WriteLine();
|
||||
//Console.WriteLine("Minimize the number of railes for quick interaction? (Y/N)");
|
||||
//string input = Console.ReadLine();
|
||||
if (_lgLayoutSettings.hugeGraph)
|
||||
{
|
||||
iteration = 1;
|
||||
unit *= 5;
|
||||
}
|
||||
|
||||
while (shortcutcount > 0 && iteration > 0)
|
||||
{
|
||||
iteration--;
|
||||
//for all vertices that are not real vertices
|
||||
for (int index = g.N; index < g.NumOfnodesBeforeDetour; index++)
|
||||
{
|
||||
//current vertex is w
|
||||
Vertex w = g.VList[index];
|
||||
|
||||
//for each neighbor of w
|
||||
for (int k = 0; k < g.DegList[w.Id]; k++)
|
||||
{
|
||||
Vertex neighbor = g.VList[g.EList[w.Id, k].NodeId];
|
||||
|
||||
//if neighbor is a real vertex then continue
|
||||
if (neighbor.Id < g.N) continue;
|
||||
|
||||
//else check whether the edge is short
|
||||
double l = g.GetEucledianDist(w.Id, neighbor.Id);
|
||||
|
||||
//if the length is short engough then short-cut
|
||||
if (l < unit)
|
||||
{
|
||||
//shortcut this edge
|
||||
//take all the neighbors of the 'neighbor' into the modification list
|
||||
List<int> modificationList = new List<int>();
|
||||
for (int j = 0; j < g.DegList[neighbor.Id]; j++)
|
||||
{
|
||||
int id = g.EList[neighbor.Id, j].NodeId;
|
||||
|
||||
if (id != w.Id)
|
||||
{
|
||||
modificationList.Add(id);
|
||||
}
|
||||
}
|
||||
//check whether it is safe to modify the graph
|
||||
bool safetomodify = true;
|
||||
if (g.DegList[w.Id] + modificationList.Count >= g.maxDeg) continue;
|
||||
foreach (var x in modificationList)
|
||||
if (g.DegList[x] + 1 >= g.maxDeg)
|
||||
safetomodify = false;
|
||||
|
||||
foreach (var x in modificationList)
|
||||
{
|
||||
if (g.Crossings(w.Id, x))
|
||||
safetomodify = false;
|
||||
}
|
||||
|
||||
if (!safetomodify) continue;
|
||||
|
||||
//add edges between w and the neighbor's neighbor
|
||||
foreach (var x in modificationList)
|
||||
{
|
||||
g.AddEdge(w.Id, x);
|
||||
}
|
||||
|
||||
g.RemoveEdge(w.Id, neighbor.Id);
|
||||
shortcutcount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
unit *= 2;
|
||||
}
|
||||
Console.WriteLine("Shortcut made for " + shortcutcount + " edges");
|
||||
}
|
||||
|
||||
public static void MsaglMoveToMedian(Tiling g, Dictionary<int, Node> idToNodes, LgLayoutSettings _lgLayoutSettings)
|
||||
{
|
||||
|
||||
//foreach point first produce the crossing candidates.
|
||||
g.buildCrossingCandidates();
|
||||
|
||||
|
||||
//now proceess the movement
|
||||
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=340
|
||||
int[,] listNeighbors = null;
|
||||
throw new InvalidOperationException();
|
||||
#else
|
||||
int[,] listNeighbors = new int[20, 3];
|
||||
#endif
|
||||
double[] d = new double[10];
|
||||
int a = 0, b = 0;
|
||||
Core.Geometry.Point[] p = new Core.Geometry.Point[10];
|
||||
bool localRefinementsFound = true;
|
||||
int iteration = 10;
|
||||
//int offset = iteration * 2;
|
||||
int unit = (int)_lgLayoutSettings.NodeSeparation / 2;
|
||||
|
||||
if (_lgLayoutSettings.hugeGraph)
|
||||
{
|
||||
iteration = 3;
|
||||
unit = (int)_lgLayoutSettings.NodeSeparation;
|
||||
}
|
||||
|
||||
while (localRefinementsFound && iteration > 0)
|
||||
{
|
||||
iteration--;
|
||||
localRefinementsFound = false;
|
||||
|
||||
|
||||
for (int index = g.N; index < g.NumOfnodesBeforeDetour; index++)
|
||||
{
|
||||
Vertex w = g.VList[index];
|
||||
|
||||
int numNeighbors = 0;
|
||||
|
||||
for (int k = 0; k < g.DegList[w.Id]; k++)
|
||||
{
|
||||
numNeighbors++;
|
||||
listNeighbors[numNeighbors, 1] = g.EList[w.Id, k].NodeId;
|
||||
listNeighbors[numNeighbors, 2] = k;
|
||||
}
|
||||
|
||||
if (numNeighbors <= 1) continue;
|
||||
|
||||
for (int counter = 1; counter <= 9; counter++)
|
||||
{
|
||||
d[counter] = 0;
|
||||
|
||||
if (counter == 1) { a = unit; b = unit; }
|
||||
if (counter == 2) { a = 0; b = unit; }
|
||||
if (counter == 3) { a = -unit; b = unit; }
|
||||
if (counter == 4) { a = -unit; b = 0; }
|
||||
if (counter == 5) { a = -unit; b = -unit; }
|
||||
if (counter == 6) { a = 0; b = -unit; }
|
||||
if (counter == 7) { a = unit; b = -unit; }
|
||||
if (counter == 8) { a = unit; b = 0; }
|
||||
if (counter == 9) { a = 0; b = 0; }
|
||||
|
||||
|
||||
for (int k = 1; k <= numNeighbors; k++)
|
||||
{
|
||||
double length = Math.Sqrt((w.XLoc + a - g.VList[listNeighbors[k, 1]].XLoc) *
|
||||
(w.XLoc + a - g.VList[listNeighbors[k, 1]].XLoc)
|
||||
+
|
||||
(w.YLoc + b - g.VList[listNeighbors[k, 1]].YLoc) *
|
||||
(w.YLoc + b - g.VList[listNeighbors[k, 1]].YLoc)
|
||||
);
|
||||
if (length < 1)
|
||||
{
|
||||
length = 1000;
|
||||
}
|
||||
|
||||
|
||||
d[counter] += length;
|
||||
|
||||
}
|
||||
|
||||
|
||||
p[counter] = new Core.Geometry.Point(a, b);
|
||||
|
||||
|
||||
}
|
||||
Array.Sort(d, p);
|
||||
|
||||
for (int counter = 1; counter <= 9; counter++)
|
||||
{
|
||||
var mincostA = (int)p[counter].X;
|
||||
var mincostB = (int)p[counter].Y;
|
||||
|
||||
if (!(mincostA == 0 && mincostB == 0))
|
||||
{
|
||||
w.XLoc += mincostA;
|
||||
w.YLoc += mincostB;
|
||||
if (g.GetNodeExceptTheGivenNode(w, w.XLoc, w.YLoc, 5) >= 0 ||
|
||||
g.MsaglGoodResolution(w, listNeighbors, numNeighbors, 5) == false
|
||||
|| g.noCrossingsHeuristics(w, index) == false
|
||||
)
|
||||
{
|
||||
w.XLoc -= mincostA;
|
||||
w.YLoc -= mincostB;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Console.Write(".");
|
||||
localRefinementsFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Done");
|
||||
}
|
||||
|
||||
|
||||
public static void MsaglStretchAccordingToZoomLevel(Tiling g, Dictionary<int, Node> idToNodes)
|
||||
{
|
||||
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=340
|
||||
throw new InvalidOperationException();
|
||||
#else
|
||||
int[,] listNeighbors = new int[20, 3];
|
||||
double[] d = new double[10];
|
||||
int[] a = new int[10];
|
||||
int[] b = new int[10];
|
||||
Core.Geometry.Point[] p = new Core.Geometry.Point[10];
|
||||
bool localRefinementsFound = true;
|
||||
int iteration = 8;
|
||||
int offset = iteration * 2;
|
||||
|
||||
a[1] = 1; b[1] = 1; a[2] = 0; b[2] = 1; a[3] = -1; b[3] = 1; a[4] = -1; b[4] = 0;
|
||||
a[5] = -1; b[5] = -1; a[6] = 0; b[6] = -1; a[7] = 1; b[7] = -1; a[8] = 1; b[8] = 0; a[9] = 0; b[9] = 0;
|
||||
|
||||
while (localRefinementsFound && iteration > 0)
|
||||
{
|
||||
iteration--;
|
||||
localRefinementsFound = false;
|
||||
|
||||
|
||||
for (int index = g.N; index < g.NumOfnodesBeforeDetour; index++)
|
||||
{
|
||||
Vertex w = g.VList[index];
|
||||
|
||||
int numNeighbors = 0;
|
||||
|
||||
for (int k = 0; k < g.DegList[w.Id]; k++)
|
||||
{
|
||||
if (g.EList[w.Id, k].Used == 0) continue;
|
||||
numNeighbors++;
|
||||
listNeighbors[numNeighbors, 1] = g.EList[w.Id, k].NodeId;
|
||||
listNeighbors[numNeighbors, 2] = k;
|
||||
}
|
||||
|
||||
if (numNeighbors <= 1) continue;
|
||||
|
||||
//compute the lowest zoom level among incident rails
|
||||
var lowestZoomLevel = int.MaxValue;
|
||||
for (int index2 = 1; index2 <= numNeighbors; index2++)
|
||||
if (g.EList[index, listNeighbors[index2, 2]].Used < lowestZoomLevel)
|
||||
lowestZoomLevel = g.EList[index, listNeighbors[index2, 2]].Used;
|
||||
|
||||
//for each possible move
|
||||
for (int counter = 1; counter <= 9; counter++)
|
||||
{
|
||||
d[counter] = 0;
|
||||
//find the ink cost of that move
|
||||
for (int k = 1; k <= numNeighbors; k++)
|
||||
{
|
||||
//try to stretch the high priority rails
|
||||
if (g.EList[index, listNeighbors[k, 2]].Used != lowestZoomLevel) continue;
|
||||
double length = Math.Sqrt((w.XLoc + a[counter] - g.VList[listNeighbors[k, 1]].XLoc) *
|
||||
(w.XLoc + a[counter] - g.VList[listNeighbors[k, 1]].XLoc)
|
||||
+
|
||||
(w.YLoc + b[counter] - g.VList[listNeighbors[k, 1]].YLoc) *
|
||||
(w.YLoc + b[counter] - g.VList[listNeighbors[k, 1]].YLoc)
|
||||
);
|
||||
if (length < .5) length = 1000;
|
||||
|
||||
d[counter] += length;
|
||||
|
||||
}
|
||||
|
||||
p[counter] = new Core.Geometry.Point(a[counter], b[counter]);
|
||||
|
||||
|
||||
}
|
||||
Array.Sort(d, p);
|
||||
|
||||
for (int counter = 1; counter <= 9; counter++)
|
||||
{
|
||||
var mincostA = (int)p[counter].X;
|
||||
var mincostB = (int)p[counter].Y;
|
||||
|
||||
if (!(mincostA == 0 && mincostB == 0))
|
||||
{
|
||||
w.XLoc += mincostA;
|
||||
w.YLoc += mincostB;
|
||||
if (g.GetNodeExceptTheGivenNode(w, w.XLoc, w.YLoc, offset) >= 0 ||
|
||||
g.MsaglGoodResolution(w, listNeighbors, numNeighbors, offset) == false
|
||||
//||g.noCrossings(w) == false
|
||||
)
|
||||
{
|
||||
w.XLoc -= mincostA;
|
||||
w.YLoc -= mincostB;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Console.Write(".");
|
||||
localRefinementsFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Done");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*Douglas-Peucker line simplification algorithm
|
||||
* INPUT: A set of points P in sequence and a tolerance value
|
||||
* OUTPUT: A simplified chain after removing some of the points from P
|
||||
*/
|
||||
public static void PolygonalChainSimplification(Microsoft.Msagl.Core.Geometry.Point[] PointList, int start, int end, double epsilon)
|
||||
{
|
||||
|
||||
// Find the point with the maximum distance
|
||||
double dmax = 0, d = 0;
|
||||
int index = 0;
|
||||
for (int i = start + 1; i <= end - 1; i++)
|
||||
{
|
||||
d = PointToSegmentDistance.GetDistance(PointList[start], PointList[end], PointList[i]);
|
||||
if (d > dmax)
|
||||
{
|
||||
index = i;
|
||||
dmax = d;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If max distance is greater than epsilon, recursively simplify
|
||||
if (dmax > epsilon)
|
||||
{
|
||||
// Recursive call
|
||||
PolygonalChainSimplification(PointList, start, index, epsilon);
|
||||
PolygonalChainSimplification(PointList, index, end, epsilon);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = start + 1; i <= end - 1; i++)
|
||||
PointList[i] = new Core.Geometry.Point(-1, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c446e34feb39ac049a8aa41b421734ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1730
Assets/Plugins/MSAGL/GraphmapsWithMesh/MeshCreator.cs
Normal file
1730
Assets/Plugins/MSAGL/GraphmapsWithMesh/MeshCreator.cs
Normal file
File diff suppressed because it is too large
Load diff
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/MeshCreator.cs.meta
Normal file
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/MeshCreator.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0cd98634e55304549a5994c27dc1bbf9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Plugins/MSAGL/GraphmapsWithMesh/MeshGraph.cs
Normal file
19
Assets/Plugins/MSAGL/GraphmapsWithMesh/MeshGraph.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Msagl.Core.Geometry;
|
||||
using Microsoft.Msagl.Core.Geometry.Curves;
|
||||
using Microsoft.Msagl.Core.Layout;
|
||||
|
||||
namespace Microsoft.Msagl.GraphmapsWithMesh
|
||||
{
|
||||
/*
|
||||
* This class requires fine tuning, currently it is used exhaustively for computing
|
||||
* orthogonal mesh, but it I was using it previously for routing in uniform grid. Therefore
|
||||
* we need to remove lots of variables that we no longer need.
|
||||
*/
|
||||
|
||||
public class MeshGraph
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/MeshGraph.cs.meta
Normal file
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/MeshGraph.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5cb765a3c90ec2f48b91810eb40c0aea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
69
Assets/Plugins/MSAGL/GraphmapsWithMesh/MsaglUtilities.cs
Normal file
69
Assets/Plugins/MSAGL/GraphmapsWithMesh/MsaglUtilities.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
using System;
|
||||
using Microsoft.Msagl.Core.Geometry.Curves;
|
||||
|
||||
namespace Microsoft.Msagl.GraphmapsWithMesh
|
||||
{
|
||||
class MsaglUtilities
|
||||
{
|
||||
public static bool HittedSegmentComesFromLeft(LineSegment hittedSegment, LineSegment hittingSegment)
|
||||
{
|
||||
//going up
|
||||
if (hittingSegment.Start.X == hittingSegment.End.X &&
|
||||
hittingSegment.Start.Y <= hittingSegment.End.Y &&
|
||||
hittedSegment.End.X <= hittedSegment.Start.X) return true;
|
||||
//going left
|
||||
if (hittingSegment.Start.Y == hittingSegment.End.Y &&
|
||||
hittingSegment.Start.X >= hittingSegment.End.X &&
|
||||
hittedSegment.End.Y <= hittedSegment.Start.Y) return true;
|
||||
//going down
|
||||
if (hittingSegment.Start.X == hittingSegment.End.X &&
|
||||
hittingSegment.Start.Y >= hittingSegment.End.Y &&
|
||||
hittedSegment.End.X >= hittedSegment.Start.X) return true;
|
||||
//going right
|
||||
if (hittingSegment.Start.Y == hittingSegment.End.Y &&
|
||||
hittingSegment.Start.X <= hittingSegment.End.X &&
|
||||
hittedSegment.End.Y >= hittedSegment.Start.Y) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static bool PointIsOnAxisAlignedSegment(LineSegment l, Core.Geometry.Point p)
|
||||
{
|
||||
if ((int)l.Start.X == (int)l.End.X && (int)l.Start.X == (int)p.X)
|
||||
{
|
||||
if (l.Start.Y < l.End.Y && l.Start.Y <= p.Y && p.Y <= l.End.Y) return true;
|
||||
if (l.Start.Y > l.End.Y && l.Start.Y >= p.Y && p.Y >= l.End.Y) return true;
|
||||
}
|
||||
|
||||
if ((int)l.Start.Y == (int)l.End.Y && (int)l.Start.Y == (int)p.Y)
|
||||
{
|
||||
if (l.Start.X < l.End.X && l.Start.X <= p.X && p.X <= l.End.X) return true;
|
||||
if (l.Start.X > l.End.X && l.Start.X >= p.X && p.X >= l.End.X) return true;
|
||||
}
|
||||
/*
|
||||
double AB = Math.Sqrt((l.Start.X - l.End.X)*(l.Start.X - l.End.X) + (l.Start.Y - l.End.Y)*(l.Start.Y - l.End.Y));
|
||||
double AP = Math.Sqrt((l.Start.X - p.X) * (l.Start.X - p.X) + (l.Start.Y - p.Y) * (l.Start.Y - p.Y));
|
||||
double PB = Math.Sqrt((p.X - l.End.X) * (p.X - l.End.X) + (p.Y - l.End.Y) * (p.Y - l.End.Y));
|
||||
if (AB == AP + PB) return true;*/
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool PointIsOnSegment(LineSegment l, Core.Geometry.Point p)
|
||||
{
|
||||
|
||||
double AB = Math.Sqrt((l.Start.X - l.End.X) * (l.Start.X - l.End.X) + (l.Start.Y - l.End.Y) * (l.Start.Y - l.End.Y));
|
||||
double AP = Math.Sqrt((l.Start.X - p.X) * (l.Start.X - p.X) + (l.Start.Y - p.Y) * (l.Start.Y - p.Y));
|
||||
double PB = Math.Sqrt((p.X - l.End.X) * (p.X - l.End.X) + (p.Y - l.End.Y) * (p.Y - l.End.Y));
|
||||
if (AB < (AP + PB + .0001) && (AP + PB - .0001) < AB) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static double EucledianDistance(double x1, double y1, double x2, double y2)
|
||||
{
|
||||
return Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 82e4b0009ddbae547ba8a668a502bbb4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Assets/Plugins/MSAGL/GraphmapsWithMesh/Network.cs
Normal file
53
Assets/Plugins/MSAGL/GraphmapsWithMesh/Network.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.Msagl.GraphmapsWithMesh
|
||||
{
|
||||
|
||||
public class Network
|
||||
{
|
||||
public List<Twin> Edges = new List<Twin>();
|
||||
public int N;
|
||||
public int E;
|
||||
public int[,] M;
|
||||
|
||||
public Network(int numV, int numE, bool Random)
|
||||
{
|
||||
N = numV;
|
||||
E = numE;
|
||||
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=340
|
||||
throw new InvalidOperationException();
|
||||
#else
|
||||
M = new int[numV + 1, numV + 1];
|
||||
#endif
|
||||
}
|
||||
public Network(int numV, int numE)
|
||||
{
|
||||
N = numV;
|
||||
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=340
|
||||
throw new InvalidOperationException();
|
||||
#else
|
||||
M = new int[numV + 1, numV + 1];
|
||||
#endif
|
||||
int v2;
|
||||
while (E < numE)
|
||||
{
|
||||
Random r = new Random();
|
||||
var v1 = r.Next(1, numV);
|
||||
v2 = r.Next(1, numV);
|
||||
|
||||
if (v1 == v2) continue;
|
||||
var newEdge = Edges.All(x => (v1 != x.A || v2 != x.B) && (v1 != x.B || v2 != x.A));
|
||||
if (newEdge)
|
||||
{
|
||||
E++;
|
||||
Edges.Add(new Twin(v1, v2));
|
||||
M[v1, v2] = 1;
|
||||
M[v2, v1] = 1;
|
||||
}
|
||||
//Console.WriteLine(E);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/Network.cs.meta
Normal file
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/Network.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 99c5a1e7f746b1f488550f874163a225
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
272
Assets/Plugins/MSAGL/GraphmapsWithMesh/PlanarGraphUtilities.cs
Normal file
272
Assets/Plugins/MSAGL/GraphmapsWithMesh/PlanarGraphUtilities.cs
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Msagl.Core.Geometry.Curves;
|
||||
|
||||
namespace Microsoft.Msagl.GraphmapsWithMesh
|
||||
{
|
||||
class PlanarGraphUtilities
|
||||
{
|
||||
/*
|
||||
* input: a geometric straight line planar graph
|
||||
* output: a combinatorial adjacency list of the corresponding planar graph
|
||||
*/
|
||||
|
||||
public static void TransformToGeometricPlanarGraph(Tiling g)
|
||||
{
|
||||
Console.WriteLine("Transforming into a planar graph.");
|
||||
|
||||
for (int nodeIndex = 0; nodeIndex < g.NumOfnodes; nodeIndex++)
|
||||
{
|
||||
var sortedEdgeList = new Edge[g.DegList[nodeIndex]];
|
||||
var clockwiseAngularDistance = new double[g.DegList[nodeIndex]];
|
||||
|
||||
//sort the neighbors according to the clockwise angular distance
|
||||
for (int neighborIndex = 0; neighborIndex < g.DegList[nodeIndex]; neighborIndex++)
|
||||
{
|
||||
sortedEdgeList[neighborIndex] = g.EList[nodeIndex, neighborIndex];
|
||||
Vertex apex = g.VList[nodeIndex];
|
||||
Vertex referrence = g.VList[g.EList[nodeIndex, 0].NodeId];
|
||||
Vertex current = g.VList[g.EList[nodeIndex, neighborIndex].NodeId];
|
||||
clockwiseAngularDistance[neighborIndex] = Angle.getClockwiseAngle(apex, referrence, current);
|
||||
}
|
||||
Array.Sort(clockwiseAngularDistance, sortedEdgeList);
|
||||
for (int neighborIndex = 0; neighborIndex < g.DegList[nodeIndex]; neighborIndex++)
|
||||
g.EList[nodeIndex, neighborIndex] = sortedEdgeList[neighborIndex];
|
||||
}
|
||||
g.isPlanar = true;
|
||||
|
||||
for (int nodeIndex = 0; nodeIndex < g.NumOfnodes; nodeIndex++)
|
||||
{
|
||||
for (int neighborIndex = 0; neighborIndex < g.DegList[nodeIndex]; neighborIndex++)
|
||||
{
|
||||
int neighbor = g.EList[nodeIndex, neighborIndex].NodeId;
|
||||
bool consistent = false;
|
||||
for (int neighborIndex2 = 0; neighborIndex2 < g.DegList[neighbor]; neighborIndex2++)
|
||||
if (g.EList[neighbor, neighborIndex2].NodeId == nodeIndex) consistent = true;
|
||||
|
||||
if (!consistent)
|
||||
Console.WriteLine("Beware! Graph is Not Consistent!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* input: a planar graph and an edge a<---b
|
||||
* output: c, the neighbor next to b around a in anticlockwise order
|
||||
*/
|
||||
public static int GetAnticlockwiseNextNeighbor(Tiling planarGraph, int currentVertexId, int neighborVertexId)
|
||||
{
|
||||
|
||||
int nextNeighborId = -1;
|
||||
|
||||
if (planarGraph.isPlanar)
|
||||
{
|
||||
for (int neighborIndex = 0; neighborIndex < planarGraph.DegList[currentVertexId]; neighborIndex++)
|
||||
{
|
||||
if (planarGraph.EList[currentVertexId, neighborIndex].NodeId == neighborVertexId)
|
||||
{
|
||||
nextNeighborId = neighborIndex + 1 < planarGraph.DegList[currentVertexId] ? planarGraph.EList[currentVertexId, neighborIndex + 1].NodeId : planarGraph.EList[currentVertexId, 0].NodeId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nextNeighborId;
|
||||
}
|
||||
|
||||
/*
|
||||
*input: a planar graph and an edge
|
||||
*output: a face that is incident to the right of this edge
|
||||
*/
|
||||
|
||||
public static List<Vertex> GetRightIncidentFace(Tiling gPlanar, Vertex givenTailVertex, Vertex givenHeadVertex, out bool degenerate)
|
||||
{
|
||||
degenerate = false;
|
||||
List<Vertex> face = new List<Vertex>();
|
||||
Vertex currentHead = givenHeadVertex, currentTail = givenTailVertex;
|
||||
|
||||
do
|
||||
{
|
||||
int subsequentVertxId = GetAnticlockwiseNextNeighbor(gPlanar, currentHead.Id, currentTail.Id);
|
||||
currentTail = currentHead;
|
||||
currentHead = gPlanar.VList[subsequentVertxId];
|
||||
if (face.Contains(currentHead)) {
|
||||
degenerate = true;
|
||||
break;
|
||||
}
|
||||
face.Add(currentHead);
|
||||
} while (!(givenTailVertex.Id == currentTail.Id && givenHeadVertex.Id == currentHead.Id));
|
||||
return face;
|
||||
}
|
||||
|
||||
/*
|
||||
* input: A geometric planar graph
|
||||
* output: remove a long edge from each face if the face does not contain any real node
|
||||
*/
|
||||
public static void RemoveLongEdgesFromThinFaces(Tiling gPlanar)
|
||||
{
|
||||
Console.WriteLine("Removing Thin Faces");
|
||||
//bool searchFurther = true;
|
||||
//while (searchFurther)
|
||||
//{
|
||||
//you need to handle face one after another - since you are changing the adjacency list
|
||||
//searchFurther = false;
|
||||
List<Face> faces = new List<Face>();
|
||||
for (int nodeIndex = 0; nodeIndex < gPlanar.NumOfnodes; nodeIndex++)
|
||||
{
|
||||
for (int neighborIndex = 0; neighborIndex < gPlanar.DegList[nodeIndex]; neighborIndex++)
|
||||
{
|
||||
bool degenerate;
|
||||
Vertex tailVertex = gPlanar.VList[nodeIndex];
|
||||
Vertex headVertex = gPlanar.VList[gPlanar.EList[nodeIndex, neighborIndex].NodeId];
|
||||
List<Vertex> boundary = GetRightIncidentFace(gPlanar, tailVertex, headVertex, out degenerate);
|
||||
if (degenerate) continue;// Console.WriteLine("Found a degenerate face!");
|
||||
|
||||
//check whether if all the boundary vertices are junctions
|
||||
if (AllBoundaryVerticesAreJunctions(gPlanar, boundary) == false) continue;
|
||||
|
||||
faces.Add(new Face(boundary));
|
||||
//if (searchFurther) break;
|
||||
}
|
||||
//if (searchFurther) break;
|
||||
}
|
||||
foreach (var face in faces)
|
||||
{
|
||||
//if not a valid boundary continue
|
||||
if (!FaceIsStillValid(gPlanar, face.boundary)) continue;
|
||||
//check whether the face is thin, and if so, find the longest edge in this face and remove it
|
||||
if (GetFacewidth(face.boundary) > gPlanar.thinness) continue;
|
||||
//searchFurther =
|
||||
RemoveLongestEdge(gPlanar, face.boundary);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
public static bool FaceIsStillValid(Tiling g, List<Vertex> boundary)
|
||||
{
|
||||
Vertex[] b = boundary.ToArray();
|
||||
for (int index = 0; index < b.Length; index++)
|
||||
{
|
||||
if (index + 1 == b.Length)
|
||||
{
|
||||
if (g.IsAnEdge(b[index].Id, b[0].Id) == false) return false;
|
||||
continue;
|
||||
}
|
||||
if (g.IsAnEdge(b[index].Id, b[index + 1].Id) == false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public class Face
|
||||
{
|
||||
public List<Vertex> boundary;
|
||||
public Face(List<Vertex> b)
|
||||
{
|
||||
boundary = b;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool AllBoundaryVerticesAreJunctions(Tiling gPlanar, List<Vertex> face)
|
||||
{
|
||||
foreach (Vertex boundaryVertex in face)
|
||||
if (boundaryVertex.Id < gPlanar.N)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static double GetFacewidth(List<Vertex> face)
|
||||
{
|
||||
int index = 0;
|
||||
LineSegment[] segments = new LineSegment[face.Count];
|
||||
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=340
|
||||
throw new InvalidOperationException();
|
||||
#else
|
||||
Vertex[,] segmentVertices = new Vertex[face.Count, 2];
|
||||
Vertex initialVertex = null, oldVertex = null;
|
||||
Core.Geometry.Point u1, u2;
|
||||
foreach (var boundaryVertex in face)
|
||||
{
|
||||
if (oldVertex == null)
|
||||
{
|
||||
initialVertex = oldVertex = boundaryVertex;
|
||||
continue;
|
||||
}
|
||||
u1 = new Core.Geometry.Point(boundaryVertex.XLoc, boundaryVertex.YLoc);
|
||||
u2 = new Core.Geometry.Point(oldVertex.XLoc, oldVertex.YLoc);
|
||||
segmentVertices[index, 0] = boundaryVertex;
|
||||
segmentVertices[index, 1] = oldVertex;
|
||||
segments[index++] = new LineSegment(u1, u2);
|
||||
oldVertex = boundaryVertex;
|
||||
}
|
||||
u1 = new Core.Geometry.Point(oldVertex.XLoc, oldVertex.YLoc);
|
||||
u2 = new Core.Geometry.Point(initialVertex.XLoc, initialVertex.YLoc);
|
||||
segmentVertices[index, 0] = initialVertex;
|
||||
segmentVertices[index, 1] = oldVertex;
|
||||
segments[index] = new LineSegment(u1, u2);
|
||||
|
||||
double facewidth = Double.MaxValue;
|
||||
for (int i = 0; i < face.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < face.Count; j++)
|
||||
{
|
||||
if (i == j) continue;
|
||||
if (segments[i].Start == segments[j].Start || segments[i].End == segments[j].End ||
|
||||
segments[i].End == segments[j].Start || segments[i].Start == segments[j].End) continue;
|
||||
|
||||
double width;
|
||||
width = PointToSegmentDistance.GetDistance(segmentVertices[i, 0], segmentVertices[i, 1],
|
||||
segmentVertices[j, 0]);
|
||||
if (facewidth > width) facewidth = width;
|
||||
width = PointToSegmentDistance.GetDistance(segmentVertices[i, 0], segmentVertices[i, 1],
|
||||
segmentVertices[j, 1]);
|
||||
if (facewidth > width) facewidth = width;
|
||||
width = PointToSegmentDistance.GetDistance(segmentVertices[j, 0], segmentVertices[j, 1],
|
||||
segmentVertices[i, 0]);
|
||||
if (facewidth > width) facewidth = width;
|
||||
width = PointToSegmentDistance.GetDistance(segmentVertices[j, 0], segmentVertices[j, 1],
|
||||
segmentVertices[i, 1]);
|
||||
if (facewidth > width) facewidth = width;
|
||||
|
||||
}
|
||||
}
|
||||
return facewidth;
|
||||
#endif
|
||||
}
|
||||
|
||||
private static bool RemoveLongestEdge(Tiling gPlanar, List<Vertex> face)
|
||||
{
|
||||
|
||||
double longestLength = -1, length;
|
||||
Vertex initialVertex = null, oldVertex = null;
|
||||
Vertex removeA = null, removeB = null;
|
||||
foreach (Vertex boundaryVertex in face)
|
||||
{
|
||||
if (oldVertex == null)
|
||||
{
|
||||
initialVertex = oldVertex = boundaryVertex;
|
||||
continue;
|
||||
}
|
||||
length = gPlanar.GetEucledianDist(boundaryVertex.Id, oldVertex.Id);
|
||||
if (longestLength < length)
|
||||
{
|
||||
removeA = oldVertex;
|
||||
removeB = boundaryVertex;
|
||||
longestLength = length;
|
||||
}
|
||||
oldVertex = boundaryVertex;
|
||||
}
|
||||
length = gPlanar.GetEucledianDist(oldVertex.Id, initialVertex.Id);
|
||||
if (longestLength < length)
|
||||
{
|
||||
removeA = initialVertex;
|
||||
removeB = oldVertex;
|
||||
longestLength = length;
|
||||
}
|
||||
//Console.WriteLine("Removing an edge of length "+ longestLength);
|
||||
//remove the longest edge
|
||||
return gPlanar.RemoveEdge(removeA.Id, removeB.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 33fa2e9ae78aeec4682e354eb0725b2c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
166
Assets/Plugins/MSAGL/GraphmapsWithMesh/PointSet.cs
Normal file
166
Assets/Plugins/MSAGL/GraphmapsWithMesh/PointSet.cs
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
using System;
|
||||
|
||||
namespace Microsoft.Msagl.GraphmapsWithMesh
|
||||
{
|
||||
|
||||
public class PointSet
|
||||
{
|
||||
public int NumPoints;
|
||||
public WeightedPoint[] Pt;
|
||||
public int NumOfLevels;
|
||||
|
||||
int[] _selected;
|
||||
|
||||
public int[,] pointMap;
|
||||
|
||||
|
||||
|
||||
public PointSet(int n)
|
||||
{
|
||||
NumPoints = n;
|
||||
Pt = new WeightedPoint[n];
|
||||
Random r1 = new Random(2);
|
||||
|
||||
|
||||
//generate points in random
|
||||
while (n > 0)
|
||||
{
|
||||
int XLoc = r1.Next(100);
|
||||
int YLoc = r1.Next(100);
|
||||
if (exists(XLoc, YLoc, n)) continue;
|
||||
n--;
|
||||
Pt[n] = new WeightedPoint(XLoc, YLoc, 0);
|
||||
}
|
||||
for (int i = 0; i < NumPoints; i++)
|
||||
{
|
||||
Pt[i].X *= 3;
|
||||
Pt[i].Y *= 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool isVeryClose(int x, int y, int n)
|
||||
{
|
||||
double d;
|
||||
for (int i = NumPoints - 1; i > n; i--)
|
||||
{
|
||||
d = Math.Sqrt((Pt[i].X - x) * (Pt[i].X - x) + (Pt[i].Y - y) * (Pt[i].Y - y));
|
||||
if (d <= 3) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public bool exists(int x, int y, int n)
|
||||
{
|
||||
for (int i = NumPoints - 1; i > n; i--)
|
||||
{
|
||||
if (Pt[i].X == x && Pt[i].Y == y) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public PointSet(int n, Tiling g, int pointsPerLevel)
|
||||
{
|
||||
NumPoints = n;
|
||||
Pt = new WeightedPoint[n + 1];
|
||||
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=340
|
||||
throw new InvalidOperationException();
|
||||
#else
|
||||
pointMap = new int[g.NumOfnodes + 1, g.NumOfnodes + 1];
|
||||
#endif
|
||||
_selected = new int[g.NumOfnodes + 1];
|
||||
Random r1 = new Random();
|
||||
|
||||
//List<int> list = new List<int>();
|
||||
|
||||
//for (int i = 1; i < 255; i++)
|
||||
//{
|
||||
//list.Add(i);
|
||||
//}
|
||||
|
||||
|
||||
//generate points in random
|
||||
while (n > 0)
|
||||
{
|
||||
var temp = r1.Next(1, g.NumOfnodes); //,temp2;
|
||||
if (_selected[temp] == 1 || (g.VList[temp].XLoc + g.VList[temp].YLoc) % 2 == 1) continue;
|
||||
Pt[n] = new WeightedPoint(g.VList[temp].XLoc, g.VList[temp].YLoc, 0);
|
||||
_selected[temp] = 1;
|
||||
//compute weight based on point density
|
||||
//temp2 = r2.Next(1, list.Count);
|
||||
//pt[n] = new Point(g.vList[temp].x_loc, g.vList[temp].y_loc, (int) list.ElementAt(temp2));
|
||||
//list.RemoveAt(temp2);
|
||||
Pt[n].GridPoint = temp;
|
||||
g.VList[temp].Weight = Pt[n].Weight;
|
||||
n--;
|
||||
}
|
||||
AssignWeight(Pt, NumPoints, (int)Math.Sqrt(g.NumOfnodes));
|
||||
|
||||
|
||||
NumOfLevels = NumPoints / pointsPerLevel;
|
||||
if (NumPoints % pointsPerLevel > 0) NumOfLevels++;
|
||||
|
||||
for (int index = 1; index <= NumPoints; index++)
|
||||
{
|
||||
Pt[index].ZoomLevel = 1 + (index - 1) / pointsPerLevel;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= NumPoints; i++)
|
||||
{
|
||||
Console.WriteLine(Pt[i].Weight);
|
||||
g.VList[Pt[i].GridPoint].Weight = Pt[i].Weight;
|
||||
g.VList[Pt[i].GridPoint].ZoomLevel = Pt[i].ZoomLevel;
|
||||
pointMap[Pt[i].X, Pt[i].Y] = i;
|
||||
|
||||
}
|
||||
|
||||
//random shuffle
|
||||
//int p1;
|
||||
//for (int i = 1; i <= 10000; i++)
|
||||
//{
|
||||
// p1 = r1.Next(1, num_points);
|
||||
// pt[p1].weight = r2.Next(10, 255);
|
||||
// g.vList[pt[p1].grid_point].weight = pt[p1].weight;
|
||||
//}
|
||||
}
|
||||
public void AssignWeight(WeightedPoint[] pt, int numPoints, int rad)
|
||||
{
|
||||
for (int i = 1; i <= numPoints; i++)
|
||||
{
|
||||
pt[i].Weight++;
|
||||
for (int j = i + 1; j <= numPoints; j++)
|
||||
{
|
||||
var temp = Math.Sqrt((pt[i].X - pt[j].X) * (pt[i].X - pt[j].X) + (pt[i].Y - pt[j].Y) * (pt[i].Y - pt[j].Y));
|
||||
if (temp < rad) { pt[i].Weight++; pt[j].Weight++; }
|
||||
}
|
||||
}
|
||||
|
||||
double tempMin = numPoints;
|
||||
double tempMax = 0;
|
||||
for (int i = 1; i <= numPoints; i++)
|
||||
{
|
||||
if (tempMax < pt[i].Weight) tempMax = pt[i].Weight;
|
||||
if (tempMin > pt[i].Weight) tempMin = pt[i].Weight;
|
||||
}
|
||||
for (int i = 1; i <= numPoints; i++)
|
||||
pt[i].Weight = 50 + (int)((pt[i].Weight - tempMin) * 200 / (tempMax - tempMin));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class WeightedPoint
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
public int Weight;
|
||||
public int GridPoint; //id of the grid point
|
||||
public int ZoomLevel;
|
||||
public WeightedPoint() { }
|
||||
public WeightedPoint(int a, int b, int c)
|
||||
{
|
||||
X = a; Y = b; Weight = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/PointSet.cs.meta
Normal file
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/PointSet.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0bb5ede1a9dcf3845b984dff3c6ccdc0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
using System;
|
||||
|
||||
namespace Microsoft.Msagl.GraphmapsWithMesh
|
||||
{
|
||||
public class PointToSegmentDistance
|
||||
{
|
||||
public static double GetDistance(Microsoft.Msagl.Core.Geometry.Point pointA, Microsoft.Msagl.Core.Geometry.Point pointB, Microsoft.Msagl.Core.Geometry.Point pointC)
|
||||
{
|
||||
return GetDistance(new Vertex((int)pointA.X, (int)pointA.Y), new Vertex((int)pointB.X, (int)pointB.Y), new Vertex((int)pointC.X, (int)pointC.Y));
|
||||
}
|
||||
public static Microsoft.Msagl.Core.Geometry.Point getClosestPoint(Vertex pointA, Vertex pointB, Vertex pointP)
|
||||
{
|
||||
|
||||
double[] AP = new double[2];
|
||||
AP[0] = pointP.XLoc - pointA.XLoc;
|
||||
AP[1] = pointP.YLoc - pointA.YLoc;
|
||||
|
||||
double[] AB = new double[2];
|
||||
AB[0] = pointB.XLoc - pointA.XLoc;
|
||||
AB[1] = pointB.YLoc - pointA.YLoc;
|
||||
|
||||
double AB_length = AB[0] * AB[0] + AB[1] * AB[1];
|
||||
double AP_AB_Dot = AP[0] * AB[0] + AP[1] * AB[1];
|
||||
double t = AP_AB_Dot / AB_length;
|
||||
|
||||
if (t < 0) t = 0;
|
||||
if (t > 1) t = 1;
|
||||
double pointx = pointA.XLoc + AB[0] * t;
|
||||
double pointy = pointA.YLoc + AB[1] * t;
|
||||
return new Microsoft.Msagl.Core.Geometry.Point(pointx, pointy);
|
||||
}
|
||||
//Compute the distance from AB to C
|
||||
//if isSegment is true, AB is a segment, not a line.
|
||||
public static double GetDistance(Vertex pointA, Vertex pointB, Vertex pointC)
|
||||
{
|
||||
double dist = CrossProduct(pointA, pointB, pointC) / Distance(pointA, pointB);
|
||||
|
||||
double dot1 = DotProduct(pointA, pointB, pointC);
|
||||
if (dot1 > 0)
|
||||
return Distance(pointB, pointC);
|
||||
|
||||
double dot2 = DotProduct(pointB, pointA, pointC);
|
||||
if (dot2 > 0)
|
||||
return Distance(pointA, pointC);
|
||||
|
||||
return Math.Abs(dist);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Compute the dot product AB . AC
|
||||
private static double DotProduct(Vertex pointA, Vertex pointB, Vertex pointC)
|
||||
{
|
||||
double[] ab = new double[2];
|
||||
double[] bc = new double[2];
|
||||
ab[0] = pointB.XLoc - pointA.XLoc;
|
||||
ab[1] = pointB.YLoc - pointA.YLoc;
|
||||
bc[0] = pointC.XLoc - pointB.XLoc;
|
||||
bc[1] = pointC.YLoc - pointB.YLoc;
|
||||
double dot = ab[0] * bc[0] + ab[1] * bc[1];
|
||||
|
||||
return dot;
|
||||
}
|
||||
|
||||
//Compute the cross product AB x AC
|
||||
static private double CrossProduct(Vertex pointA, Vertex pointB, Vertex pointC)
|
||||
{
|
||||
double[] ab = new double[2];
|
||||
double[] ac = new double[2];
|
||||
ab[0] = pointB.XLoc - pointA.XLoc;
|
||||
ab[1] = pointB.YLoc - pointA.YLoc;
|
||||
ac[0] = pointC.XLoc - pointA.XLoc;
|
||||
ac[1] = pointC.YLoc - pointA.YLoc;
|
||||
double cross = ab[0] * ac[1] - ab[1] * ac[0];
|
||||
|
||||
return cross;
|
||||
}
|
||||
|
||||
//Compute the distance from A to B
|
||||
static double Distance(Vertex pointA, Vertex pointB)
|
||||
{
|
||||
double d1 = pointA.XLoc - pointB.XLoc;
|
||||
double d2 = pointA.YLoc - pointB.YLoc;
|
||||
|
||||
return Math.Sqrt(d1 * d1 + d2 * d2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ee905eeab42cb424cad4e1e8b6b7dcf9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
Assets/Plugins/MSAGL/GraphmapsWithMesh/SteinerTree.cs
Normal file
50
Assets/Plugins/MSAGL/GraphmapsWithMesh/SteinerTree.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.Msagl.GraphmapsWithMesh
|
||||
{
|
||||
class SteinerTree
|
||||
{
|
||||
public Stack<Tuple> Edgelist = new Stack<Tuple>();
|
||||
public List<Twin> SpanningTree = new List<Twin>();
|
||||
//ComponentCollection _compCollection;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class Component
|
||||
{
|
||||
public int CId = 0;
|
||||
public double Dist;
|
||||
public bool Dead = true;
|
||||
public List<Vertex> V = new List<Vertex>();
|
||||
public List<VertexNeighbor> Segments = new List<VertexNeighbor>();
|
||||
|
||||
public void AddVertex(Vertex w)
|
||||
{
|
||||
foreach (Vertex z in V)
|
||||
{
|
||||
if (w.Id == z.Id) return;
|
||||
}
|
||||
V.Add(w);
|
||||
}
|
||||
}
|
||||
|
||||
public class Twin
|
||||
{
|
||||
public int A;
|
||||
public int B;
|
||||
public Twin(int x, int y) { A = x; B = y; }
|
||||
|
||||
}
|
||||
public class Tuple
|
||||
{
|
||||
public Vertex A;
|
||||
public Vertex B;
|
||||
public int Value;
|
||||
public Tuple(Vertex x, Vertex y, int z)
|
||||
{
|
||||
A = x; B = y; Value = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/SteinerTree.cs.meta
Normal file
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/SteinerTree.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 08f778dccb3c62d438a0539dd6c57ad5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1864
Assets/Plugins/MSAGL/GraphmapsWithMesh/Tiling.cs
Normal file
1864
Assets/Plugins/MSAGL/GraphmapsWithMesh/Tiling.cs
Normal file
File diff suppressed because it is too large
Load diff
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/Tiling.cs.meta
Normal file
11
Assets/Plugins/MSAGL/GraphmapsWithMesh/Tiling.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: eba9642053196364b9540353c37fd0ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue