/// <summary>
        ///     Splits the line into two lines at the distance along the line given.
        /// </summary>
        /// <param name="distance">The distance along the line to split the line, in the range 0-1 (exclusive).</param>
        /// <param name="line1">The first line.</param>
        /// <param name="line2">The second line.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">The distance must be in the range 0-1.</exception>
        public void SplitLine(float distance, out ILine line1, out ILine line2)
        {
            if (distance <= 0 || distance >= 1)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(distance),
                          distance,
                          "The distance must be in the range 0-1.");
            }

            Vector2 p1 = Start;
            Vector2 p2 = ControlPointA;
            Vector2 p3 = ControlPointB;
            Vector2 p4 = End;

            Vector2 p12 = ((p2 - p1) * distance) + p1;
            Vector2 p23 = ((p3 - p2) * distance) + p2;
            Vector2 p34 = ((p4 - p3) * distance) + p3;

            Vector2 p123 = ((p23 - p12) * distance) + p12;
            Vector2 p234 = ((p34 - p23) * distance) + p23;

            Vector2 p1234 = ((p234 - p123) * distance) + p123;

            LineVector midVector = new LineVector(p1234);

            line1 = new CubicBezierCurve(Start, new LineVector(p12), new LineVector(p123), midVector);
            line2 = new CubicBezierCurve(midVector, new LineVector(p234), new LineVector(p34), End);
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="CubicBezierCurve" /> class.
 /// </summary>
 /// <param name="start">The start point.</param>
 /// <param name="controlPointA">The first control point.</param>
 /// <param name="controlPointB">The second control point.</param>
 /// <param name="end">The end point.</param>
 public CubicBezierCurve(
     [NotNull] LineVector start,
     [NotNull] LineVector controlPointA,
     [NotNull] LineVector controlPointB,
     [NotNull] LineVector end)
 {
     if (start == null)
     {
         throw new ArgumentNullException(nameof(start));
     }
     if (controlPointA == null)
     {
         throw new ArgumentNullException(nameof(controlPointA));
     }
     if (controlPointB == null)
     {
         throw new ArgumentNullException(nameof(controlPointB));
     }
     if (end == null)
     {
         throw new ArgumentNullException(nameof(end));
     }
     Start         = start;
     ControlPointA = controlPointA;
     ControlPointB = controlPointB;
     End           = end;
 }
Exemple #3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Line" /> class.
        /// </summary>
        /// <param name="start">The start point.</param>
        /// <param name="end">The end point.</param>
        public Line([NotNull] LineVector start, [NotNull] LineVector end)
        {
            if (start == null)
            {
                throw new ArgumentNullException(nameof(start));
            }
            if (end == null)
            {
                throw new ArgumentNullException(nameof(end));
            }

            Start = start;
            End   = end;
        }
Exemple #4
0
        /// <summary>
        ///     Splits the line into two lines at the distance along the line given.
        /// </summary>
        /// <param name="distance">The distance along the line to split the line, in the range 0-1 (exclusive).</param>
        /// <param name="line1">The first line.</param>
        /// <param name="line2">The second line.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">The distance must be in the range 0-1.</exception>
        public void SplitLine(float distance, out ILine line1, out ILine line2)
        {
            if (distance <= 0 || distance >= 1)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(distance),
                          distance,
                          "The distance must be in the range 0-1.");
            }

            Vector2 mid = Start + ((End.Vector - Start.Vector) * distance);

            LineVector midVector = new LineVector(mid);

            line1 = new Line(Start, midVector);
            line2 = new Line(midVector, End);
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="QuadraticBezierCurve" /> class.
 /// </summary>
 /// <param name="start">The start point.</param>
 /// <param name="controlPoint">The control point.</param>
 /// <param name="end">The end point.</param>
 public QuadraticBezierCurve(
     [NotNull] LineVector start,
     [NotNull] LineVector controlPoint,
     [NotNull] LineVector end)
 {
     if (start == null)
     {
         throw new ArgumentNullException(nameof(start));
     }
     if (controlPoint == null)
     {
         throw new ArgumentNullException(nameof(controlPoint));
     }
     if (end == null)
     {
         throw new ArgumentNullException(nameof(end));
     }
     Start        = start;
     ControlPoint = controlPoint;
     End          = end;
 }
        /// <summary>
        ///     Splits the line into two lines at the distance along the line given.
        /// </summary>
        /// <param name="distance">The distance along the line to split the line, in the range 0-1 (exclusive).</param>
        /// <param name="line1">The first line.</param>
        /// <param name="line2">The second line.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">The distance must be in the range 0-1.</exception>
        public void SplitLine(float distance, out ILine line1, out ILine line2)
        {
            if (distance <= 0 || distance >= 1)
            {
                throw new ArgumentOutOfRangeException(
                    nameof(distance),
                    distance,
                    "The distance must be in the range 0-1.");
            }

            Vector2 p1 = Start;
            Vector2 p2 = ControlPoint;
            Vector2 p3 = End;

            Vector2 p12 = ((p2 - p1) * distance) + p1;
            Vector2 p23 = ((p3 - p2) * distance) + p2;

            Vector2 p123 = ((p23 - p12) * distance) + p12;

            LineVector midVector = new LineVector(p123);

            line1 = new QuadraticBezierCurve(Start, new LineVector(p12), midVector);
            line2 = new QuadraticBezierCurve(midVector, new LineVector(p23), End);
        }
Exemple #7
0
        /// <summary>
        ///     Splits the line into two lines at the distance along the line given.
        /// </summary>
        /// <param name="distance">The distance along the line to split the line, in the range 0-1 (exclusive).</param>
        /// <param name="line1">The first line.</param>
        /// <param name="line2">The second line.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">The distance must be in the range 0-1.</exception>
        public void SplitLine(float distance, out ILine line1, out ILine line2)
        {
            if (distance <= 0 || distance >= 1)
            {
                throw new ArgumentOutOfRangeException(
                    nameof(distance),
                    distance,
                    "The distance must be in the range 0-1.");
            }

            Vector2 mid = Start + ((End.Vector - Start.Vector) * distance);

            LineVector midVector = new LineVector(mid);

            line1 = new Line(Start, midVector);
            line2 = new Line(midVector, End);
        }