Ejemplo n.º 1
0
 /// <summary>
 /// Determine if a line is encompassed completely within a rectangle
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool Encompasses(Line2D <T> line)
 {
     return(RayTrace(line.Ends[0]) && RayTrace(line.Ends[1]));
 }
Ejemplo n.º 2
0
 public void AngleToTest(Line2D <Int32> line1, Line2D <Int32> line2, double expectedAngle)
 {
     Assert.AreEqual(expectedAngle, line1.AngleTo(line2));
 }
Ejemplo n.º 3
0
 public void IntersectingTest(Line2D <Int32> lhs, Line2D <Int32> rhs, bool result)
 {
     Assert.AreEqual(result, lhs.Intersects(rhs));
 }
Ejemplo n.º 4
0
 public void ParallelTest(Line2D <Int32> lhs, Line2D <Int32> rhs, bool result)
 {
     Assert.AreEqual(result, lhs.Parallel(rhs));
 }
Ejemplo n.º 5
0
 public void IsPerpendicularTest(Line2D <Int32> line1, Line2D <Int32> line2, bool expectedResult)
 {
     Assert.AreEqual(expectedResult, line1.IsPerpendicular(line2));
     Assert.AreEqual(expectedResult, line2.IsPerpendicular(line1));
 }
Ejemplo n.º 6
0
 public void EqualsTest(Line2D <Int32> lhs, Line2D <Int32> rhs, bool result)
 {
     Assert.AreEqual(result, lhs.Equals(rhs));
 }
Ejemplo n.º 7
0
 public void ExtendLineTest(Line2D <Int32> originalLine, Int32 extension1, Int32 extension2, Line2D <Int32> expectedLine)
 {
     Assert.AreEqual(expectedLine, originalLine.Extend(extension1, extension2));
 }
Ejemplo n.º 8
0
 public void CoincidentTest(Line2D <Int32> lhs, Line2D <Int32> rhs, bool result)
 {
     Assert.AreEqual(result, lhs.Coincident(rhs));
 }
Ejemplo n.º 9
0
 public void OverlapTest(Line2D <Int32> lhs, Line2D <Int32> rhs, Locus <Int32> result)
 {
     Assert.AreEqual(result, lhs.Overlaps(rhs));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="newLine">The line to replace this line with</param>
 public Line2D(Line2D <T> newLine)
 {
     this.Ends = newLine.Ends.CloneDeepCollection();
 }
Ejemplo n.º 11
0
 public void IntersectionTest(Line2D <Int32> lhs, Line2D <Int32> rhs, Locus <Int32> expected)
 {
     Assert.AreEqual(expected, lhs.Intersection(rhs));
 }
Ejemplo n.º 12
0
        public T1 Clone <T1, T2>()
        {
            Line2D <T2> result = new Line2D <T2>((dynamic)Ends[0].Clone(), (dynamic)Ends[1].Clone());

            return((dynamic)result);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Determine if the supplied line is perpendicular to this line
        /// </summary>
        /// <param name="rhs">The supplied line</param>
        /// <returns>true if perpendicular, false otherwise</returns>
        public bool IsPerpendicular(Line2D <T> rhs)
        {
            double angle = AngleTo(rhs);

            return(angle == 90 || angle == 270);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Determine if two lines are coincident (they lie one on top of the other)
        /// <para>This function does not consider endpoints of lines, so non-overlapping
        /// lines will be considered co-incident if they have the same linear function</para>
        /// </summary>
        /// <param name="rhs">The other line</param>
        /// <returns>true if the lines are in the same space</returns>
        public bool Coincident(Line2D <T> rhs)
        {
            Formula f = CalculateIntersectionFormulae(rhs);

            return(f.Udenominator == 0 && f.UA == 0 && f.UB == 0);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Determine if two lines are parallel
        /// </summary>
        /// <param name="rhs">the other line</param>
        /// <returns>true if the lines are parallel, false otherwise</returns>
        public bool Parallel(Line2D <T> rhs)
        {
            Formula f = CalculateIntersectionFormulae(rhs);

            return(f.Udenominator == 0);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Determine if a line overlaps another line
        /// and fetch the line segment of the overlap
        /// <para>The two lines must be coincident for this function to work</para>
        /// </summary>
        /// <param name="rhs">The line to check against</param>
        /// <returns>A locus containing the overlapping segments</returns>
        public Locus <T> Overlaps(Line2D <T> rhs)
        {
            if (!Coincident(rhs))
            {
                return(new EmptyLocus <T>());
            }

            Point2D <T> p1 = null;
            Point2D <T> p2 = null;

            double r1 = CalculatePerpindicularOffset(rhs.Ends[0]);

            if (0 <= r1 && r1 <= 1)
            {
                p1 = CalculatePerpindicularPoint(rhs.Ends[0]);
            }
            else
            {
                r1 = rhs.CalculatePerpindicularOffset(Ends[0]);
                if (0 <= r1 && r1 <= 1)
                {
                    p1 = rhs.CalculatePerpindicularPoint(Ends[0]);
                }
                else
                {
                    r1 = rhs.CalculatePerpindicularOffset(Ends[1]);
                    if (0 <= r1 && r1 <= 1)
                    {
                        p1 = rhs.CalculatePerpindicularPoint(Ends[1]);
                    }
                    else
                    {
                        return(new EmptyLocus <T>());
                    }
                }
            }


            double r2 = CalculatePerpindicularOffset(rhs.Ends[1]);

            if (0 <= r2 && r2 <= 1)
            {
                p2 = CalculatePerpindicularPoint(rhs.Ends[1]);
            }
            else
            {
                r2 = rhs.CalculatePerpindicularOffset(Ends[1]);
                if (0 <= r2 && r2 <= 1)
                {
                    p2 = rhs.CalculatePerpindicularPoint(Ends[1]);
                }
                else
                {
                    r2 = rhs.CalculatePerpindicularOffset(Ends[0]);
                    if (0 <= r2 && r2 <= 1)
                    {
                        p2 = rhs.CalculatePerpindicularPoint(Ends[0]);
                    }
                    else
                    {
                        return(new EmptyLocus <T>());
                    }
                }
            }

            if (p1 == null || p2 == null)
            {
                return(new EmptyLocus <T>());
            }

            if (p1.Equals(p2))
            {
                return(new PointLocus <T>(p1));
            }

            LineSegmentLocus <T> result = new LineSegmentLocus <T>();

            result.Segments.Add(new Line2D <T>(p1, p2));
            return(result);
        }