public static XYExtent GetExtent(XYLine line) { XYExtent res = new XYExtent(); if (line.P1.X < line.P2.X) { res.XMin = line.P1.X; res.XMax = line.P2.X; } else { res.XMin = line.P2.X; res.XMax = line.P1.X; } if (line.P1.Y < line.P2.Y) { res.YMin = line.P1.Y; res.YMax = line.P2.Y; } else { res.YMin = line.P2.Y; res.YMax = line.P1.Y; } return(res); }
public void PointSearchTest() { ElementSet elmtSet = ReadMesh(@"..\..\Spatial\Data\oresund.mesh"); XYElementSearchTree <int> tree = XYElementSearchTree <int> .BuildSearchTree(elmtSet); // Point in element 746 (has index 745) XYPoint point = new XYPoint(355273.227764, 6201136.0892); XYExtent pointExtent = XYExtentUtil.GetExtent(point); ICollection <int> pointCandidates = tree.FindElements(pointExtent); Assert.Contains(745, (ICollection)pointCandidates); XYPolygon elmt745 = ElementMapper.CreateFromXYPolygon(elmtSet, 745); Assert.IsTrue(XYGeometryTools.IsPointInPolygon(point.X, point.Y, elmt745)); // Point in element 3583 (has index 3582) XYPoint point2 = new XYPoint(354683.522377, 6167696.720773); XYExtent point2Extent = XYExtentUtil.GetExtent(point2); ICollection <int> point2Candidates = tree.FindElements(point2Extent); Assert.Contains(3582, (ICollection)point2Candidates); XYPolygon elmt3582 = ElementMapper.CreateFromXYPolygon(elmtSet, 3582); Assert.IsTrue(XYGeometryTools.IsPointInPolygon(point2.X, point2.Y, elmt3582)); // Node 2001 is part of 7 elements XYPoint pointNode2001 = new XYPoint(355451.29058143805, 6167084.759883712); XYExtent pointNode2001Extent = XYExtentUtil.GetExtent(pointNode2001); ICollection <int> pointNode2001Candidates = tree.FindElements(pointNode2001Extent); Assert.AreEqual(7, pointNode2001Candidates.Count); }
public static XYExtent GetExtent(XYPolygon polygon) { XYExtent res = new XYExtent(); foreach (XYPoint point in polygon.Points) { res.Include(point.X, point.Y); } return(res); }