From cb2a6b16f3132153a58b6b1675d8135ae081eaef Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Sun, 17 Nov 2019 16:41:35 +0100 Subject: [PATCH] poprawiono usuwanie niepoprawnych dzialek --- Assets/Scripts/AnnotationPass/CityFieldsPass.cs | 6 +----- Assets/Scripts/Common/PointUtils.cs | 5 +++++ 2 files changed, 6 insertions(+), 5 deletions(-) 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;