/// <summary>
        /// Get <see cref="LineShape"/> maximum length for <see cref="LineFixedLengthFlags.All"/> mode.
        /// </summary>
        /// <param name="line">The line shape.</param>
        /// <param name="x1">The calculated X coordinate for <see cref="LineShape.Start"/> point.</param>
        /// <param name="y1">The calculated Y coordinate for <see cref="LineShape.Start"/> point.</param>
        /// <param name="x2">The calculated X coordinate for <see cref="LineShape.End"/> point.</param>
        /// <param name="y2">The calculated Y coordinate for <see cref="LineShape.End"/> point.</param>
        public static void GetMaxLengthAll(this LineShape line, ref double x1, ref double y1, ref double x2, ref double y2)
        {
            var ls = line.Style.LineStyle;

            bool shortenStart = ls.FixedLength.StartTrigger.Flags != ShapeStateFlags.Default &&
                                line.Start.State.Flags.HasFlag(ls.FixedLength.StartTrigger.Flags) &&
                                ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Start);

            bool shortenEnd = ls.FixedLength.EndTrigger.Flags != ShapeStateFlags.Default &&
                              line.End.State.Flags.HasFlag(ls.FixedLength.EndTrigger.Flags) &&
                              ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.End);

            if (shortenStart && !shortenEnd)
            {
                double dx       = x1 - x2;
                double dy       = y1 - y2;
                double distance = Sqrt(dx * dx + dy * dy);
                x1 = x2 - (x2 - x1) / distance * ls.FixedLength.Length;
                y1 = y2 - (y2 - y1) / distance * ls.FixedLength.Length;
            }

            if (!shortenStart && shortenEnd)
            {
                double dx       = x2 - x1;
                double dy       = y2 - y1;
                double distance = Sqrt(dx * dx + dy * dy);
                x2 = x1 - (x1 - x2) / distance * ls.FixedLength.Length;
                y2 = y1 - (y1 - y2) / distance * ls.FixedLength.Length;
            }
        }
        /// <summary>
        /// Get <see cref="LineShape"/> maximum length using <see cref="LineFixedLengthFlags"/>.
        /// </summary>
        /// <param name="line">The line shape.</param>
        /// <param name="x1">The calculated X coordinate for <see cref="LineShape.Start"/> point.</param>
        /// <param name="y1">The calculated Y coordinate for <see cref="LineShape.Start"/> point.</param>
        /// <param name="x2">The calculated X coordinate for <see cref="LineShape.End"/> point.</param>
        /// <param name="y2">The calculated Y coordinate for <see cref="LineShape.End"/> point.</param>
        public static void GetMaxLength(this LineShape line, ref double x1, ref double y1, ref double x2, ref double y2)
        {
            var ls = line.Style.LineStyle;

            if (ls.FixedLength.Flags == LineFixedLengthFlags.Disabled)
            {
                return;
            }

            if (ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.All))
            {
                GetMaxLengthAll(line, ref x1, ref y1, ref x2, ref y2);
            }
            else
            {
                if (ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Vertical))
                {
                    bool isVertical = Round(x1, 1) == Round(x2, 1);
                    if (isVertical)
                    {
                        GetMaxLengthVertical(line, ref y1, ref y2);
                    }
                }

                if (ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Horizontal))
                {
                    bool isHorizontal = Round(y1, 1) == Round(y2, 1);
                    if (isHorizontal)
                    {
                        GetMaxLengthHorizontal(line, ref x1, ref x2);
                    }
                }
            }
        }
Example #3
0
 public static Line2 ToLine2(this LineShape line, double dx = 0.0, double dy = 0.0)
 {
     return(Line2.FromPoints(
                line.StartPoint.X, line.StartPoint.Y,
                line.Point.X, line.Point.Y,
                dx, dy));
 }
        /// <summary>
        /// Get <see cref="LineShape"/> maximum length for <see cref="LineFixedLengthFlags.Vertical"/> mode.
        /// </summary>
        /// <param name="line">The line shape.</param>
        /// <param name="y1">The calculated Y coordinate for <see cref="LineShape.Start"/> point.</param>
        /// <param name="y2">The calculated Y coordinate for <see cref="LineShape.End"/> point.</param>
        public static void GetMaxLengthVertical(this LineShape line, ref double y1, ref double y2)
        {
            var ls = line.Style.LineStyle;

            bool shortenStart = ls.FixedLength.StartTrigger.Flags != ShapeStateFlags.Default &&
                                line.Start.State.Flags.HasFlag(ls.FixedLength.StartTrigger.Flags) &&
                                ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Start);

            bool shortenEnd = ls.FixedLength.EndTrigger.Flags != ShapeStateFlags.Default &&
                              line.End.State.Flags.HasFlag(ls.FixedLength.EndTrigger.Flags) &&
                              ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.End);

            if (shortenStart && !shortenEnd)
            {
                if (y2 > y1)
                {
                    y1 = y2 - ls.FixedLength.Length;
                }
                else
                {
                    y1 = y2 + ls.FixedLength.Length;
                }
            }

            if (!shortenStart && shortenEnd)
            {
                if (y2 > y1)
                {
                    y2 = y1 + ls.FixedLength.Length;
                }
                else
                {
                    y2 = y1 - ls.FixedLength.Length;
                }
            }
        }
        /// <summary>
        /// Get <see cref="LineShape"/> maximum length for <see cref="LineFixedLengthFlags.Horizontal"/> mode.
        /// </summary>
        /// <param name="line">The line shape.</param>
        /// <param name="x1">The calculated X coordinate for <see cref="LineShape.Start"/> point.</param>
        /// <param name="x2">The calculated X coordinate for <see cref="LineShape.End"/> point.</param>
        public static void GetMaxLengthHorizontal(this LineShape line, ref double x1, ref double x2)
        {
            var ls = line.Style.LineStyle;

            bool shortenStart = ls.FixedLength.StartTrigger.Flags != ShapeStateFlags.Default &&
                                line.Start.State.Flags.HasFlag(ls.FixedLength.StartTrigger.Flags) &&
                                ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Start);

            bool shortenEnd = ls.FixedLength.EndTrigger.Flags != ShapeStateFlags.Default &&
                              line.End.State.Flags.HasFlag(ls.FixedLength.EndTrigger.Flags) &&
                              ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.End);

            if (shortenStart && !shortenEnd)
            {
                if (x2 > x1)
                {
                    x1 = x2 - ls.FixedLength.Length;
                }
                else
                {
                    x1 = x2 + ls.FixedLength.Length;
                }
            }

            if (!shortenStart && shortenEnd)
            {
                if (x2 > x1)
                {
                    x2 = x1 + ls.FixedLength.Length;
                }
                else
                {
                    x2 = x1 - ls.FixedLength.Length;
                }
            }
        }