Skip to content

Commit

Permalink
Merge pull request #926 from DmytroMuravskyi/flags-hotfix
Browse files Browse the repository at this point in the history
EdgeInfo.Flags hotfix (#926)
  • Loading branch information
wynged authored Dec 2, 2022
2 parents dc11441 + 140d272 commit a640e33
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
8 changes: 1 addition & 7 deletions Elements/src/Spatial/AdaptiveGrid/AdaptiveGraphRouting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ private Dictionary<ulong, EdgeInfo> CalculateEdgeInfos(
}

var info = new EdgeInfo(_grid, e, hintFactor * offsetFactor * modifierFactor);
info.Flags = flags;
info.AddFlags(flags);
weights[e.Id] = info;
}
}
Expand Down Expand Up @@ -992,12 +992,6 @@ private bool IsNearby(Vector3 v, IEnumerable<RoutingHintLine> hints)
return false;
}

private bool IsAffectedBy(
Vector3 start, Vector3 end, IEnumerable<RoutingHintLine> hints)
{
return hints != null && hints.Any(h => IsAffectedBy(start, end, h));
}

private bool IsAffectedBy(Vector3 start, Vector3 end, RoutingHintLine hint)
{
var influenceDistance = Math.Max(hint.InfluenceDistance, _grid.Tolerance);
Expand Down
6 changes: 3 additions & 3 deletions Elements/src/Spatial/AdaptiveGrid/EdgeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public EdgeInfo(AdaptiveGrid grid, Edge edge, double factor = 1)

if (Math.Abs(v0.Point.Z - v1.Point.Z) > grid.Tolerance)
{
Flags &= EdgeFlags.HasVerticalChange;
Flags |= EdgeFlags.HasVerticalChange;
HasVerticalChange = true;
}
}
Expand All @@ -51,13 +51,13 @@ public EdgeInfo(AdaptiveGrid grid, Edge edge, double factor = 1)
/// <summary>
/// Are edge end points on different elevations.
/// </summary>
[Obsolete("Use HasFlag(EdgeFlags.HasVerticalChange) instead")]
[Obsolete("Use HasAnyFlag(EdgeFlags.HasVerticalChange) instead")]
public readonly bool HasVerticalChange;

/// <summary>
/// Additional information about the edge.
/// </summary>
internal EdgeFlags Flags;
private EdgeFlags Flags;

/// <summary>
/// Check if edge info has a certain flag or combination of flags set.
Expand Down
24 changes: 18 additions & 6 deletions Elements/test/AdaptiveGridTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,12 +1083,24 @@ public void EdgeInfoFlagsTest()
AdaptiveGrid grid = new AdaptiveGrid();
var polygon = Polygon.Rectangle(Vector3.Origin, new Vector3(10, 10));
grid.AddFromPolygon(polygon, new List<Vector3>() { new Vector3(5, 5) });
EdgeInfo info = new EdgeInfo(grid, grid.GetEdges().First());
info.AddFlags(EdgeFlags.UserDefinedHint2D | EdgeFlags.HasVerticalChange);
Assert.True(info.HasAnyFlag(EdgeFlags.HasVerticalChange));
Assert.True(info.HasAnyFlag(EdgeFlags.UserDefinedHint2D));
Assert.False(info.HasAnyFlag(EdgeFlags.UserDefinedHint3D));
Assert.True(info.HasAnyFlag(EdgeFlags.UserDefinedHint2D | EdgeFlags.UserDefinedHint3D));
grid.AddEdge(Vector3.Origin, new Vector3(0, 0, 5));

grid.TryGetVertexIndex(Vector3.Origin, out var id0);
grid.TryGetVertexIndex(new Vector3(0, 0, 5), out var id1);
grid.TryGetVertexIndex(new Vector3(0, 5), out var id2);

var verticalEdge = grid.GetVertex(id0).Edges.First(e => e.StartId == id1 || e.EndId == id1);
var horizontalEdge = grid.GetVertex(id0).Edges.First(e => e.StartId == id2 || e.EndId == id2);
EdgeInfo verticalEdgeInfo = new EdgeInfo(grid, verticalEdge);
EdgeInfo horizontalEdgeInfo = new EdgeInfo(grid, horizontalEdge);
Assert.True(verticalEdgeInfo.HasAnyFlag(EdgeFlags.HasVerticalChange));
Assert.False(horizontalEdgeInfo.HasAnyFlag(EdgeFlags.HasVerticalChange));

horizontalEdgeInfo.AddFlags(EdgeFlags.UserDefinedHint2D | EdgeFlags.HasVerticalChange);
Assert.True(horizontalEdgeInfo.HasAnyFlag(EdgeFlags.HasVerticalChange));
Assert.True(horizontalEdgeInfo.HasAnyFlag(EdgeFlags.UserDefinedHint2D));
Assert.False(horizontalEdgeInfo.HasAnyFlag(EdgeFlags.UserDefinedHint3D));
Assert.True(horizontalEdgeInfo.HasAnyFlag(EdgeFlags.UserDefinedHint2D | EdgeFlags.UserDefinedHint3D));
}

// (4)
Expand Down

0 comments on commit a640e33

Please sign in to comment.