Пример #1
0
        public void AddLine(List <ClipperLib.IntPoint> points)
        {
            PolylineReduction.CurrentPolylineId++;

            // Get rid of mid-points along the line that are not needed
            points = RemovePointsOnLine(points);

            // Always add the polyline forward
            InternalPolyline forwards = new InternalPolyline();

            forwards.Id = PolylineReduction.CurrentPolylineId;
            forwards.Points.AddRange(points);

            m_TablePolyline.Add(forwards.Points.Last(), forwards);

            // Add the polyline backwards too if the end-points are different
            // Make sure the Id is the same though
            if (points.First() != points.Last())
            {
                InternalPolyline backwards = new InternalPolyline();
                backwards.Id = PolylineReduction.CurrentPolylineId;
                backwards.Points.AddRange(points);
                backwards.Points.Reverse();

                m_TablePolyline.Add(backwards.Points.Last(), backwards);
            }
        }
Пример #2
0
        public void AddLine(List<ClipperLib.IntPoint> points)
        {
            PolylineReduction.CurrentPolylineId++;

            // Get rid of mid-points along the line that are not needed
            points = RemovePointsOnLine(points);

            // Always add the polyline forward
            InternalPolyline forwards = new InternalPolyline();
            forwards.Id = PolylineReduction.CurrentPolylineId;
            forwards.Points.AddRange(points);

            this.tablePolyline.Add(forwards.Points.Last(), forwards);

            // Add the polyline backwards too if the end-points are different
            // Make sure the Id is the same though
            if (points.First() != points.Last())
            {
                InternalPolyline backwards = new InternalPolyline();
                backwards.Id = PolylineReduction.CurrentPolylineId;
                backwards.Points.AddRange(points);
                backwards.Points.Reverse();

                this.tablePolyline.Add(backwards.Points.Last(), backwards);
            }
        }
Пример #3
0
 private void RemovePolyline(InternalPolyline polyline)
 {
     foreach (InternalPolyline item in (from pairs in tablePolyline
                                        from line in pairs.Value
                                        where line.Id == polyline.Id
                                        select line).ToList())
     {
         tablePolyline.Remove(item.Points.Last(), item);
     }
 }
Пример #4
0
        private void CombinePolyline(InternalPolyline line0, InternalPolyline line1)
        {
            List <IntPoint> list = new List <IntPoint>();

            list.AddRange(line0.Points);
            line1.Points.Reverse();
            line1.Points.RemoveAt(0);
            list.AddRange(line1.Points);
            AddLine(list);
        }
Пример #5
0
        private void CombinePolyline(InternalPolyline line0, InternalPolyline line1)
        {
            // Assumes Line0 and Line1 have the same end-points
            // We reverse Line1 and remove its first end-point
            List<ClipperLib.IntPoint> combined = new List<ClipperLib.IntPoint>();
            combined.AddRange(line0.Points);

            line1.Points.Reverse();
            line1.Points.RemoveAt(0);
            combined.AddRange(line1.Points);

            AddLine(combined);
        }
Пример #6
0
        private void RemovePolyline(InternalPolyline polyline)
        {
            var removes = from pairs in m_TablePolyline
                          from line in pairs.Value
                          where line.Id == polyline.Id
                          select line;

            var removeList = removes.ToList();

            foreach (var rem in removeList)
            {
                m_TablePolyline.Remove(rem.Points.Last(), rem);
            }
        }
Пример #7
0
        private void CombinePolyline(InternalPolyline line0, InternalPolyline line1)
        {
            // Assumes Line0 and Line1 have the same end-points
            // We reverse Line1 and remove its first end-point
            List <ClipperLib.IntPoint> combined = new List <ClipperLib.IntPoint>();

            combined.AddRange(line0.Points);

            line1.Points.Reverse();
            line1.Points.RemoveAt(0);
            combined.AddRange(line1.Points);

            AddLine(combined);
        }
Пример #8
0
        public void AddLine(List <IntPoint> points)
        {
            CurrentPolylineId++;
            points = RemovePointsOnLine(points);
            InternalPolyline internalPolyline = new InternalPolyline();

            internalPolyline.Id = CurrentPolylineId;
            internalPolyline.Points.AddRange(points);
            tablePolyline.Add(internalPolyline.Points.Last(), internalPolyline);
            if (points.First() != points.Last())
            {
                InternalPolyline internalPolyline2 = new InternalPolyline();
                internalPolyline2.Id = CurrentPolylineId;
                internalPolyline2.Points.AddRange(points);
                internalPolyline2.Points.Reverse();
                tablePolyline.Add(internalPolyline2.Points.Last(), internalPolyline2);
            }
        }
Пример #9
0
        public List <List <IntPoint> > Reduce()
        {
            KeyValuePair <IntPoint, HashSet <InternalPolyline> > keyValuePair = tablePolyline.FirstOrDefault((KeyValuePair <IntPoint, HashSet <InternalPolyline> > kvp) => kvp.Value.Count > 1);

            while (keyValuePair.Value != null)
            {
                List <InternalPolyline> list              = keyValuePair.Value.ToList();
                InternalPolyline        internalPolyline  = list[0];
                InternalPolyline        internalPolyline2 = list[1];
                RemovePolyline(internalPolyline);
                RemovePolyline(internalPolyline2);
                CombinePolyline(internalPolyline, internalPolyline2);
                keyValuePair = tablePolyline.FirstOrDefault((KeyValuePair <IntPoint, HashSet <InternalPolyline> > kvp) => kvp.Value.Count > 1);
            }
            return((from pairs in tablePolyline
                    from line in pairs.Value
                    select line into ln
                    group ln by ln.Id into grp
                    select grp.First() into l
                    select l.Points).ToList());
        }
Пример #10
0
        // Returns a list of polylines (each polyine is itself a list of points)
        public List <List <ClipperLib.IntPoint> > Reduce()
        {
            // Combine all the polylines together
            // We should end up with a table of polylines where each key has only one entry
            var set = m_TablePolyline.FirstOrDefault(kvp => kvp.Value.Count > 1);

            while (set.Value != null)
            {
                // The set is guaranteed to have at least two polylines in it
                // Combine the first and reverse-second polylines into a bigger polyline
                // Remove both polylines from the table
                // Add the combined polyline
                var polylines          = set.Value.ToList();
                InternalPolyline line0 = polylines[0];
                InternalPolyline line1 = polylines[1];

                RemovePolyline(line0);
                RemovePolyline(line1);
                CombinePolyline(line0, line1);

                // Look for the next group of polylines that share an endpoint
                set = m_TablePolyline.FirstOrDefault(kvp => kvp.Value.Count > 1);
            }

            // The resulting lines will be in the table twice so make the list unique on Polyline Id
            var unique = from pairs in m_TablePolyline
                         from line in pairs.Value
                         select line;

            unique = unique.GroupBy(ln => ln.Id).Select(grp => grp.First());

            var lines = from l in unique
                        select l.Points;

            return(lines.ToList());
        }
Пример #11
0
        private void RemovePolyline(InternalPolyline polyline)
        {
            var removes = from pairs in this.tablePolyline
                          from line in pairs.Value
                          where line.Id == polyline.Id
                          select line;

            var removeList = removes.ToList();
            foreach (var rem in removeList)
            {
                this.tablePolyline.Remove(rem.Points.Last(), rem);
            }
        }