Skip to content

Commit

Permalink
AdaptiveGrid.AddEdge no longer delete edges in case where new edge …
Browse files Browse the repository at this point in the history
…partially overlaps old edges without intersections.
  • Loading branch information
DmytroMuravskyi committed Dec 5, 2023
1 parent 311e767 commit 6a58373
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
- `BoundedCurve.ToPolyline` now works correctly for `EllipticalArc` class.
- `Ray.Intersects(Topography)` and `Ray.Intersects(Mesh)` would sometimes return a different intersection than the closest one.
- `Ray.Intersects(Topography)` now considers the topography's transform.
- `AdaptiveGrid.AddEdge` no longer delete edges in case where new edge partially overlaps old edges without intersections.

### Changed

Expand Down
2 changes: 2 additions & 0 deletions Elements/src/Spatial/AdaptiveGrid/AdaptiveGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -936,12 +936,14 @@ private List<Edge> AddCutEdge(ulong startId, ulong endId)
AddEdgeOverlappingExisting(edgeV0, edgeV1, startVertex, endVertex, true))
{
edgesToRemove.Add(edge);
intersectionPoints.Add(oldEdgeLine.End);
}

if (isOldEdgeStartOnNewEdge &&
AddEdgeOverlappingExisting(edgeV0, edgeV1, startVertex, endVertex, false))
{
edgesToRemove.Add(edge);
intersectionPoints.Add(oldEdgeLine.Start);
}
}
// old edge is inside new edge
Expand Down
35 changes: 35 additions & 0 deletions Elements/test/AdaptiveGridTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,41 @@ public void AdaptiveGridAddCutEdge()
Assert.Equal(new Vector3(6, 4), otherVertex.Point);
}

[Fact]
public void AdaptiveGridAddCutWithOverlap()
{
var grid = new AdaptiveGrid();
//Create single edges, so cut operation process only overlaps and not intersections.
grid.AddEdge(new Vector3(0, 0), new Vector3(0, 10));

//Start point of new edge is outside, end is inside.
var v0 = grid.AddVertex(new Vector3(0, -5));
var v1 = grid.AddVertex(new Vector3(0, 3));
var edges = grid.AddEdge(v0.Id, v1.Id);
Assert.Equal(2, edges.Count);
Assert.Single(v0.Edges);
Assert.Equal(2, v1.Edges.Count);
var middle = edges.First().OtherVertexId(v0.Id);
var middleVertex = grid.GetVertex(middle);
Assert.Equal(new Vector3(0, 0), middleVertex.Point);
Assert.Equal(2, middleVertex.Edges.Count);

//End point of new edge is outside, start is inside.
v0 = grid.AddVertex(new Vector3(0, 7));
v1 = grid.AddVertex(new Vector3(0, 15));
edges = grid.AddEdge(v0.Id, v1.Id);
Assert.Equal(2, edges.Count);
Assert.Equal(2, v0.Edges.Count);
Assert.Single(v1.Edges);
middle = edges.Last().OtherVertexId(v1.Id);
middleVertex = grid.GetVertex(middle);
Assert.Equal(new Vector3(0, 10), middleVertex.Point);
Assert.Equal(2, middleVertex.Edges.Count);

// Result should be strip of 6 vertices.
Assert.Equal(6, grid.GetVertices().Count);
}

[Fact]
public void AdaptiveGridAddVertexWithAngle()
{
Expand Down

0 comments on commit 6a58373

Please sign in to comment.