private void CalculateWindingDirectionIfNeeded() { if (_windingDirection == WindingDirection.Unknown) // Only if unknown { _windingDirection = (Mathf.Sign(_signedArea) > 0.0f) ? WindingDirection.CCW : WindingDirection.CW; } }
public void UpdatePointPositionsWithTransforms(Transform[] pointTransforms) // Assuming unchanged point count { for (int index = 0; index < pointTransforms.Length; index++) { Transform eachPointTransform = pointTransforms[index]; _points[index] = eachPointTransform.localPosition.xy(); } // Polygon calculations. CalculateBounds(); CalculateArea(); CalculateCentroid(); _windingDirection = WindingDirection.Unknown; CalculateWindingDirectionIfNeeded(); }
public static Polygon PolygonWithPoints(Vector2[] points, WindingDirection windingDirection) { Polygon polygon = new Polygon(points.Length); // Create points (copy actually). for (int index = 0; index < points.Length; index++) { polygon._points[index] = points[index]; } // Polygon calculations. polygon.CalculateBounds(); polygon.CalculateWindingDirectionIfNeeded(); polygon.CalculateArea(); polygon.CalculateCentroid(); // Create members. polygon.CreateVerticesFromPoints(); polygon.CreateEdgesConnectingPoints(); return(polygon); }
// Centering public void RecalculateWindindDirection() { _windingDirection = WindingDirection.Unknown; CalculateWindingDirectionIfNeeded(); }
public static Polygon PolygonWithPointTransforms(Transform[] pointTransforms, WindingDirection windingDirection) // Uses Transform.localPosition.xy() { // Create points array. Vector2[] points = new Vector2[pointTransforms.Length]; for (int index = 0; index < pointTransforms.Length; index++) { Transform eachPointTransform = pointTransforms[index]; points[index] = eachPointTransform.localPosition.xy(); } return(Polygon.PolygonWithPoints(points, windingDirection)); }