diff --git a/Assets/Scripts/AnnotationPass/CityFieldsPass.cs b/Assets/Scripts/AnnotationPass/CityFieldsPass.cs index 1e40aff..68e562e 100644 --- a/Assets/Scripts/AnnotationPass/CityFieldsPass.cs +++ b/Assets/Scripts/AnnotationPass/CityFieldsPass.cs @@ -132,11 +132,7 @@ namespace Assets.AnnotationPass } // remove outside field - city.Fields.RemoveAll(field => - { - var points = field.Boundary.Take(3).ToArray(); - return !PointUtils.IsClockwise(points[0], points[1], points[2]); - }); + city.Fields.RemoveAll(field => !PointUtils.IsClockwise(field.Boundary)); } public void Annotate(Map map) diff --git a/Assets/Scripts/Common/PointUtils.cs b/Assets/Scripts/Common/PointUtils.cs index 1a15d2e..bf3c2a4 100644 --- a/Assets/Scripts/Common/PointUtils.cs +++ b/Assets/Scripts/Common/PointUtils.cs @@ -60,6 +60,11 @@ namespace Assets.Common return xa * yb - xb * ya < 0; } + public static bool IsClockwise(IEnumerable points) + { + return points.Zip(points.RotateRight(), (a, b) => (b.x - a.x) * (b.y + a.y)).Aggregate((a, b) => a + b) < 0; + } + public static bool IsPointInside(Point point, Point[] polygon) { var j = polygon.Length - 1;