Exemplo n.º 1
0
        internal void ClearPropertyMap()
        {
            // when clearing the property map we want to retain the styles that we have inherited from elsewhere
            // to do this, we need to read in the inherited values, store them, clear the map, then write the values back
            LightList <StyleProperty> inherited = LightList <StyleProperty> .Get();

            inherited.EnsureCapacity(StyleUtil.InheritedProperties.Count);
            StyleProperty[] inheritedArray = inherited.Array;
            for (int i = 0; i < StyleUtil.InheritedProperties.Count; i++)
            {
                int key = BitUtil.SetHighLowBits(1, (int)StyleUtil.InheritedProperties[i]);
                if (propertyMap.TryGetValue(key, out StyleProperty inheritedValue))
                {
                    inherited.AddUnchecked(inheritedValue);
                }
            }

            propertyMap.Clear();
            // re-apply values
            for (int i = 0; i < inherited.Count; i++)
            {
                int key = BitUtil.SetHighLowBits(1, (int)inheritedArray[i].propertyId);
                propertyMap.Add(key, inheritedArray[i]);
            }

            LightList <StyleProperty> .Release(ref inherited);
        }
Exemplo n.º 2
0
        public static int Arc(LightList <Vector2> output, Vector2 p1, float rx, float ry, float angle, bool largeArcFlag, bool sweepFlag, Vector2 p2, int vpm = 1)
        {
            int originalSize = output.Count;

            float _radian    = (angle * Mathf.PI / 180.0f);
            float _CosRadian = Mathf.Cos(_radian);
            float _SinRadian = Mathf.Sin(_radian);
            float temp1      = (p1.x - p2.x) / 2.0f;
            float temp2      = (p1.y - p2.y) / 2.0f;
            float tx         = (_CosRadian * temp1) + (_SinRadian * temp2);
            float ty         = (-_SinRadian * temp1) + (_CosRadian * temp2);

            double trx2 = rx * rx;
            double try2 = ry * ry;
            double tx2  = tx * tx;
            double ty2  = ty * ty;

            double radiiCheck = tx2 / trx2 + ty2 / try2;

            if (radiiCheck > 1)
            {
                float sqrt = Mathf.Sqrt((float)radiiCheck);
                rx   = sqrt * rx;
                ry   = sqrt * ry;
                trx2 = rx * rx;
                try2 = ry * ry;
            }

            double tm1 = (trx2 * try2 - trx2 * ty2 - try2 * tx2) / (trx2 * ty2 + try2 * tx2);

            tm1 = (tm1 < 0) ? 0 : tm1;

            float tm2 = (largeArcFlag == sweepFlag) ? -Mathf.Sqrt((float)tm1) : Mathf.Sqrt((float)tm1);

            float tcx = tm2 * ((rx * ty) / ry);
            float tcy = tm2 * (-(ry * tx) / rx);

            float cx = _CosRadian * tcx - _SinRadian * tcy + ((p1.x + p2.x) / 2.0f);
            float cy = _SinRadian * tcx + _CosRadian * tcy + ((p1.y + p2.y) / 2.0f);

            float ux = (tx - tcx) / rx;
            float uy = (ty - tcy) / ry;
            float vx = (-tx - tcx) / rx;
            float vy = (-ty - tcy) / ry;

            float n      = Mathf.Sqrt((ux * ux) + (uy * uy));
            float p      = ux;
            float _angle = (uy < 0) ? -Mathf.Acos(p / n) : Mathf.Acos(p / n);

            _angle  = _angle * 180.0f / Mathf.PI;
            _angle %= 360f;

            n = Mathf.Sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy));
            p = ux * vx + uy * vy;
            float t = p / n;

            if ((Mathf.Abs(t) >= 0.99999f) && (Mathf.Abs(t) < 1.000009f))
            {
                t = t > 0 ? 1f : -1f;
            }

            float _delta = (ux * vy - uy * vx < 0) ? -Mathf.Acos(t) : Mathf.Acos(t);

            _delta = _delta * 180.0f / Mathf.PI;

            if (!sweepFlag && _delta > 0)
            {
                _delta -= 360f;
            }
            else if (sweepFlag && _delta < 0)
            {
                _delta += 360f;
            }

            _delta %= 360f;

            int   number = Mathf.RoundToInt(Mathf.Clamp((100f / vpm) * Mathf.Abs(_delta) / 360f, 2, 100));
            float deltaT = _delta / number;

            output.EnsureAdditionalCapacity(number + 1);

            for (int i = 0; i <= number; i++)
            {
                float t_angle = (deltaT * i + _angle) * Mathf.PI / 180.0f;
                float cos     = Mathf.Cos(t_angle);
                float sin     = Mathf.Sin(t_angle);
                output.AddUnchecked(new Vector2(
                                        _CosRadian * rx * cos - _SinRadian * ry * sin + cx,
                                        _SinRadian * rx * cos + _CosRadian * ry * sin + cy
                                        ));
            }

            return(output.Count - originalSize);
        }