Skip to content

Commit

Permalink
Bump to .NET 8.0 (#6)
Browse files Browse the repository at this point in the history
* Bump to .NET 8.0

* Updated QuikGraph dependency.

* Changed obsolete method
  • Loading branch information
carl-andersson-at-westermo authored Mar 11, 2024
1 parent 0901aae commit 9c9fd64
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Examples/ShowcaseApp.WPF/ShowcaseApp.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion Examples/SimpleGraph/SimpleGraph.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<RootNamespace>SimpleGraph</RootNamespace>
<IsPackable>false</IsPackable>
Expand Down
70 changes: 40 additions & 30 deletions Westermo.GraphX.Common/Helpers/GraphSharpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public static class GraphXExtensions
/// <typeparam name="TGraph"></typeparam>
/// <param name="graph">Graph</param>
/// <param name="vertex">Vertex</param>
public static IEnumerable<TEdge> GetAllEdges<TVertex, TEdge>(this IBidirectionalGraph<TVertex, TEdge> graph, TVertex vertex)
public static IEnumerable<TEdge> GetAllEdges<TVertex, TEdge>(this IBidirectionalGraph<TVertex, TEdge> graph,
TVertex vertex)
where TVertex : class, IGraphXVertex
where TEdge : class, IGraphXEdge<TVertex>
{
Expand All @@ -32,8 +33,9 @@ public static IEnumerable<TEdge> GetAllEdges<TVertex, TEdge>(this IBidirectional
return result;
}

public static IEnumerable<TEdge> GetInEdges<TVertex, TEdge>(this IBidirectionalGraph<TVertex, TEdge> graph, TVertex vertex)
where TEdge : IEdge<TVertex>
public static IEnumerable<TEdge> GetInEdges<TVertex, TEdge>(this IBidirectionalGraph<TVertex, TEdge> graph,
TVertex vertex)
where TEdge : IEdge<TVertex>
{
var result = new List<TEdge>();
IEnumerable<TEdge> edges;
Expand All @@ -43,8 +45,9 @@ public static IEnumerable<TEdge> GetInEdges<TVertex, TEdge>(this IBidirectionalG
return result;
}

public static IEnumerable<TEdge> GetOutEdges<TVertex, TEdge>(this IBidirectionalGraph<TVertex, TEdge> graph, TVertex vertex)
where TEdge : IEdge<TVertex>
public static IEnumerable<TEdge> GetOutEdges<TVertex, TEdge>(this IBidirectionalGraph<TVertex, TEdge> graph,
TVertex vertex)
where TEdge : IEdge<TVertex>
{
var result = new List<TEdge>();
IEnumerable<TEdge> edges;
Expand All @@ -60,7 +63,8 @@ public static IEnumerable<TEdge> GetOutEdges<TVertex, TEdge>(this IBidirectional
/// <param name="g">The graph.</param>
/// <param name="vertex">The vertex which neighbours' we want to get.</param>
/// <returns>List of the adjacent vertices of the <code>vertex</code>.</returns>
public static IEnumerable<TVertex> GetNeighbours<TVertex, TEdge>(this IBidirectionalGraph<TVertex, TEdge> g, TVertex vertex)
public static IEnumerable<TVertex> GetNeighbours<TVertex, TEdge>(this IBidirectionalGraph<TVertex, TEdge> g,
TVertex vertex)
where TEdge : IEdge<TVertex>
{
return (from e in g.InEdges(vertex) select e.Source)
Expand All @@ -69,18 +73,20 @@ public static IEnumerable<TVertex> GetNeighbours<TVertex, TEdge>(this IBidirecti
}


public static IEnumerable<TVertex> GetOutNeighbours<TVertex, TEdge>(this IVertexAndEdgeListGraph<TVertex, TEdge> g, TVertex vertex)
public static IEnumerable<TVertex> GetOutNeighbours<TVertex, TEdge>(
this IVertexAndEdgeListGraph<TVertex, TEdge> g, TVertex vertex)
where TEdge : IEdge<TVertex>
{
return (from e in g.OutEdges(vertex)
select e.Target).Distinct();
select e.Target).Distinct();
}

public static IEnumerable<TVertex> GetInNeighbours<TVertex, TEdge>(this IBidirectionalGraph<TVertex, TEdge> g, TVertex vertex)
public static IEnumerable<TVertex> GetInNeighbours<TVertex, TEdge>(this IBidirectionalGraph<TVertex, TEdge> g,
TVertex vertex)
where TEdge : IEdge<TVertex>
{
return (from e in g.InEdges(vertex)
select e.Source).Distinct();
select e.Source).Distinct();
}


Expand All @@ -95,18 +101,19 @@ public static IEnumerable<TVertex> GetInNeighbours<TVertex, TEdge>(this IBidirec
/// <param name="set2"></param>
/// <param name="undirected">Assume undirected graph - get both in and out edges</param>
/// <returns>Return the list of the selected edges.</returns>
public static IEnumerable<TEdge> GetEdgesBetween<TVertex, TEdge>(this IVertexAndEdgeListGraph<TVertex, TEdge> g, List<TVertex> set1, List<TVertex> set2, bool undirected = false)
public static IEnumerable<TEdge> GetEdgesBetween<TVertex, TEdge>(this IVertexAndEdgeListGraph<TVertex, TEdge> g,
List<TVertex> set1, List<TVertex> set2, bool undirected = false)
where TEdge : IEdge<TVertex>
where TVertex: class
where TVertex : class
{
var edgesBetween = new List<TEdge>();

//vegig kell menni az osszes vertex minden elen, es megnezni, hogy a target hol van
foreach (var v in set1)
{
edgesBetween.AddRange(g.OutEdges(v).Where(edge => set2.Contains(edge.Target)));
if(undirected)
edgesBetween.AddRange(g.Edges.Where(a=> a.Target == v).Where(edge => set2.Contains(edge.Source)));
if (undirected)
edgesBetween.AddRange(g.Edges.Where(a => a.Target == v).Where(edge => set2.Contains(edge.Source)));
}

return edgesBetween;
Expand All @@ -124,8 +131,8 @@ public static IEnumerable<TVertex> GetSources<TVertex, TEdge>(this IBidirectiona
where TEdge : IEdge<TVertex>
{
return from v in g.Vertices
where g.InDegree(v) == 0
select v;
where g.InDegree(v) == 0
select v;
}

/// <summary>
Expand Down Expand Up @@ -167,6 +174,7 @@ public static double GetDiameter<TVertex, TEdge, TGraph>(this TGraph g, out doub
distance = Math.Max(distance, distances[i, j]);
}
}

return distance;
}

Expand Down Expand Up @@ -199,18 +207,20 @@ public static double GetDiameter<TVertex, TEdge, TGraph>(this TGraph g, out doub
{
//compute the distances from the 'source'
var spaDijkstra =
new UndirectedDijkstraShortestPathAlgorithm<TVertex, TEdge>(undirected, edge => weights[edge], QuikGraph.Algorithms.DistanceRelaxers.ShortestDistance);
new UndirectedDijkstraShortestPathAlgorithm<TVertex, TEdge>(undirected, edge => weights[edge],
QuikGraph.Algorithms.DistanceRelaxers.ShortestDistance);
spaDijkstra.Compute(source);

var j = 0;
foreach (var v in undirected.Vertices)
{
var d = spaDijkstra.Distances[v];
var d = spaDijkstra.GetDistance(v);
distances[i, j] = Math.Min(distances[i, j], d);
distances[i, j] = Math.Min(distances[i, j], distances[j, i]);
distances[j, i] = Math.Min(distances[i, j], distances[j, i]);
j++;
}

i++;
}

Expand All @@ -223,16 +233,15 @@ public static TVertex OtherVertex<TVertex>(this IEdge<TVertex> edge, TVertex thi
}



public static void AddEdgeRange<TVertex, TEdge>(this IMutableEdgeListGraph<TVertex, TEdge> graph, IEnumerable<TEdge> edges)
public static void AddEdgeRange<TVertex, TEdge>(this IMutableEdgeListGraph<TVertex, TEdge> graph,
IEnumerable<TEdge> edges)
where TEdge : IEdge<TVertex>
{
foreach (var edge in edges)
graph.AddEdge(edge);
}



public static BidirectionalGraph<TNewVertex, TNewEdge> Convert<TOldVertex, TOldEdge, TNewVertex, TNewEdge>(
this IVertexAndEdgeListGraph<TOldVertex, TOldEdge> oldGraph,
Func<TOldVertex, TNewVertex> vertexMapperFunc,
Expand All @@ -247,7 +256,6 @@ public static BidirectionalGraph<TNewVertex, TNewEdge> Convert<TOldVertex, TOldE
}



public static BidirectionalGraph<TOldVertex, TNewEdge> Convert<TOldVertex, TOldEdge, TNewEdge>(
this IVertexAndEdgeListGraph<TOldVertex, TOldEdge> oldGraph,
Func<TOldEdge, TNewEdge> edgeMapperFunc)
Expand All @@ -258,7 +266,6 @@ public static BidirectionalGraph<TOldVertex, TNewEdge> Convert<TOldVertex, TOldE
}



public static TNewGraph Convert<TOldVertex, TOldEdge, TNewVertex, TNewEdge, TNewGraph>(
this IVertexAndEdgeListGraph<TOldVertex, TOldEdge> oldGraph,
TNewGraph newGraph,
Expand All @@ -269,16 +276,19 @@ public static TNewGraph Convert<TOldVertex, TOldEdge, TNewVertex, TNewEdge, TNew
where TNewGraph : IMutableVertexAndEdgeListGraph<TNewVertex, TNewEdge>
{
//VERTICES
newGraph.AddVertexRange(vertexMapperFunc != null ? oldGraph.Vertices.Select(vertexMapperFunc) : oldGraph.Vertices.Cast<TNewVertex>());
newGraph.AddVertexRange(vertexMapperFunc != null
? oldGraph.Vertices.Select(vertexMapperFunc)
: oldGraph.Vertices.Cast<TNewVertex>());

//EDGES
newGraph.AddEdgeRange(edgeMapperFunc != null ? oldGraph.Edges.Select(edgeMapperFunc) : oldGraph.Edges.Cast<TNewEdge>());
newGraph.AddEdgeRange(edgeMapperFunc != null
? oldGraph.Edges.Select(edgeMapperFunc)
: oldGraph.Edges.Cast<TNewEdge>());

return newGraph;
}



public static TNewGraph Convert<TOldVertex, TOldEdge, TNewEdge, TNewGraph>(
this IVertexAndEdgeListGraph<TOldVertex, TOldEdge> oldGraph,
TNewGraph newGraph,
Expand All @@ -287,11 +297,11 @@ public static TNewGraph Convert<TOldVertex, TOldEdge, TNewEdge, TNewGraph>(
where TNewEdge : IEdge<TOldVertex>
where TNewGraph : IMutableVertexAndEdgeListGraph<TOldVertex, TNewEdge>
{
return oldGraph.Convert<TOldVertex, TOldEdge, TOldVertex, TNewEdge, TNewGraph>(newGraph, null, edgeMapperFunc);
return oldGraph.Convert<TOldVertex, TOldEdge, TOldVertex, TNewEdge, TNewGraph>(newGraph, null,
edgeMapperFunc);
}



public static TNewGraph Convert<TOldVertex, TOldEdge, TNewGraph>(
this IVertexAndEdgeListGraph<TOldVertex, TOldEdge> oldGraph,
TNewGraph newGraph)
Expand All @@ -309,7 +319,7 @@ public static BidirectionalGraph<TVertex, TEdge> CopyToBidirectionalGraph<TVerte
var newGraph = new BidirectionalGraph<TVertex, TEdge>();

//copy the vertices
if(!includeEmpty)
if (!includeEmpty)
newGraph.AddVerticesAndEdgeRange(graph.Edges);
else
{
Expand Down Expand Up @@ -339,4 +349,4 @@ public static TGraph CopyToGraph<TGraph, TVertex, TEdge>(this TGraph graph, bool
return newGraph;
}
}
}
}
2 changes: 1 addition & 1 deletion Westermo.GraphX.Common/Westermo.GraphX.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="QuikGraph" Version="2.2.0" />
<PackageReference Include="QuikGraph" Version="2.5.0" />
</ItemGroup>

<!-- NuGet related -->
Expand Down
12 changes: 6 additions & 6 deletions Westermo.GraphX.Controls/MathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static bool IsIntersected(Rect r, Point a, Point b)
return false;

/* select point with zero code */
sides code;
Sides code;
Point c; /* one of the points */
if (!codeA.IsInside())
{
Expand Down Expand Up @@ -177,7 +177,7 @@ public static int GetIntersectionPoint(Rect r, Point a, Point b, out Point pt)
return -1;
}

sides code;
Sides code;
Point c;
if (!codeA.IsInside())
{
Expand Down Expand Up @@ -226,7 +226,7 @@ public static int GetIntersectionPoint(Rect r, Point a, Point b, out Point pt)
return 0;
}

public sealed class sides
public sealed class Sides
{
public bool Left;
public bool Right;
Expand All @@ -238,16 +238,16 @@ public bool IsInside()
return Left == false && Right == false && Top == false && Bottom == false;
}

public bool SameSide(sides o)
public bool SameSide(Sides o)
{
return (Left && o.Left) || (Right && o.Right) || (Top && o.Top)
|| (Bottom && o.Bottom);
}
}

public static sides GetIntersectionData(Rect r, Point p)
public static Sides GetIntersectionData(Rect r, Point p)
{
return new sides() { Left = p.X < r.Left, Right = p.X > r.Right, Bottom = p.Y > r.Bottom, Top = p.Y < r.Top };
return new Sides() { Left = p.X < r.Left, Right = p.X > r.Right, Bottom = p.Y > r.Bottom, Top = p.Y < r.Top };
}

public static double GetDistance(Point a, Point b)
Expand Down
2 changes: 1 addition & 1 deletion Westermo.GraphX.Controls/Westermo.GraphX.Controls.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<UseWPF>true</UseWPF>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,13 @@ private TVertex GetClosest( Point tempPos )
return vertex;
}

#pragma warning disable CS0414 // Field is assigned but its value is never used
private class ISOMData
{
public Vector Force = new Vector();
public bool Visited;
public double Distance;
}
#pragma warning restore CS0414 // Field is assigned but its value is never used
}
}
6 changes: 0 additions & 6 deletions global.json

This file was deleted.

0 comments on commit 9c9fd64

Please sign in to comment.