Example #1
0
        private static double ClipTest(Vector spineVector, double beginRadius, double endRadius, Vector hitBegin, Vector hitEnd)
        {
            if (DoubleUtil.IsZero(spineVector.X) && DoubleUtil.IsZero(spineVector.Y))
            {
                Vector nearest = StrokeNodeOperations.GetNearest(hitBegin, hitEnd);
                double num     = (nearest.X == 0.0) ? Math.Abs(nearest.Y) : ((nearest.Y != 0.0) ? nearest.Length : Math.Abs(nearest.X));
                return(StrokeNodeOperations.AdjustFIndex((num - beginRadius) / (endRadius - beginRadius)));
            }
            if (DoubleUtil.AreClose(hitBegin, hitEnd))
            {
                return(ClipTest(spineVector, beginRadius, endRadius, hitBegin));
            }
            Vector vector = hitEnd - hitBegin;
            double num2;

            if (DoubleUtil.IsZero(Vector.Determinant(spineVector, vector)))
            {
                num2 = ClipTest(spineVector, beginRadius, endRadius, StrokeNodeOperations.GetNearest(hitBegin, hitEnd));
            }
            else
            {
                double projectionFIndex = StrokeNodeOperations.GetProjectionFIndex(hitBegin, hitEnd);
                Vector vector2          = hitBegin + vector * projectionFIndex;
                if (vector2.LengthSquared < beginRadius * beginRadius)
                {
                    num2 = ClipTest(spineVector, beginRadius, endRadius, (0.0 > projectionFIndex) ? hitBegin : hitEnd);
                }
                else
                {
                    Vector vector3 = spineVector + StrokeNodeOperations.GetProjection(-spineVector, vector2 - spineVector);
                    if (DoubleUtil.IsZero(vector3.LengthSquared) || DoubleUtil.IsZero(endRadius - beginRadius + vector3.Length))
                    {
                        return(1.0);
                    }
                    num2 = (vector2.Length - beginRadius) / (endRadius - beginRadius + vector3.Length);
                    Vector vector4           = spineVector * num2;
                    double projectionFIndex2 = StrokeNodeOperations.GetProjectionFIndex(hitBegin - vector4, hitEnd - vector4);
                    if (!DoubleUtil.IsBetweenZeroAndOne(projectionFIndex2))
                    {
                        num2 = ClipTest(spineVector, beginRadius, endRadius, (0.0 > projectionFIndex2) ? hitBegin : hitEnd);
                    }
                }
            }
            return(StrokeNodeOperations.AdjustFIndex(num2));
        }
Example #2
0
        private static double ClipTest(Vector spine, double beginRadius, double endRadius, Vector hit)
        {
            double num  = endRadius - beginRadius;
            double num2 = spine.X * spine.X + spine.Y * spine.Y - num * num;
            double num3 = -2.0 * (hit.X * spine.X + hit.Y * spine.Y + beginRadius * num);
            double num4 = hit.X * hit.X + hit.Y * hit.Y - beginRadius * beginRadius;

            if (DoubleUtil.IsZero(num2) || !DoubleUtil.GreaterThanOrClose(num3 * num3, 4.0 * num2 * num4))
            {
                return(1.0);
            }
            double num5   = Math.Sqrt(num3 * num3 - 4.0 * num2 * num4);
            double num6   = (0.0 - num3 + num5) / (2.0 * num2);
            double num7   = (0.0 - num3 - num5) / (2.0 * num2);
            double findex = (DoubleUtil.IsBetweenZeroAndOne(num6) && DoubleUtil.IsBetweenZeroAndOne(num6)) ? Math.Min(num6, num7) : (DoubleUtil.IsBetweenZeroAndOne(num6) ? num6 : (DoubleUtil.IsBetweenZeroAndOne(num7) ? num7 : ((num6 > 1.0 && num7 > 1.0) ? 1.0 : ((!(num6 < 0.0) || !(num7 < 0.0)) ? ((Math.Abs(Math.Min(num6, num7) - 0.0) < Math.Abs(Math.Max(num6, num7) - 1.0)) ? 0.0 : 1.0) : 0.0))));

            return(StrokeNodeOperations.AdjustFIndex(findex));
        }