private void AddEndIntercept(XYZ point, List <XYZS> intercepts, double station) { if (!Index.CalculateIndexOfCellContainingPosition(point.X, point.Y, out int cellX, out int cellY)) { Log.LogWarning($"No cell address computable for end point location {point.X}:{point.Y}"); return; } var subGrid = Index.LocateSubGridContaining(cellX, cellY); if (subGrid == null) // No triangles in this 'node' sub grid { return; } if (!(subGrid is TriangleArrayReferenceSubGrid referenceSubGrid)) { Log.LogCritical($"Sub grid is not a TriangleArrayReferenceSubGrid, is is a {subGrid.GetType()}"); return; } // Get the cell representing a leaf sub grid and determine if there is a triangle at the point location subGrid.GetSubGridCellIndex(cellX, cellY, out byte subGridX, out byte subGridY); TriangleArrayReference referenceList = referenceSubGrid.Items[subGridX, subGridY]; int endIndex = referenceList.TriangleArrayIndex + referenceList.Count; for (int i = referenceList.TriangleArrayIndex; i < endIndex; i++) { double height = XYZ.GetTriangleHeightEx (ref TTM.Vertices.Items[TTM.Triangles.Items[Indices[i]].Vertex0], ref TTM.Vertices.Items[TTM.Triangles.Items[Indices[i]].Vertex1], ref TTM.Vertices.Items[TTM.Triangles.Items[Indices[i]].Vertex2], point.X, point.Y); if (height != Common.Consts.NullDouble) { intercepts.Add(new XYZS(point.X, point.Y, height, station, Indices[i])); return; } } }