Ejemplo n.º 1
0
        private static Vector2 BezierCalculatorAdjustVector(float adjustment, BezierCalculatorControlPointDirection dir)
        {
            switch (dir)
            {
            case BezierCalculatorControlPointDirection.Down:
                return(Utils.Down(adjustment));

            case BezierCalculatorControlPointDirection.Up:
                return(Utils.Up(adjustment));

            case BezierCalculatorControlPointDirection.Left:
                return(Utils.Left(adjustment));

            case BezierCalculatorControlPointDirection.Right:
                return(Utils.Right(adjustment));

            case BezierCalculatorControlPointDirection.UpRight:
                return(Utils.UpRight(adjustment));

            case BezierCalculatorControlPointDirection.UpLeft:
                return(Utils.UpLeft(adjustment));

            case BezierCalculatorControlPointDirection.DownRight:
                return(Utils.DownRight(adjustment));

            case BezierCalculatorControlPointDirection.DownLeft:
                return(Utils.DownLeft(adjustment));
            }
            return(new Vector2(0, 0));
        }
Ejemplo n.º 2
0
        public static CalcResult Calc(
            float bezierLengthRequired,
            Vector2 start,
            Vector2 end,
            BezierCalculatorControlPointDirection dir1,
            BezierCalculatorControlPointDirection dir2,
            Vector2 p1Adj = new Vector2(),
            Vector2 p2Adj = new Vector2(),
            int rangeMin  = 1,
            int rangeMax  = 200)
        {
            if (layoutOnly)
            {
                return(new CalcResult());
            }

            int        currentIterationValue  = ((rangeMax - rangeMin) / 2) + rangeMin;
            int        previousIterationValue = 0;
            CalcResult lengthFound            = new CalcResult();

            for (int i = 1; i < 51; i++)
            {
                lengthFound = CalcLength(start, end, dir1, dir2, p1Adj, p2Adj, currentIterationValue);

                if (Math.Abs(bezierLengthRequired - lengthFound.FoundLength) <= 0.3F)
                {
                    //System.Diagnostics.Debug.WriteLine(" BezierCalculator requiredLength=" + bezierLengthRequired + " foundLength=" + lengthFound.FoundLength + " i=" + i);
                    lengthFound.SolutionFound = true;
                    return(lengthFound);
                }

                if (lengthFound.FoundLength > bezierLengthRequired)
                {
                    rangeMax = currentIterationValue;
                }

                if (lengthFound.FoundLength < bezierLengthRequired)
                {
                    rangeMin = currentIterationValue;
                }

                currentIterationValue = ((rangeMax - rangeMin) / 2) + rangeMin;
                if (currentIterationValue == previousIterationValue)
                {
                    break;
                }
                previousIterationValue = currentIterationValue;
                //System.Diagnostics.Debug.WriteLine("currentIterationValue="+currentIterationValue);
            }
            //System.Diagnostics.Debug.WriteLine(description + " Warning - BezierCalculator, no soltion found after 50 iterations");
            lengthFound.SolutionFound = false;
            return(lengthFound);// new CalcResult();
        }
Ejemplo n.º 3
0
        public static CalcResult CalcLength(
            Vector2 start,
            Vector2 end,
            BezierCalculatorControlPointDirection dir1,
            BezierCalculatorControlPointDirection dir2,
            float p1Adj,
            float p2Adj)
        {
            Vector2 firstpoint  = BezierCalculatorAdjustVector(p1Adj, dir1);
            Vector2 secondPoint = BezierCalculatorAdjustVector(p2Adj, dir2);
            float   foundLength = new PartEntityBezier(start, end, start + firstpoint, end + secondPoint).Length;

            return(new CalcResult(firstpoint, secondPoint, foundLength));
        }
Ejemplo n.º 4
0
        private static CalcResult CalcLength(
            Vector2 start,
            Vector2 end,
            BezierCalculatorControlPointDirection dir1,
            BezierCalculatorControlPointDirection dir2,
            Vector2 p1Adj,
            Vector2 p2Adj,
            int i)
        {
            Vector2 firstpoint  = BezierCalculatorAdjustVector(i, dir1) + p1Adj;
            Vector2 secondPoint = BezierCalculatorAdjustVector(i, dir2) + p2Adj;
            float   foundLength = new PartEntityBezier(start, end, start + firstpoint, end + secondPoint).Length;

            return(new CalcResult(firstpoint, secondPoint, foundLength));
        }