public void Protected_TriangleIntersectionArea() { XYPolygon t1 = new XYPolygon(); t1.Points.Add(new XYPoint(0.0, 0.5)); t1.Points.Add(new XYPoint(6.0, 0.5)); t1.Points.Add(new XYPoint(1.0, 7.0)); XYPolygon t2 = new XYPolygon(); t2.Points.Add(new XYPoint(1, 1)); t2.Points.Add(new XYPoint(5, 1)); t2.Points.Add(new XYPoint(1, 5)); XYPolygon t3 = new XYPolygon(); t3.Points.Add(new XYPoint(1, 1)); t3.Points.Add(new XYPoint(3, 1)); t3.Points.Add(new XYPoint(1, 3)); XYPolygon t4 = new XYPolygon(); t4.Points.Add(new XYPoint(1, 2)); t4.Points.Add(new XYPoint(3, 2)); t4.Points.Add(new XYPoint(3, 4)); XYPolygon t5 = new XYPolygon(); t5.Points.Add(new XYPoint(6.5, 3.5)); t5.Points.Add(new XYPoint(9.5, 3.4)); t5.Points.Add(new XYPoint(7, 5)); XYPolygon t6 = new XYPolygon(); t6.Points.Add(new XYPoint(-2, 0)); t6.Points.Add(new XYPoint(3, 0)); t6.Points.Add(new XYPoint(3, 2)); //t2 is fully inside t1 Assert.AreEqual(8, AXYGeometryTools.ATriangleIntersectionArea(t2, t1), "t2, t1"); Assert.AreEqual(8, AXYGeometryTools.ATriangleIntersectionArea(t1, t2), "t1, t2"); // t4 is partly inside t2 Assert.AreEqual((double)7 / (double)4, AXYGeometryTools.ATriangleIntersectionArea(t2, t4), "t2, t4"); Assert.AreEqual((double)7 / (double)4, AXYGeometryTools.ATriangleIntersectionArea(t4, t2), "t4, t2"); // t3 is inside t2 but is sharing two edges Assert.AreEqual(2, AXYGeometryTools.ATriangleIntersectionArea(t2, t3), "t2, t3"); Assert.AreEqual(2, AXYGeometryTools.ATriangleIntersectionArea(t3, t2), "t3, t2"); // t1 and t5 has no overlap Assert.AreEqual(0, AXYGeometryTools.ATriangleIntersectionArea(t1, t5), "t1, t5"); Assert.AreEqual(0, AXYGeometryTools.ATriangleIntersectionArea(t5, t1), "t5, t1"); // two times t6 Assert.AreEqual(t6.GetArea(), AXYGeometryTools.ATriangleIntersectionArea(t6, t6), "t6, t6"); }
public void Protected_IsPointInLine() { XYPoint point = new XYPoint(); Assert.AreEqual(true, AXYGeometryTools.AIsPointInLine(new XYPoint(0, 0), new XYLine(0, 0, 1, 1)), "Test1"); Assert.AreEqual(true, AXYGeometryTools.AIsPointInLine(new XYPoint(0.5, 0.5), new XYLine(0, 0, 1, 1)), "Test2"); Assert.AreEqual(true, AXYGeometryTools.AIsPointInLine(new XYPoint(1, 1), new XYLine(0, 0, 1, 1)), "Test3"); Assert.AreEqual(false, AXYGeometryTools.AIsPointInLine(new XYPoint(0.5, 0), new XYLine(0, 0, 1, 1)), "Test4"); }
public void Protected_CalculateLineToPointDistance() { Assert.AreEqual(Math.Sqrt(2), AXYGeometryTools.ACalculateLineToPointDistance(new XYLine(0, 2, 2, 0), new XYPoint(2, 2)), 1e-12, "Test1"); Assert.AreEqual(0, AXYGeometryTools.ACalculateLineToPointDistance(new XYLine(0, 2, 2, 0), new XYPoint(1, 1)), 1e-12, "Test2"); Assert.AreEqual(Math.Sqrt(2), AXYGeometryTools.ACalculateLineToPointDistance(new XYLine(0, 2, 2, 0), new XYPoint(3, 1)), 1e-12, "Test3"); Assert.AreEqual(1, AXYGeometryTools.ACalculateLineToPointDistance(new XYLine(0, 2, 2, 0), new XYPoint(3, 0)), 1e-12, "Test4"); Assert.AreEqual(Math.Sqrt(2), AXYGeometryTools.ACalculateLineToPointDistance(new XYLine(0, 2, 2, 0), new XYPoint(3, -1)), 1e-12, "Test5"); Assert.AreEqual(1, AXYGeometryTools.ACalculateLineToPointDistance(new XYLine(0, 2, 2, 0), new XYPoint(2, -1)), 1e-12, "Test6"); Assert.AreEqual(Math.Sqrt(2), AXYGeometryTools.ACalculateLineToPointDistance(new XYLine(0, 2, 2, 0), new XYPoint(1, -1)), 1e-12, "Test1"); }
public void Protected_CalculateSharedLength() { Assert.AreEqual(Math.Sqrt(2), AXYGeometryTools.ACalculateSharedLength(new XYLine(0, 0, 1, 1), new XYLine(0, 0, 1, 1)), "Test1"); Assert.AreEqual(0, AXYGeometryTools.ACalculateSharedLength(new XYLine(0, 0, 1, 1), new XYLine(10, 10, 11, 11)), "Test2"); Assert.AreEqual(Math.Sqrt(2) / 2, AXYGeometryTools.ACalculateSharedLength(new XYLine(0, 0, 1, 1), new XYLine(0.5, 0.5, 10, 10)), "Test3"); Assert.AreEqual(0, AXYGeometryTools.ACalculateSharedLength(new XYLine(1, 1, 1, 3), new XYLine(1, 4, 1, 5)), "Test4 vertical lines"); Assert.AreEqual(1, AXYGeometryTools.ACalculateSharedLength(new XYLine(1, 1, 1, 3), new XYLine(1, 2, 1, 5)), "Test4"); Assert.AreEqual(0, AXYGeometryTools.ACalculateSharedLength(new XYLine(1, 1, 1, 3), new XYLine(2, 1, 2, 5)), "Test5"); Assert.AreEqual(2, AXYGeometryTools.ACalculateSharedLength(new XYLine(7, 3, 10, 3), new XYLine(8, 3, 11, 3)), "Test5"); Assert.AreEqual(0, AXYGeometryTools.ACalculateSharedLength(new XYLine(7, 3, 10, 3), new XYLine(11, 3, 13, 3)), "Test6"); Assert.AreEqual(30, AXYGeometryTools.ACalculateSharedLength(new XYLine(20, 40, 20, 0), new XYLine(20, 40, 20, 10)), "Test7"); Assert.AreEqual(30, AXYGeometryTools.ACalculateSharedLength(new XYLine(20, 40, 20, 10), new XYLine(20, 40, 20, 10)), "Test8"); Assert.AreEqual(30, AXYGeometryTools.ACalculateSharedLength(new XYLine(20, 10, 20, 40), new XYLine(20, 10, 20, 40)), "Test9"); Assert.AreEqual(0, AXYGeometryTools.ACalculateSharedLength(new XYLine(10, 40, 20, 40), new XYLine(20, 40, 20, 10)), "Test10"); }
public void Protected_IsPointInPolygonOrOnEdge() { 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)); Assert.AreEqual(true, AXYGeometryTools.AIsPointInPolygonOrOnEdge(0, 3, p1), "Test1"); Assert.AreEqual(true, AXYGeometryTools.AIsPointInPolygonOrOnEdge(1, 3, p1), "Test2"); Assert.AreEqual(false, AXYGeometryTools.AIsPointInPolygonOrOnEdge(1, 5, p1), "Test3"); Assert.AreEqual(true, AXYGeometryTools.AIsPointInPolygonOrOnEdge(3, 2, p1), "Test4"); Assert.AreEqual(true, AXYGeometryTools.AIsPointInPolygonOrOnEdge(3, 3, p1), "Test5"); Assert.AreEqual(true, AXYGeometryTools.AIsPointInPolygonOrOnEdge(6, 1, p1), "Test6"); Assert.AreEqual(false, AXYGeometryTools.AIsPointInPolygonOrOnEdge(6, 2, p1), "Test7"); Assert.AreEqual(false, AXYGeometryTools.AIsPointInPolygonOrOnEdge(6, 7, p1), "Test8"); }
public void Protected_CalculateLengthOfLineInsidePolygon() { 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(0, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 12, 11, 12), xypolygon), "Test1"); Assert.AreEqual(4, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 11, 11, 11), xypolygon), "Test2"); Assert.AreEqual(8, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 10, 11, 10), xypolygon), "Test3"); Assert.AreEqual(8, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 9, 11, 9), xypolygon), "Test4"); Assert.AreEqual(5, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 8, 11, 8), xypolygon), "Test5"); Assert.AreEqual(2, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 7, 11, 7), xypolygon), "Test6"); Assert.AreEqual(2, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 5, 11, 5), xypolygon), "Test7"); Assert.AreEqual(3, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 4, 11, 4), xypolygon), "Test8"); Assert.AreEqual(3, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 4, 11, 4), xypolygon), "Test9"); Assert.AreEqual(5, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 3, 11, 3), xypolygon), "Test10"); Assert.AreEqual(7, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 2, 11, 2), xypolygon), "Test11"); Assert.AreEqual(4, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 1, 11, 1), xypolygon), "Test12"); Assert.AreEqual(0, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 0, 11, 0), xypolygon), "Test13"); Assert.AreEqual(10, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(2, 12, 2, 0), xypolygon), "Test14"); Assert.AreEqual(6, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(6, 12, 6, 0), xypolygon), "Test15"); Assert.AreEqual(Math.Sqrt(8) + 1.5 * Math.Sqrt(0.5), AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(1, 0.5, 10, 9.5), xypolygon), "Test16"); Assert.AreEqual(1, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(-2, 4, 2, 4), xypolygon), "Test17"); Assert.AreEqual(5, AXYGeometryTools.ACalculateLengthOfLineInsidePolygon(new XYLine(4, 12, 4, 0), xypolygon), "Test18"); }