private void BuildWellList() { double distanceInMeters = SearchDistance * 1000; Wells = AllWells.Where(var => XYGeometryTools.CalculatePointToPointDistance(var, CurrentPlant.plant) <= distanceInMeters); RaisePropertyChanged("Wells"); }
public void IsPointInPolygon() { XYPolygon xypolygon = new XYPolygon(); xypolygon.Points.Add(new XYPoint(1, 1)); xypolygon.Points.Add(new XYPoint(9, 1)); xypolygon.Points.Add(new XYPoint(5, 5)); xypolygon.Points.Add(new XYPoint(5, 3)); xypolygon.Points.Add(new XYPoint(3, 3)); xypolygon.Points.Add(new XYPoint(3, 8)); xypolygon.Points.Add(new XYPoint(9, 8)); xypolygon.Points.Add(new XYPoint(9, 11)); xypolygon.Points.Add(new XYPoint(1, 11)); Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(2, 2, xypolygon)); Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(2, 4, xypolygon)); Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(2, 10, xypolygon)); Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(7, 10, xypolygon)); Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(4, 2, xypolygon)); Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(7, 2, xypolygon)); Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(6, 3.5, xypolygon)); Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(7.5, 2, xypolygon)); Assert.AreEqual(false, XYGeometryTools.IsPointInPolygon(0, 0, xypolygon)); Assert.AreEqual(false, XYGeometryTools.IsPointInPolygon(4, 4, xypolygon)); Assert.AreEqual(false, XYGeometryTools.IsPointInPolygon(4, 5, xypolygon)); Assert.AreEqual(false, XYGeometryTools.IsPointInPolygon(10, 8, xypolygon)); Assert.AreEqual(false, XYGeometryTools.IsPointInPolygon(9, 12, xypolygon)); Assert.AreEqual(true, XYGeometryTools.IsPointInPolygon(new XYPoint(7.5, 2), xypolygon)); Assert.AreEqual(false, XYGeometryTools.IsPointInPolygon(new XYPoint(0, 0), xypolygon)); }
public void DoLineSegmentsIntersect() { // crossing (using three overloaded methods for the same lines) Assert.AreEqual(true, XYGeometryTools.DoLineSegmentsIntersect(2, 1, 5, 2, 3, 4, 4, 1)); Assert.AreEqual(true, XYGeometryTools.DoLineSegmentsIntersect(new XYPoint(2, 1), new XYPoint(5, 2), new XYPoint(3, 4), new XYPoint(4, 1))); Assert.AreEqual(true, XYGeometryTools.DoLineSegmentsIntersect(new XYLine(2, 1, 5, 2), new XYLine(3, 4, 4, 1))); // too short to cross( using three overloaded methods for the same lines) Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(2, 1, 5, 2, 3, 4, 4, 2)); Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYPoint(2, 1), new XYPoint(5, 2), new XYPoint(3, 4), new XYPoint(4, 2))); Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYLine(2, 1, 5, 2), new XYLine(3, 4, 4, 2))); // Long enough but wrong direction to cross (using three overloaded methods for the same lines) Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(2, 1, 5, 2, 3, 4, 9, 1)); Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYPoint(2, 1), new XYPoint(5, 2), new XYPoint(3, 4), new XYPoint(9, 1))); Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYLine(2, 1, 5, 2), new XYLine(3, 4, 9, 1))); // parallel lines (using three overloaded methods for the same lines) Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(2, 1, 4, 1, 2, 2, 4, 2)); Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYPoint(2, 1), new XYPoint(4, 1), new XYPoint(2, 2), new XYPoint(4, 2))); Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYLine(2, 1, 4, 1), new XYLine(2, 2, 4, 2))); // Two identical lines Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYLine(2, 1, 4, 1), new XYLine(2, 1, 4, 1))); //horizontal lines Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYLine(2, 10, 2, 3), new XYLine(2, 10, 2, 3))); // vertical lines Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYLine(2, 2, 10, 10), new XYLine(2, 2, 10, 10))); // Two line on top of each other but with different length Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYLine(0, 1, 5, 1), new XYLine(2, 1, 4, 1))); //Horizontal lines Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYLine(2, 1, 4, 1), new XYLine(0, 1, 5, 1))); //Horizontal lines Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYLine(2, 1, 3, 4), new XYLine(2, 1, 3, 3))); //Vertical lines Assert.AreEqual(false, XYGeometryTools.DoLineSegmentsIntersect(new XYLine(2, 1, 3, 3), new XYLine(2, 1, 3, 4))); //Vertical lines }
public void CalculatePointToPointDistance() { Assert.AreEqual((double)5, XYGeometryTools.CalculatePointToPointDistance(new XYPoint(1, 1), new XYPoint(4, 5))); Assert.AreEqual((double)5, XYGeometryTools.CalculatePointToPointDistance(new XYPoint(4, 5), new XYPoint(1, 1))); Assert.AreEqual((double)9, XYGeometryTools.CalculatePointToPointDistance(new XYPoint(1, 5), new XYPoint(10, 5))); Assert.AreEqual((double)6, XYGeometryTools.CalculatePointToPointDistance(new XYPoint(4, 2), new XYPoint(4, 8))); }
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 void CalculateIntersectionPoint() { // Testing two overloaded methods with the same lines. Assert.AreEqual(new XYPoint(5, 2.5), XYGeometryTools.CalculateIntersectionPoint(new XYPoint(2, 3.5), new XYPoint(8, 1.5), new XYPoint(2, 1), new XYPoint(8, 4))); Assert.AreEqual(new XYPoint(5, 2.5), XYGeometryTools.CalculateIntersectionPoint(new XYLine(2, 3.5, 8, 1.5), new XYLine(2, 1, 8, 4))); // Intersection between horizontal and vertical lines Assert.AreEqual(new XYPoint(5, 1), XYGeometryTools.CalculateIntersectionPoint(new XYPoint(1, 1), new XYPoint(9, 1), new XYPoint(5, 5), new XYPoint(5, 0))); }
public void CalculateIntersectionPoint_Exception_1() { try { XYGeometryTools.CalculateIntersectionPoint(new XYPoint(2, 3.5), new XYPoint(8, 1.5), new XYPoint(2, 2.5), new XYPoint(8, 0.5)); } catch (Exception ex) { Assert.IsTrue(ex.GetType() == typeof(Exception)); } }
public void CalculatePolylineToPointDistance() { XYPolyline polyline = new XYPolyline(); polyline.Points.Add(new XYPoint(0, 0)); polyline.Points.Add(new XYPoint(1, 1)); polyline.Points.Add(new XYPoint(2, 2)); polyline.Points.Add(new XYPoint(4, 2)); polyline.Points.Add(new XYPoint(6, 0)); Assert.AreEqual(Math.Sqrt(2), XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(-1, -1)), 1e-12, "Test1"); Assert.AreEqual(Math.Sqrt(2), XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(2, 0)), 1e-12, "Test2"); Assert.AreEqual(0, XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(2, 2)), 1e-12, "Test3"); Assert.AreEqual(1, XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(3, 1)), 1e-12, "Test4"); Assert.AreEqual(1, XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(3, 3)), 1e-12, "Test5"); Assert.AreEqual(2, XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(3, 4)), 1e-12, "Test6"); Assert.AreEqual(0, XYGeometryTools.CalculatePolylineToPointDistance(polyline, new XYPoint(6, 0)), 1e-12, "Test7"); }
public void CalculateSharedArea() { XYPolygon p1 = new XYPolygon(); p1.Points.Add(new XYPoint(0, 3)); p1.Points.Add(new XYPoint(3, 0)); p1.Points.Add(new XYPoint(8, 0)); p1.Points.Add(new XYPoint(8, 2)); p1.Points.Add(new XYPoint(3, 1)); p1.Points.Add(new XYPoint(3, 3)); p1.Points.Add(new XYPoint(8, 3)); p1.Points.Add(new XYPoint(4, 7)); XYPolygon p2 = new XYPolygon(); p2.Points.Add(new XYPoint(3, 3)); p2.Points.Add(new XYPoint(4, 3)); p2.Points.Add(new XYPoint(4, 4)); p2.Points.Add(new XYPoint(3, 4)); XYPolygon p3 = new XYPolygon(); p3.Points.Add(new XYPoint(0, 0)); p3.Points.Add(new XYPoint(8, 0)); p3.Points.Add(new XYPoint(8, 8)); p3.Points.Add(new XYPoint(0, 8)); XYPolygon p4 = new XYPolygon(); p4.Points.Add(new XYPoint(-2, 0)); p4.Points.Add(new XYPoint(3, 0)); p4.Points.Add(new XYPoint(3, 2)); p4.Points.Add(new XYPoint(0, 2)); p4.Points.Add(new XYPoint(0, 5)); p4.Points.Add(new XYPoint(4, 5)); p4.Points.Add(new XYPoint(4, 7)); p4.Points.Add(new XYPoint(-2, 7)); Assert.AreEqual(p1.GetArea(), XYGeometryTools.CalculateSharedArea(p1, p1), 1e-12, "Test1 - Polygon1 in Polygon1"); Assert.AreEqual(p2.GetArea(), XYGeometryTools.CalculateSharedArea(p2, p2), 1e-12, "Test2 - Polygon1 in Polygon1"); Assert.AreEqual(p4.GetArea(), XYGeometryTools.CalculateSharedArea(p4, p4), 1e-12, "Test3 - Polygon1 in Polygon1"); Assert.AreEqual(p2.GetArea(), XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12, "Test4 - Polygon2 in Polygon1"); Assert.AreEqual(p1.GetArea(), XYGeometryTools.CalculateSharedArea(p1, p3), 1e-12, "Test5 - Polygon1 in Polygon2"); Assert.AreEqual(4, XYGeometryTools.CalculateSharedArea(p1, p4), 1e-12, "Test6 - Polygon1 in Polygon3"); }
public void OverLapsTest() { int overlap = 0; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); int match = 0; using (Geometry.Shapes.ShapeReader sr = new Geometry.Shapes.ShapeReader(@"F:\Oplandsmodel\Overfladevand\oplande\id15_NSTmodel_24112014.shp")) { using (Geometry.Shapes.ShapeReader sr2 = new Geometry.Shapes.ShapeReader(@"F:\Oplandsmodel\NitrateModel\output\WaterBiasStatRerun06.shp")) { var geom1 = sr.GeoData.ToList(); var geom2 = sr2.GeoData.ToList(); foreach (var pol in geom1) { foreach (var pol2 in geom2) { var f = ((IXYPolygon)pol2.Geometry).OverLaps((IXYPolygon)pol.Geometry); if (f) { overlap++; var area = XYGeometryTools.CalculateSharedArea((IXYPolygon)pol.Geometry, (IXYPolygon)pol2.Geometry); if (area / ((IXYPolygon)pol.Geometry).GetArea() > 0.99) { match++; break; } } } } } } sw.Stop(); int k = overlap; }
public void BuildGrid(string ShapeSoilCodes) { using (ShapeReader sr = new ShapeReader(ShapeSoilCodes)) { var Allpoints = sr.GeoData.ToList(); var BornholmPoints = Allpoints.Where(g => int.Parse(g.Data["Model_Doma"].ToString()) == 7).ToList(); var OtherPoints = Allpoints.Where(g => int.Parse(g.Data["Model_Doma"].ToString()) != 7).ToList(); var bbox = XYGeometryTools.BoundingBox(OtherPoints.Select(f => (IXYPoint)f.Geometry)); GlobalGrid.GridSize = 500.0; GlobalGrid.XOrigin = bbox.Points.Min(p => p.X); GlobalGrid.YOrigin = bbox.Points.Min(p => p.Y); GlobalGrid.NumberOfColumns = (int)(Math.Round((bbox.Points.Max(p => p.X) - GlobalGrid.XOrigin) / GlobalGrid.GridSize, 0)) + 1; GlobalGrid.NumberOfRows = (int)(Math.Round((bbox.Points.Max(p => p.Y) - GlobalGrid.YOrigin) / GlobalGrid.GridSize, 0) + 1); foreach (var g in OtherPoints) { GlobalGrid.Data[GlobalGrid.GetColumnIndex(((IXYPoint)g.Geometry).X), GlobalGrid.GetRowIndex(((IXYPoint)g.Geometry).Y)] = int.Parse(g.Data["GRIDID"].ToString()); } bbox = XYGeometryTools.BoundingBox(BornholmPoints.Select(f => (IXYPoint)f.Geometry)); BornholmGrid.GridSize = 250.0; BornholmGrid.XOrigin = bbox.Points.Min(p => p.X); BornholmGrid.YOrigin = bbox.Points.Min(p => p.Y); BornholmGrid.NumberOfColumns = (int)(Math.Round((bbox.Points.Max(p => p.X) - BornholmGrid.XOrigin) / BornholmGrid.GridSize, 0)) + 1; BornholmGrid.NumberOfRows = (int)(Math.Round((bbox.Points.Max(p => p.Y) - BornholmGrid.YOrigin) / BornholmGrid.GridSize, 0) + 1); foreach (var g in BornholmPoints) { int id = int.Parse(g.Data["GRIDID"].ToString()); BornholmerID.Add(id, id); BornholmGrid.Data[BornholmGrid.GetColumnIndex(((IXYPoint)g.Geometry).X), BornholmGrid.GetRowIndex(((IXYPoint)g.Geometry).Y)] = id; } } }
/// <summary> /// Calculates the theis drawdown. Pumpingrate is positive for injection. Pumpingrate and transmissivity time units should be seconds /// </summary> /// <param name="PumpingWell"></param> /// <param name="PumpingRate"></param> /// <param name="Storativity"></param> /// <param name="Transmissivity"></param> /// <param name="Time"></param> /// <param name="ObservationPoint"></param> /// <returns></returns> public double Drawdown(IXYPoint PumpingWell, double PumpingRate, double Storativity, double Transmissivity, TimeSpan Time, IXYPoint ObservationPoint) { double r = XYGeometryTools.CalculatePointToPointDistance(PumpingWell, ObservationPoint); return((PumpingRate / (4 * Math.PI * Transmissivity)) * W(r, Storativity, Transmissivity, Time.TotalSeconds)); }
public void CalculateLengthOfPolylineInsidePolygon() { XYPolygon xypolygon = new XYPolygon(); xypolygon.Points.Add(new XYPoint(1, 1)); xypolygon.Points.Add(new XYPoint(9, 1)); xypolygon.Points.Add(new XYPoint(5, 5)); xypolygon.Points.Add(new XYPoint(5, 3)); xypolygon.Points.Add(new XYPoint(3, 3)); xypolygon.Points.Add(new XYPoint(3, 8)); xypolygon.Points.Add(new XYPoint(9, 8)); xypolygon.Points.Add(new XYPoint(9, 11)); xypolygon.Points.Add(new XYPoint(1, 11)); XYPolyline xypolyline = new XYPolyline(); xypolyline.Points.Add(new XYPoint(9, 13)); xypolyline.Points.Add(new XYPoint(7, 12)); xypolyline.Points.Add(new XYPoint(7, 10)); xypolyline.Points.Add(new XYPoint(2, 10)); xypolyline.Points.Add(new XYPoint(2, 3)); Assert.AreEqual(13, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(xypolyline, xypolygon)); XYPolygon rectangle = new XYPolygon(); rectangle.Points.Add(new XYPoint(10, 10)); rectangle.Points.Add(new XYPoint(20, 10)); rectangle.Points.Add(new XYPoint(20, 40)); rectangle.Points.Add(new XYPoint(10, 40)); XYPolyline line1 = new XYPolyline(); line1.Points.Add(new XYPoint(0, 20)); line1.Points.Add(new XYPoint(30, 20)); Assert.AreEqual(10, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line1, rectangle)); // horizontal line crossing XYPolyline line2 = new XYPolyline(); line2.Points.Add(new XYPoint(10, 20)); line2.Points.Add(new XYPoint(20, 20)); Assert.AreEqual(10, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line2, rectangle)); // fits inside XYPolyline line3 = new XYPolyline(); line3.Points.Add(new XYPoint(0, 40)); line3.Points.Add(new XYPoint(30, 40)); Assert.AreEqual(5, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line3, rectangle)); XYPolyline line4 = new XYPolyline(); line4.Points.Add(new XYPoint(20, 40)); line4.Points.Add(new XYPoint(20, 0)); Assert.AreEqual(15, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line4, rectangle)); XYPolyline line5 = new XYPolyline(); line5.Points.Add(new XYPoint(20, 40)); line5.Points.Add(new XYPoint(20, 10)); Assert.AreEqual(15, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line5, rectangle)); XYPolyline line6 = new XYPolyline(); line6.Points.Add(new XYPoint(10, 40)); line6.Points.Add(new XYPoint(30, 40)); Assert.AreEqual(5, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line6, rectangle)); XYPolyline line7 = new XYPolyline(); line7.Points.Add(new XYPoint(10, 20)); line7.Points.Add(new XYPoint(30, 20)); Assert.AreEqual(10, XYGeometryTools.CalculateLengthOfPolylineInsidePolygon(line7, rectangle)); }
public void CalculateSharedAreaNonTrivial() { int numFailed = 0; { XYPolygon p1 = new XYPolygon(); p1.Points.Add(new XYPoint(105.53344586732879, 454.15364801254128)); p1.Points.Add(new XYPoint(122.15618253108046, 428.47512721589305)); p1.Points.Add(new XYPoint(136.1095555912604, 453.25736756177577)); XYPolygon p2 = new XYPolygon(); p2.Points.Add(new XYPoint(120, 440)); p2.Points.Add(new XYPoint(120, 480)); p2.Points.Add(new XYPoint(80, 480)); Assert.AreEqual(97.0970145705396, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-10); } // ------------------------------------------------- // The following triangles should overlap a bit more than // 25% of p2 (25% of 50), i.e. around 14 { XYPolygon p2 = new XYPolygon(); p2.Points.Add(new XYPoint(10, 0)); p2.Points.Add(new XYPoint(10, 10)); p2.Points.Add(new XYPoint(0, 10)); // Previous version failed on 3 of 4 of the following cases of p1 XYPolygon p1 = new XYPolygon(); p1.Points.Add(new XYPoint(15, 7)); p1.Points.Add(new XYPoint(5, 4.9)); p1.Points.Add(new XYPoint(12, -2.5)); Assert.AreEqual(14.629132231405, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); p1 = new XYPolygon(); p1.Points.Add(new XYPoint(15, 7)); p1.Points.Add(new XYPoint(5, 4.9)); p1.Points.Add(new XYPoint(12, -2.0)); Assert.AreEqual(14.629132231405, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); p1 = new XYPolygon(); p1.Points.Add(new XYPoint(15, 7)); p1.Points.Add(new XYPoint(5, 4.9)); p1.Points.Add(new XYPoint(12, -1.5)); Assert.AreEqual(13.9993703266431, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); p1 = new XYPolygon(); p1.Points.Add(new XYPoint(15, 7)); p1.Points.Add(new XYPoint(5, 5)); p1.Points.Add(new XYPoint(12, -2.5)); Assert.AreEqual(15, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); } { XYPolygon p2 = new XYPolygon(); p2.Points.Add(new XYPoint(10, 0)); p2.Points.Add(new XYPoint(10, 10)); p2.Points.Add(new XYPoint(0, 10)); // Sharing a common side, p1 side fully part of p2 side, p1 inside p2 XYPolygon p1 = new XYPolygon(); p1.Points.Add(new XYPoint(8, 8)); p1.Points.Add(new XYPoint(2, 8)); p1.Points.Add(new XYPoint(8, 2)); Assert.AreEqual(18, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); // Sharing a common side, p1 side fully part of p2 side, p1 outside p2 p1 = new XYPolygon(); p1.Points.Add(new XYPoint(8, 2)); p1.Points.Add(new XYPoint(2, 8)); p1.Points.Add(new XYPoint(2, 2)); Assert.AreEqual(0, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); // Sharing a common side, sides overlapping, polygons overlapping p1 = new XYPolygon(); p1.Points.Add(new XYPoint(12, 8)); p1.Points.Add(new XYPoint(2, 8)); p1.Points.Add(new XYPoint(12, -2)); Assert.AreEqual(32, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); // Sharing a common side, sides overlapping, polygons not overlapping p1 = new XYPolygon(); p1.Points.Add(new XYPoint(12, -2)); p1.Points.Add(new XYPoint(2, 8)); p1.Points.Add(new XYPoint(2, -2)); Assert.AreEqual(0, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); // p1 outside p2, sharing one point only p1 = new XYPolygon(); p1.Points.Add(new XYPoint(5, 0)); p1.Points.Add(new XYPoint(8, 2)); p1.Points.Add(new XYPoint(4, 3)); Assert.AreEqual(0, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); // p1 almost outside p2, sharing one point just inside p2 only p1 = new XYPolygon(); p1.Points.Add(new XYPoint(5, 0)); p1.Points.Add(new XYPoint(8, 2.0001)); p1.Points.Add(new XYPoint(4, 3)); Assert.AreEqual(3.66653035e-9, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); // p1 inside p2, sharing one point only p1 = new XYPolygon(); p1.Points.Add(new XYPoint(5, 8)); p1.Points.Add(new XYPoint(2, 8)); p1.Points.Add(new XYPoint(9, 4)); Assert.AreEqual(6.0, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); // Intersection of jewish-like star p1 = new XYPolygon(); p1.Points.Add(new XYPoint(2, 2)); p1.Points.Add(new XYPoint(12, 3)); p1.Points.Add(new XYPoint(3, 12)); Assert.AreEqual(30.37272727272727, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); // Intersection of jewish-like star where one line is "too high", and exactly hits a // point of the other polygon // Hit with overlap p1 = new XYPolygon(); p1.Points.Add(new XYPoint(2, 2)); p1.Points.Add(new XYPoint(12, 8.9999)); p1.Points.Add(new XYPoint(8, 11)); Assert.AreEqual(16.878689085945744, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); // Exact hit p1 = new XYPolygon(); p1.Points.Add(new XYPoint(2, 2)); p1.Points.Add(new XYPoint(12, 9)); p1.Points.Add(new XYPoint(8, 11)); Assert.AreEqual(16.878431372549, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); // No hit p1 = new XYPolygon(); p1.Points.Add(new XYPoint(2, 2)); p1.Points.Add(new XYPoint(12, 9.0001)); p1.Points.Add(new XYPoint(8, 11)); Assert.AreEqual(16.878173655919, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-12); } // Point on line, or close to line { XYPolygon p1 = new XYPolygon(); p1.Points.Add(new XYPoint(3, 10)); p1.Points.Add(new XYPoint(1, 10)); p1.Points.Add(new XYPoint(2, 0)); XYPolygon p2 = new XYPolygon(); p2.Points.Add(new XYPoint(4, 1e-4)); p2.Points.Add(new XYPoint(0, 1e-4)); p2.Points.Add(new XYPoint(2, -4)); Assert.AreEqual(0, XYGeometryTools.CalculateSharedArea(p1, p2), 1e-9); } { XYPolygon p1 = new XYPolygon(); p1.Points.Add(new XYPoint(3, 10)); p1.Points.Add(new XYPoint(1, 10)); p1.Points.Add(new XYPoint(2, 0)); XYPolygon p2 = new XYPolygon(); p2.Points.Add(new XYPoint(4, 1e-12)); p2.Points.Add(new XYPoint(2, 10)); p2.Points.Add(new XYPoint(0, 1e-12)); Console.Out.WriteLine("area = " + XYGeometryTools.CalculateSharedArea(p1, p2)); } // Sharing one point { XYPolygon p1 = new XYPolygon(); p1.Points.Add(new XYPoint(3, 10)); p1.Points.Add(new XYPoint(1, 10)); p1.Points.Add(new XYPoint(2, 0)); XYPolygon p2 = new XYPolygon(); p2.Points.Add(new XYPoint(3, 10)); p2.Points.Add(new XYPoint(2, 0)); p2.Points.Add(new XYPoint(1, 10)); try { Console.Out.WriteLine("area = " + XYGeometryTools.CalculateSharedArea(p1, p2)); } catch (Exception) { Console.Out.WriteLine("failed"); numFailed++; } } // Overlapping slightly in one point, area should be very small { XYPolygon p1 = new XYPolygon(); p1.Points.Add(new XYPoint(3, 10)); p1.Points.Add(new XYPoint(1, 10)); p1.Points.Add(new XYPoint(2, 0)); XYPolygon p2 = new XYPolygon(); p2.Points.Add(new XYPoint(3, -10)); p2.Points.Add(new XYPoint(2, 1e-4)); p2.Points.Add(new XYPoint(1, -10)); try { Console.Out.WriteLine("area = " + XYGeometryTools.CalculateSharedArea(p1, p2)); } catch (Exception) { Console.Out.WriteLine("failed"); numFailed++; } } // Sharing a line approximately, no (extremely small) overlap { XYPolygon p1 = new XYPolygon(); p1.Points.Add(new XYPoint(-233.870971679688, 73.7704925537109)); p1.Points.Add(new XYPoint(-241.935485839844, 81.9672164916992)); p1.Points.Add(new XYPoint(-241.935485839844, 73.7704925537109)); XYPolygon p2 = new XYPolygon(); p2.Points.Add(new XYPoint(-230, 70)); p2.Points.Add(new XYPoint(-230, 80)); p2.Points.Add(new XYPoint(-240, 80)); try { Console.Out.WriteLine("area = " + XYGeometryTools.CalculateSharedArea(p1, p2)); } catch (Exception) { Console.Out.WriteLine("failed"); numFailed++; } } if (numFailed > 0) { Assert.Fail("Number of failures: " + numFailed); } }
private void panelViewer_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { // write x and y coordinates double x = ((e.X - _margin) / _scale) + _minX; double y = _minY - (e.Y + _margin - panelViewer.ClientSize.Height) / _scale; if (_scale != double.MaxValue) { this.label3.Text = "(" + x.ToString("F3") + ", " + y.ToString("F3") + ")"; } else { this.label3.Text = ""; } // write elementSet ID and element index this.label4.Text = " "; this.label7.Text = " "; this.label8.Text = " "; this.label9.Text = " "; this.label10.Text = " "; this.label11.Text = " "; for (int elementSetNumber = 0; elementSetNumber < this._elementSets.Count; elementSetNumber++) { string elementID = " "; int elementIndex = -9; double distance = 10e30; IElementSet elementSet = (IElementSet)_elementSets[elementSetNumber]; if (elementSetNumber == 0) { this.label7.Text = elementSet.Caption.Substring(0, Math.Min(20, elementSet.Caption.Length)); } if (elementSetNumber == 1) { this.label9.Text = elementSet.Caption.Substring(0, Math.Min(20, elementSet.Caption.Length)); } for (int index = 0; index < elementSet.ElementCount; index++) { if (((IElementSet)_elementSets[elementSetNumber]).ElementType == ElementType.Polygon) { XYPolygon xyPolygon = new XYPolygon(); for (int i = 0; i < elementSet.GetVertexCount(index); i++) { xyPolygon.Points.Add(new XYPoint(elementSet.GetVertexXCoordinate(index, i), elementSet.GetVertexYCoordinate(index, i))); } if (XYGeometryTools.IsPointInPolygon(x, y, xyPolygon)) { elementID = elementSet.GetElementId(index).Id; elementIndex = index; } } if (((IElementSet)_elementSets[elementSetNumber]).ElementType == ElementType.PolyLine) { XYPolyline xyPolyline = new XYPolyline(); for (int i = 0; i < elementSet.GetVertexCount(index); i++) { xyPolyline.Points.Add(new XYPoint(elementSet.GetVertexXCoordinate(index, i), elementSet.GetVertexYCoordinate(index, i))); } double xx = XYGeometryTools.CalculatePolylineToPointDistance(xyPolyline, new XYPoint(x, y)); if (xx < distance) { distance = xx; if (xx < 0.3 * xyPolyline.GetLength()) { elementIndex = index; elementID = elementSet.GetElementId(index).Id; } } } if (elementSetNumber == 0 && elementIndex >= 0) { this.label4.Text = "Index: " + elementIndex.ToString(); this.label8.Text = "ID: " + elementID.Substring(0, Math.Min(17, elementID.Length)); } if (elementSetNumber == 1 && elementIndex >= 0) { this.label10.Text = "Index: " + elementIndex.ToString(); this.label11.Text = "ID: " + elementID.Substring(0, Math.Min(17, elementID.Length)); } } } }
public double GetReduction(Catchment c, double CurrentMass, DateTime CurrentTime) { double red = 0; var CurrentWetLands = c.Wetlands.Where(w => w.StartTime <= CurrentTime).ToList(); if (CurrentWetLands.Count > 0) { if (CurrentTime > new DateTime(2010, 1, 1)) { int k = 0; } var precip = c.Precipitation.GetTs(TimeStepUnit.Month).GetValue(CurrentTime); double accurain = c.Precipitation.GetTs(TimeStepUnit.Month).Average; double afs = Math.Abs((precip - accurain) / accurain * Par1 + Par2); foreach (var w in CurrentWetLands) { red += SoilEquations[w.SoilString].GetReduction(CurrentTime, afs) * XYGeometryTools.CalculateSharedArea(c.Geometry, w.Geometry) / 10000.0; } //Make sure we do not reduce more than what is available red = Math.Max(0, Math.Min(CurrentMass, red)); red /= (DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month) * 86400.0); } red = red * MultiplicationPar + AdditionPar; if (MultiplicationFactors != null) { if (MultiplicationFactors.ContainsKey(c.ID)) { red *= MultiplicationFactors[c.ID]; } } if (AdditionFactors != null) { if (AdditionFactors.ContainsKey(c.ID)) { red += AdditionFactors[c.ID]; } } return(red); }
public void CalculateIntersectionPoint_Exception_2() { XYGeometryTools.CalculateIntersectionPoint(new XYPoint(0, 1), new XYPoint(1, 1.5), new XYPoint(1, 1.5), new XYPoint(8, 0.5)); }
public void CalculateIntersectionPoint_Exception_1() { XYGeometryTools.CalculateIntersectionPoint(new XYPoint(2, 3.5), new XYPoint(8, 1.5), new XYPoint(2, 2.5), new XYPoint(8, 0.5)); }