Esempio n. 1
0
        /// Update the bounding box of the path
        void UpdateBounds()
        {
            if (boundsUpToDate)
            {
                return;
            }

            // Loop through all segments and keep track of the minmax points of all their bounding boxes
            MinMax3D minMax = new MinMax3D();

            for (int i = 0; i < NumSegments; i++)
            {
                Vector3[] p = GetPointsInSegment(i);
                minMax.AddValue(p[0]);
                minMax.AddValue(p[3]);

                List <float> extremePointTimes = CubicBezierUtility.ExtremePointTimes(p[0], p[1], p[2], p[3]);
                foreach (float t in extremePointTimes)
                {
                    minMax.AddValue(CubicBezierUtility.EvaluateCurve(p, t));
                }
            }

            boundsUpToDate = true;
            bounds         = new Bounds((minMax.Min + minMax.Max) / 2, minMax.Max - minMax.Min);
        }
Esempio n. 2
0
        /// Update the bounding box of the path
        public Bounds CalculateBoundsWithTransform(Transform transform)
        {
            // Loop through all segments and keep track of the minmax points of all their bounding boxes
            MinMax3D minMax = new MinMax3D();

            for (int i = 0; i < NumSegments; i++)
            {
                Vector3[] p = GetPointsInSegment(i);
                for (int j = 0; j < p.Length; j++)
                {
                    p[j] = MathUtility.TransformPoint(p[j], transform, space);
                }

                minMax.AddValue(p[0]);
                minMax.AddValue(p[3]);

                List <float> extremePointTimes = CubicBezierUtility.ExtremePointTimes(p[0], p[1], p[2], p[3]);
                foreach (float t in extremePointTimes)
                {
                    minMax.AddValue(CubicBezierUtility.EvaluateCurve(p, t));
                }
            }

            return(new Bounds((minMax.Min + minMax.Max) / 2, minMax.Max - minMax.Min));
        }