Ejemplo n.º 1
0
        public override void Run(List <Point> points, List <Line> lines, List <Polygon> polygons, ref List <Point> outPoints, ref List <Line> outLines, ref List <Polygon> outPolygons)
        {
            if (polygons[0].lines.Count < 3 || points.Count == 0)
            { // not valid case to be solved
                return;
            }
            // line to right of given point
            Point       a             = points[0];
            Point       b             = new Point(a.X + 10000, a.Y);
            Line        vir_line      = new Line(a, b);
            List <Line> poly_segments = polygons[0].lines;

            // this may be bad practice
            segment_segment_intersection seg_inter = new segment_segment_intersection();

            // do segment - segment intersection for vir_line with all the segments of the concave polygon
            for (int i = 0; i < poly_segments.Count; i++)
            {
                Line poly_seg = poly_segments[i];
                // check segment - segment intersection
                List <Line> tmp_lines = new List <Line>();
                tmp_lines.Add(vir_line);
                tmp_lines.Add(poly_seg);

                /*
                 * this will add points of intersections to outpoints list
                 * so we have to delete them later
                 */
                seg_inter.Run(points, tmp_lines, polygons, ref outPoints, ref outLines, ref outPolygons);

                // check for colinearity (point is on a polygon segment)
                Enums.TurnType t = HelperMethods.CheckTurn(poly_seg, a);
                if (t == Enums.TurnType.Colinear && check_point_inside_segment(poly_seg, a))
                {
                    outPoints.Clear(); // clear points of intersections
                    outPoints.Add(a);
                    return;
                }
            }

            // intersect odd number of segments = inside the polygon
            if (outPoints.Count % 2 != 0)
            {
                outPoints.Clear(); // clear points of intersections
                outPoints.Add(a);
            }
            else
            {
                outPoints.Clear();
            }
            return;
        }
Ejemplo n.º 2
0
        public override void Run(List <Point> points, List <Line> lines, List <Polygon> polygons, ref List <Point> outPoints, ref List <Line> outLines, ref List <Polygon> outPolygons)
        {
            Line        l             = lines[0];
            List <Line> polygon_lines = polygons[0].lines;

            /*
             * this will affect the outpoints list
             * and this function need this , and every other function that call it need this too
             */
            segment_segment_intersection seg_seg_inter = new segment_segment_intersection();

            for (int i = 0; i < polygon_lines.Count; i++)
            {
                Line pline = polygon_lines[i];
                // segment segment intersection
                List <Line> tmp_lines = new List <Line>();
                tmp_lines.Add(l);
                tmp_lines.Add(pline);
                seg_seg_inter.Run(points, tmp_lines, polygons, ref outPoints, ref outLines, ref outPolygons);
            }
        }