public void ConvexHullTest(string points, string expected) { var testPoints = (from x in points.Split(';') select Point2D.Parse(x)).ToList(); var expectedPoints = (from x in expected.Split(';') select Point2D.Parse(x)).ToList(); var hullClockwise = Polygon2D.GetConvexHullFromPoints(testPoints, true); var clockwiseVertices = hullClockwise.Vertices; CollectionAssert.AreEqual(expectedPoints, clockwiseVertices); /* * for (var i = 0; i < hullClockwise.VertexCount; i++) * { * Assert.That(ClockwiseVerticies[i], Is.EqualTo(expectedPoints[i])); * } */ var hullCounterClockwise = Polygon2D.GetConvexHullFromPoints(testPoints, false); var counterClockwiseVertices = hullCounterClockwise.Vertices; expectedPoints.Reverse(); CollectionAssert.AreEqual(expectedPoints, counterClockwiseVertices); /* * for (var i = 0; i < hullCounterClockwise.VertexCount; i++) * { * Assert.That(counterClockwiseVerticies[i], Is.EqualTo(expectedPoints[hullCounterClockwise.VertexCount - 1 - i])); * } */ var pointsNotOnConvexHull = testPoints.Except(hullCounterClockwise.Vertices); foreach (var pointNotOnConvexHull in pointsNotOnConvexHull) { var pointIsInsideConvexHull = hullCounterClockwise.EnclosesPoint(pointNotOnConvexHull); Assert.That(pointIsInsideConvexHull); } // second check: if we remove any point from the convex hull and build a new convex hull // then that point should be outside the new convex hull; if it's inside then our new // convex hull is the actual convex hull, which means the original one wasn't! foreach (var pointToRemove in counterClockwiseVertices) { var convexHullWithPointRemoved = new Polygon2D(hullCounterClockwise.Vertices.Except(new[] { pointToRemove })); var pointIsInsideConvexHull = convexHullWithPointRemoved.EnclosesPoint(pointToRemove); Assert.That(pointIsInsideConvexHull, Is.Not.True); } }
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); }