Ejemplo n.º 1
0
        /// <summary>Slices off anything below the given line.</summary>
        public override void SliceBottom(float sliceLine, VectorPath path)
        {
            float previous = Previous.Y;
            float current  = Y;

            // Both below?
            if (previous < sliceLine && current < sliceLine)
            {
                // Both below.
                path.RemoveVisually(this);

                return;
            }
            else if (previous >= sliceLine && current >= sliceLine)
            {
                // Do nothing.
                return;
            }

            // Split where the slice line is.
            VectorPoint newPoint = Split((sliceLine - previous) / (current - previous), path);

            // Delete the segment to the left/right.
            if (current < sliceLine)
            {
                // Delete this -> newPoint
                path.RemoveVisually(newPoint);
            }
            else
            {
                // Delete previous -> this
                path.RemoveVisually(this);
            }
        }
Ejemplo n.º 2
0
        /// <summary>Slices off anything to the right of the given line.</summary>
        public override void SliceRight(float sliceLine, VectorPath path)
        {
            float previous = Previous.X;
            float control1 = Control1X;
            float current  = X;

            // All to the right?
            if (previous <= sliceLine && current <= sliceLine && control1 <= sliceLine)
            {
                // Do nothing.
                return;
            }
            else if (previous > sliceLine && current > sliceLine && control1 > sliceLine)
            {
                // All to the right.
                path.RemoveVisually(this);

                return;
            }

            VectorPoint newPoint;

            if (control1 == sliceLine)
            {
                // Control point is on the line - split at 0.5:
                newPoint = Split(0.5f, path);

                // Which point is to the right?
                if (current > sliceLine)
                {
                    // 2nd half is to the right.
                    path.RemoveVisually(newPoint);
                }
                else
                {
                    path.RemoveVisually(this);
                }

                return;
            }

            // Second line intersects?
            bool  removeThis     = false;
            float alreadySplitAt = 1f;

            if ((current > sliceLine != control1 > sliceLine))
            {
                // Yep! Split at the intersect:
                alreadySplitAt = (((sliceLine - control1) / (current - control1)) * 0.5f) + 0.5f;
                newPoint       = Split(alreadySplitAt, path);
                X = sliceLine;

                // If the second part is to the right, delete it:
                if (current > sliceLine)
                {
                    path.RemoveVisually(newPoint);
                }
                else
                {
                    // Remove this, but only after checking if first line intersects.
                    removeThis = true;
                }
            }

            // First line intersects?
            if ((previous > sliceLine != control1 > sliceLine))
            {
                // Yep! Split at the intersect:
                newPoint = Split(((sliceLine - previous) / (control1 - previous)) * 0.5f * alreadySplitAt, path);
                X        = sliceLine;

                // If the first part is to the right, delete it:
                if (previous > sliceLine)
                {
                    path.RemoveVisually(this);
                }
                else
                {
                    // Remove newPoint:
                    path.RemoveVisually(newPoint);
                }
            }
            else if (removeThis)
            {
                path.RemoveVisually(this);
            }
        }
Ejemplo n.º 3
0
        /// <summary>Slices off anything to the right of the given line.</summary>
        public override void SliceRight(float sliceLine, VectorPath path)
        {
            float previous = Previous.X;
            float control1 = Control1X;
            float control2 = Control2X;
            float current  = X;

            // All to the right?
            if (previous <= sliceLine && current <= sliceLine && control1 <= sliceLine && control2 <= sliceLine)
            {
                // Do nothing.
                return;
            }
            else if (previous > sliceLine && current > sliceLine && control1 > sliceLine && control2 > sliceLine)
            {
                // All to the right.
                path.RemoveVisually(this);

                return;
            }

            VectorPoint newPoint;
            float       alreadySplitAt = 1f;
            bool        deleteAll      = false;

            // Third line intersects?
            if ((current > sliceLine != control2 > sliceLine))
            {
                // Yep! Split at the intersect:
                alreadySplitAt = (((sliceLine - control2) / (current - control2)) * 1f / 3f) + 2f / 3f;
                newPoint       = Split(alreadySplitAt, path);
                X = sliceLine;

                // If the second part is to the right, delete it:
                if (current > sliceLine)
                {
                    path.RemoveVisually(newPoint);
                }
                else
                {
                    // Potentially deleting everything else.
                    deleteAll = true;
                }
            }

            // Second line intersects?
            if ((control2 > sliceLine != control1 > sliceLine))
            {
                // Yep! Split at the intersect:
                alreadySplitAt = ((((sliceLine - control1) / (control2 - control1)) * 1f / 3f) + 1f / 3f) * alreadySplitAt;
                newPoint       = Split(alreadySplitAt, path);
                X = sliceLine;

                // If the first part is to the *other side*, delete newPoint:
                if (deleteAll)
                {
                    path.RemoveVisually(newPoint);
                    deleteAll = false;
                }
                else
                {
                    deleteAll = true;
                }
            }

            // First line intersects?
            if ((previous > sliceLine != control1 > sliceLine))
            {
                // Yep! Split at the intersect:
                newPoint = Split(((sliceLine - previous) / (control1 - previous)) * 1f / 3f * alreadySplitAt, path);
                X        = sliceLine;

                // If the first part is to the *other side*, delete newPoint:
                if (deleteAll)
                {
                    path.RemoveVisually(newPoint);
                    deleteAll = false;
                }
                else
                {
                    // Delete whatever is left:
                    path.RemoveVisually(this);
                }
            }
            else if (deleteAll)
            {
                // Delete whatever is left:
                path.RemoveVisually(this);
            }
        }