Пример #1
0
        public OBBox CreateConvex(Vector2[] points)
        {
            if (points.Length == 0)
            {
                Debug.LogError("No points sent!");
            }
            int   pointCount = points.Length;
            OBBox defaultBox = GetBox();
            OBBox output     = defaultBox;
            float minArea    = Mathf.Infinity;

            for (int p = 0; p < pointCount; p++)
            {
                Vector2 p0  = points[p];
                Vector2 p1  = points[(p + 1) % pointCount];
                Vector2 dir = (p1 - p0).normalized;
                if (dir.sqrMagnitude < Mathf.Epsilon)
                {
                    continue;                                  //ignore duplicate points
                }
                float angle = JMath.SignAngle(dir);

                _bounds.Clear();
                for (int o = 0; o < pointCount; o++)//encapsulate rotated points
                {
                    _bounds.Encapsulate(JMath.Rotate(points[o], angle));
                }

                Vector2 center    = JMath.Rotate(_bounds.center, -angle);
                OBBox   candidate = GetBox(center, dir, _bounds.height, JMath.Rotate(dir, 90), _bounds.width);
                if (_bounds.Area() < minArea)
                {
                    if (output != defaultBox)
                    {
                        PutBox(output);
                    }
                    output = candidate;
                }
                else
                {
                    PutBox(candidate);
                }
            }

            return(output);
        }
Пример #2
0
        private void CalculatePlanBounds()
        {
            _bounds.Clear();
            int pointCount = _points.Count;

            for (int p = 0; p < pointCount; p++)
            {
                _bounds.Encapsulate(_points[p].position.vector2);
            }
        }
Пример #3
0
        public static float PolyAreaQuick(Vector2[] points)
        {
            BOUNDS.Clear();
            for (int i = 0; i < points.Length; i++)
            {
                BOUNDS.Encapsulate(points[i]);
            }
            float output = BOUNDS.Area();

            return(output);
        }
 public void ClearSegments()
 {
     _segments.Clear();
     _bounds.Clear();
 }