/// <summary> /// Find element containing (x,y) coordinate. Returns null if no element found. /// <para> /// If (x,y) is exacly on the boundary between two elements, one of them will be returned. /// If (x,y) is matching exacly a node coordinate, one of the elements including the node will be returned. /// </para> /// </summary> 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)) { return(element); } } return(null); }
/// <summary> /// Find element containing (x,y) coordinate. Returns null if no element found. /// <para> /// If (x,y) is exactly on the boundary between two elements, one of them will be returned. /// If (x,y) is matching exacly a node coordinate, one of the elements including the node will be returned. /// </para> /// </summary> public MeshElement FindElement(double x, double y) { // Find potential elements for (x,y) point Envelope targetEnvelope = new Envelope(x, x, y, y); IList <MeshElement> potentialSourceElmts = _elementSearchTree.Query(targetEnvelope); // Loop over all potential elements for (int i = 0; i < potentialSourceElmts.Count; i++) { MeshElement element = potentialSourceElmts[i]; // Check if element includes the (x,y) point if (element.Includes(x, y)) { return(element); } } if (Tolerance <= 0) { return(null); } // Try again, now with tolerance for (int i = 0; i < potentialSourceElmts.Count; i++) { MeshElement element = potentialSourceElmts[i]; // Check if element includes the (x,y) point if (element.Includes(x, y, Tolerance)) { return(element); } } return(null); }