示例#1
0
 public bool Equals <T1>(LineSegmentLocus <T> rhs)
 {
     if (rhs == null)
     {
         return(false);
     }
     if (Segments == null && rhs.Segments == null)
     {
         return(true);
     }
     if (Segments == null || rhs.Segments == null)
     {
         return(false);
     }
     if (Segments.Count != rhs.Segments.Count)
     {
         return(false);
     }
     foreach (Line2D <T> line in Segments)
     {
         if (!rhs.Segments.Contains(line))
         {
             return(false);
         }
     }
     return(true);
 }
示例#2
0
 private Locus <T> CombineIntersections(PointLocus <T> current, LineSegmentLocus <T> addition)
 {
     if (ContainsPoint(addition, current))
     {
         return(addition);
     }
     addition.Segments.Add(new Line2D <T>(current.IntersectionPoint, current.IntersectionPoint));
     return(addition);
 }
示例#3
0
 /// <summary>
 /// Determine if the point is contained in any of the segments of the line segment
 /// </summary>
 /// <param name="lineSegment"></param>
 /// <param name="point"></param>
 /// <returns>true if the point lands on a line segment</returns>
 private bool ContainsPoint(LineSegmentLocus <T> lineSegment, PointLocus <T> point)
 {
     foreach (Line2D <T> line in lineSegment.Segments)
     {
         if (line.Contains(point.IntersectionPoint))
         {
             return(true);
         }
     }
     return(false);
 }
示例#4
0
 private Locus <T> CombineIntersections(LineSegmentLocus <T> current, PointLocus <T> addition)
 {
     // If the point to be added already exists in one of the line
     // segments ignore it
     if (ContainsPoint(current, addition))
     {
         return(current);
     }
     current.Segments.Add(new Line2D <T>(addition.IntersectionPoint, addition.IntersectionPoint));
     return(current);
 }
示例#5
0
 private Locus <T> CombineIntersections(MultiPointLocus <T> current, LineSegmentLocus <T> addition)
 {
     foreach (Point2D <T> point in current.Points)
     {
         bool found = false;
         foreach (Line2D <T> line in addition.Segments)
         {
             if (line.Contains(point))
             {
                 found = true;
             }
         }
         if (!found)
         {
             addition.Segments.Add(new Line2D <T>(point, point));
         }
     }
     return(addition);
 }
示例#6
0
        private Locus <T> CombineIntersections(LineSegmentLocus <T> current, MultiPointLocus <T> addition)
        {
            ICollection <Point2D <T> > additionalPoints = addition.Points;

            // If the points to be added already exists in one of the line
            // segments ignore it
            foreach (Line2D <T> line in current.Segments)
            {
                foreach (Point2D <T> point in addition.Points)
                {
                    if (line.Contains(point))
                    {
                        additionalPoints.Remove(point);
                    }
                }
            }
            additionalPoints.ForEach(p => current.Segments.Add(new Line2D <T>(p, p)));
            return(current);
        }
示例#7
0
        private Locus <T> CombineIntersections(LineSegmentLocus <T> current, LineSegmentLocus <T> addition)
        {
            // If the segment to be added already exists in one of the line
            // segments ignore it
            ICollection <Line2D <T> > linesToAdd = new List <Line2D <T> >();

            foreach (Line2D <T> line in current.Segments)
            {
                if (!line.Equals(addition.Segments))
                {
                    linesToAdd.Add(line);
                }
            }
            if (linesToAdd.Count > 0)
            {
                current.Segments.AddRange(linesToAdd);
            }
            return(current);
        }
示例#8
0
 private Locus <T> CombineIntersections(EmptyLocus <T> current, LineSegmentLocus <T> addition)
 {
     return(addition);
 }
示例#9
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);
        }