Esempio n. 1
0
        private void GetRoundedCornerPoints(List <Vector2> points, EdgeControl.EdgeCornerSweepValues corner, Direction closestPortDirection)
        {
            int  num  = Mathf.CeilToInt((float)Math.Abs(corner.sweepAngle * 4.0));
            int  num2 = Math.Sign(corner.sweepAngle);
            bool flag = closestPortDirection == Direction.Input;
            int  i    = 0;

            while (i < num)
            {
                float  num3 = (float)((!flag) ? i : (i - num));
                double num4 = corner.startAngle + (double)((float)num2 * num3 / 4f);
                float  num5 = (float)((double)corner.circleCenter.x + Math.Cos(num4) * (double)corner.radius);
                float  num6 = (float)((double)corner.circleCenter.y + Math.Sin(num4) * (double)corner.radius);
                if (i == 0 && flag)
                {
                    if (this.orientation == Orientation.Horizontal)
                    {
                        if (corner.sweepAngle < 0.0 && points[points.Count - 1].y > num6)
                        {
                            goto IL_1B4;
                        }
                        if (corner.sweepAngle >= 0.0 && points[points.Count - 1].y < num6)
                        {
                            goto IL_1B4;
                        }
                    }
                    else
                    {
                        if (corner.sweepAngle < 0.0 && points[points.Count - 1].x < num5)
                        {
                            goto IL_1B4;
                        }
                        if (corner.sweepAngle >= 0.0 && points[points.Count - 1].x > num5)
                        {
                            goto IL_1B4;
                        }
                    }
                    goto IL_1A4;
                }
                goto IL_1A4;
IL_1B4:
                i++;
                continue;
IL_1A4:
                points.Add(new Vector2(num5, num6));
                goto IL_1B4;
            }
        }
Esempio n. 2
0
        private EdgeControl.EdgeCornerSweepValues GetCornerSweepValues(Vector2 p1, Vector2 cornerPoint, Vector2 p2, float diameter, Direction closestPortDirection)
        {
            EdgeControl.EdgeCornerSweepValues result = default(EdgeControl.EdgeCornerSweepValues);
            result.radius = diameter / 2f;
            Vector2 normalized  = (cornerPoint - p1).normalized;
            Vector2 vector      = normalized * diameter;
            float   x           = vector.x;
            float   y           = vector.y;
            Vector2 normalized2 = (cornerPoint - p2).normalized;
            Vector2 vector2     = normalized2 * diameter;
            float   x2          = vector2.x;
            float   y2          = vector2.y;
            float   num         = (float)(Math.Atan2((double)y, (double)x) - Math.Atan2((double)y2, (double)x2)) / 2f;
            float   num2        = (float)Math.Abs(Math.Tan((double)num));
            float   num3        = result.radius / num2;

            if (num3 > diameter)
            {
                num3          = diameter;
                result.radius = diameter * num2;
            }
            result.crossPoint1  = cornerPoint - normalized * num3;
            result.crossPoint2  = cornerPoint - normalized2 * num3;
            result.circleCenter = this.GetCornerCircleCenter(cornerPoint, result.crossPoint1, result.crossPoint2, num3, result.radius);
            result.startAngle   = Math.Atan2((double)(result.crossPoint1.y - result.circleCenter.y), (double)(result.crossPoint1.x - result.circleCenter.x));
            result.endAngle     = Math.Atan2((double)(result.crossPoint2.y - result.circleCenter.y), (double)(result.crossPoint2.x - result.circleCenter.x));
            result.sweepAngle   = result.endAngle - result.startAngle;
            if (closestPortDirection == Direction.Input)
            {
                double endAngle = result.endAngle;
                result.endAngle   = result.startAngle;
                result.startAngle = endAngle;
            }
            if (result.sweepAngle > 3.1415926535897931)
            {
                result.sweepAngle = -6.2831853071795862 + result.sweepAngle;
            }
            else if (result.sweepAngle < -3.1415926535897931)
            {
                result.sweepAngle = 6.2831853071795862 + result.sweepAngle;
            }
            return(result);
        }
Esempio n. 3
0
        private void ValidateCornerSweepValues(ref EdgeControl.EdgeCornerSweepValues corner1, ref EdgeControl.EdgeCornerSweepValues corner2)
        {
            Vector2 b       = (corner1.circleCenter + corner2.circleCenter) / 2f;
            Vector2 vector  = corner1.circleCenter - corner1.crossPoint1;
            Vector2 vector2 = corner1.circleCenter - b;
            double  num     = (this.orientation != Orientation.Horizontal) ? (Math.Atan2((double)vector.x, (double)vector.y) - Math.Atan2((double)vector2.x, (double)vector2.y)) : (Math.Atan2((double)vector.y, (double)vector.x) - Math.Atan2((double)vector2.y, (double)vector2.x));

            num = (double)((float)(Math.Sign(num) * 2) * 3.14159274f) - num;
            if ((double)Mathf.Abs((float)num) > 4.71238911151886)
            {
                num = (double)((float)(-1 * Math.Sign(num) * 2) * 3.14159274f) + num;
            }
            float magnitude = vector2.magnitude;
            float num2      = Mathf.Acos(corner1.radius / magnitude);
            float a         = Mathf.Abs((float)corner1.sweepAngle) - num2 * 2f;

            if (Mathf.Abs((float)num) < Mathf.Abs((float)corner1.sweepAngle))
            {
                corner1.sweepAngle = (double)((float)Math.Sign(corner1.sweepAngle) * Mathf.Min(a, Mathf.Abs((float)corner1.sweepAngle)));
                corner2.sweepAngle = (double)((float)Math.Sign(corner2.sweepAngle) * Mathf.Min(a, Mathf.Abs((float)corner2.sweepAngle)));
            }
        }
Esempio n. 4
0
 protected virtual void UpdateRenderPoints()
 {
     this.ComputeControlPoints();
     if (this.m_RenderPointsDirty || this.m_ControlPoints == null)
     {
         this.m_RenderPointsDirty = false;
         this.m_MeshDirty         = true;
         this.m_RenderPoints.Clear();
         float   num     = 16f;
         Vector2 vector  = base.parent.ChangeCoordinatesTo(this, this.m_ControlPoints[0]);
         Vector2 vector2 = base.parent.ChangeCoordinatesTo(this, this.m_ControlPoints[1]);
         Vector2 vector3 = base.parent.ChangeCoordinatesTo(this, this.m_ControlPoints[2]);
         Vector2 vector4 = base.parent.ChangeCoordinatesTo(this, this.m_ControlPoints[3]);
         if ((this.orientation == Orientation.Horizontal && Mathf.Abs(vector.y - vector4.y) < 2f && vector.x + 12f < vector4.x - 12f) || (this.orientation == Orientation.Vertical && Mathf.Abs(vector.x - vector4.x) < 2f && vector.y + 12f < vector4.y - 12f))
         {
             float num2 = (this.orientation != Orientation.Horizontal) ? Mathf.Abs(vector.y + 12f - (vector4.y - 12f)) : Mathf.Abs(vector.x + 12f - (vector4.x - 12f));
             float a    = num2 / 5f;
             float num3 = Mathf.Min(a, num);
             num3 = Mathf.Max(0f, num3);
             Vector2 b = (this.orientation != Orientation.Horizontal) ? new Vector2(0f, num - num3) : new Vector2(num - num3, 0f);
             this.m_RenderPoints.Add(vector);
             this.m_RenderPoints.Add(vector2 - b);
             this.m_RenderPoints.Add(vector3 + b);
             this.m_RenderPoints.Add(vector4);
         }
         else
         {
             this.m_RenderPoints.Add(vector);
             EdgeControl.EdgeCornerSweepValues cornerSweepValues  = this.GetCornerSweepValues(vector, vector2, vector3, num, Direction.Output);
             EdgeControl.EdgeCornerSweepValues cornerSweepValues2 = this.GetCornerSweepValues(vector2, vector3, vector4, num, Direction.Input);
             this.ValidateCornerSweepValues(ref cornerSweepValues, ref cornerSweepValues2);
             this.GetRoundedCornerPoints(this.m_RenderPoints, cornerSweepValues, Direction.Output);
             this.GetRoundedCornerPoints(this.m_RenderPoints, cornerSweepValues2, Direction.Input);
             this.m_RenderPoints.Add(vector4);
         }
     }
 }