public void ClosestPointToTest(string points, string testPoint, string expectedPoint) { var testCurve = new PolyLine2D(from x in points.Split(';') select Point2D.Parse(x)); var test = Point2D.Parse(testPoint); var expected = Point2D.Parse(expectedPoint); Assert.AreEqual(expected, testCurve.ClosestPointTo(test)); }
[TestCase("0,0;0,1;1,1", "0.5,1.5", "0.5,1")] // Off curve public void ClosestPointToTest(string points, string testPoint, string expectedPoint) { var testCurve = new PolyLine2D(from x in points.Split(';') select Point2D.Parse(x)); var test = Point2D.Parse(testPoint); var expected = Point2D.Parse(expectedPoint); Assert.AreEqual(expected, testCurve.ClosestPointTo(test)); }
private static float NormalizedMergeInfluence(Tiles tiles, Point2D currentPoint, PolyLine2D lines, Polygon2D polygon) { double mergeDistance; double minDistance = lines.ClosestPointTo(currentPoint).DistanceTo(currentPoint); if (polygon.EnclosesPoint(currentPoint)) { mergeDistance = minDistance + tiles.MergeWidth; } else { mergeDistance = tiles.MergeWidth - minDistance; if (mergeDistance < 0) { mergeDistance = 0; } } float normalizedMergeInfluence = (float)mergeDistance / (tiles.MergeWidth * 2f); return(normalizedMergeInfluence); }