Skip to content

Commit

Permalink
Support for NTS173
Browse files Browse the repository at this point in the history
  • Loading branch information
JesperGr committed Jul 10, 2019
1 parent 62322b4 commit f72faeb
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/DHI.Mesh/MeshSearcher.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
using GeoAPI.Geometries;
#if NTS173
using GisSharpBlog.NetTopologySuite.Geometries;
using GisSharpBlog.NetTopologySuite.Index.Strtree;
#else
using NetTopologySuite.Index.Strtree;
#endif

namespace DHI.Mesh
{
Expand All @@ -14,7 +20,11 @@ public class MeshSearcher
{
private MeshData _mesh;

#if NTS173
private STRtree _elementSearchTree;
#else
private STRtree<MeshElement> _elementSearchTree;
#endif

/// <summary>
/// Create searcher for provided <paramref name="mesh"/>
Expand All @@ -29,7 +39,11 @@ public MeshSearcher(MeshData mesh)
/// </summary>
public void SetupElementSearch()
{
#if NTS173
_elementSearchTree = new STRtree();
#else
_elementSearchTree = new STRtree<MeshElement>();
#endif
for (int i = 0; i < _mesh.Elements.Count; i++)
{
MeshElement element = _mesh.Elements[i];
Expand All @@ -55,12 +69,21 @@ public MeshElement FindElement(double x, double y)
{
// Find potential elements for (x,y) point
Envelope targetEnvelope = new Envelope(x, x, y, y);

#if NTS173
IList potentialSourceElmts = _elementSearchTree.Query(targetEnvelope);
#else
IList<MeshElement> potentialSourceElmts = _elementSearchTree.Query(targetEnvelope);
#endif

// Loop over all potential elements
for (int i = 0; i < potentialSourceElmts.Count; i++)
{
#if NTS173
MeshElement element = (MeshElement)potentialSourceElmts[i];
#else
MeshElement element = potentialSourceElmts[i];
#endif

// Check if element includes the (x,y) point
if (element.Includes(x, y))
Expand Down

0 comments on commit f72faeb

Please sign in to comment.