Пример #1
0
        private void SetupCollinearHandlesConstraint(int index, bool enforceConstraint)
        {
            PathFigureEditor pathFigureEditor = new PathFigureEditor(this.figure);

            if (!pathFigureEditor.HasDownstreamBezierHandleNeighbor(index) || !pathFigureEditor.HasUpstreamBezierHandleNeighbor(index))
            {
                return;
            }
            Point  point = pathFigureEditor.GetPoint(index);
            Vector a     = pathFigureEditor.GetPoint(index - 1) - point;
            Vector b     = pathFigureEditor.GetPoint(index + 1) - point;

            if (!enforceConstraint || VectorUtilities.HaveOppositeDirections(a, b))
            {
                return;
            }
            double length1 = a.Length;
            double length2 = b.Length;

            if (length1 > length2)
            {
                a.Normalize();
                b = -a * length2;
                pathFigureEditor.SetPoint(index + 1, point + b);
            }
            else
            {
                b.Normalize();
                Vector vector = -b * length1;
                pathFigureEditor.SetPoint(index - 1, point - vector);
            }
        }