//added code SD : keeps all the points in the new polygon formed
        internal Polygon2d(List <Point2d> points, int dummy = 0)
        {
            if (points == null)
            {
                m_bbox   = null;
                m_points = points;
                return;
            }
            if (points.Count < 3)
            {
                m_bbox   = null;
                m_points = points;
                return;
            }
            m_points = new List <Point2d>();
            foreach (Point2d point in points)
            {
                m_points.Add(new Point2d(point));
            }

            m_bbox = null;
            foreach (Point2d point in points)
            {
                m_bbox = new Range2d(m_bbox, point);
            }
        }
 internal Grid2d(Outline2d outline, GridBasis basis)
 {
     m_outline = outline;
     m_basis   = basis;
     m_extents = m_basis.Extend(m_outline.BBox);
     m_axes    = null;
 }
예제 #3
0
 internal Outline2d(List <Polygon2d> polygons)
 {
     m_polygons = polygons;
     m_bbox     = null;
     foreach (Polygon2d polygon in polygons)
     {
         m_bbox = new Range2d(m_bbox, polygon.BBox);
     }
 }
예제 #4
0
        internal Outline2d(List <Line2d> rawLines)
        {
            if (rawLines == null || rawLines.Count < 1)
            {
                m_polygons = null;
                m_bbox     = null;
                return;
            }

            m_polygons = new List <Polygon2d>();
            m_bbox     = null;

            int    nextIndex = 0;
            Line2d firstLine = rawLines[nextIndex];

            List <Point2d> points = new List <Point2d>();

            points.Add(firstLine.StartPoint);

            Line2d currentLine = firstLine;
            bool   start       = true;

            while (rawLines.Count > 0)
            {
                currentLine = rawLines[nextIndex];
                rawLines.RemoveAt(nextIndex);
                nextIndex = 0;

                Point2d testPoint = GetPoint(currentLine, !start);
                int     index     = GetClosestLine(testPoint, rawLines, (currentLine == firstLine) ? null : firstLine, ref start);
                if (index == -1)
                {
                    Polygon2d polygon = new Polygon2d(points);
                    m_polygons.Add(polygon);
                    m_bbox = new Range2d(m_bbox, polygon.BBox.Min);
                    m_bbox = new Range2d(m_bbox, polygon.BBox.Max);

                    points.Clear();
                    if (rawLines.Count > 0)
                    {
                        firstLine = rawLines[nextIndex];
                        points.Add(firstLine.StartPoint);
                    }
                }
                else
                {
                    Point2d point = currentLine.Heal(rawLines[index], false);
                    if (point != null)
                    {
                        points.Add(point);
                    }
                    nextIndex = index;
                }
            }
        }
예제 #5
0
 public Range2d(Range2d r0, Range2d r1)
 {
     if (r0 == null)
     {
         m_x = new Range1d(r1.m_x);
         m_y = new Range1d(r1.m_y);
     }
     else
     {
         m_x = new Range1d(r0.m_x, r1.m_x);
         m_y = new Range1d(r0.m_y, r1.m_y);
     }
 }
예제 #6
0
 public Range2d(Range2d other, Point2d point)
 {
     if (other == null)
     {
         m_x = new Range1d(point.X, point.X);
         m_y = new Range1d(point.Y, point.Y);
     }
     else
     {
         m_x = new Range1d(other.m_x, point.X);
         m_y = new Range1d(other.m_y, point.Y);
     }
 }
예제 #7
0
        public bool Compare(Range2d value)
        {
            if (!value.m_x.Compare(m_x))
            {
                return(false);
            }
            if (!value.m_y.Compare(m_y))
            {
                return(false);
            }

            return(true);
        }
        public Range2d Extend(Range2d extents)
        {
            if (extents == null)
            {
                return(null);
            }

            Range2d extended = null;

            extended = new Range2d(extended, InflateToGrid(extents.Min));
            extended = new Range2d(extended, InflateToGrid(extents.Max));

            return(extended);
        }
        public static Polygon PolygonByBBox2d(Range2d bbox, double height)
        {
            if (bbox == null)
            {
                return(null);
            }
            List <Point> points = new List <Point>();

            points.Add(Point.ByCoordinates(bbox.Min.X, bbox.Min.Y, height));
            points.Add(Point.ByCoordinates(bbox.Max.X, bbox.Min.Y, height));
            points.Add(Point.ByCoordinates(bbox.Max.X, bbox.Max.Y, height));
            points.Add(Point.ByCoordinates(bbox.Min.X, bbox.Max.Y, height));

            return(Polygon.ByPoints(points));
        }
        internal Polygon2d(List <Point2d> points)
        {
            if (points == null || points.Count == 0)
            {
                m_bbox   = null;
                m_points = points;
                return;
            }
            m_points = new List <Point2d>();
            foreach (Point2d point in points)
            {
                m_points.Add(new Point2d(point));
            }

            bool removed = false;

            do
            {
                removed = false;
                for (int index = 0; index < m_points.Count; ++index)
                {
                    int      idxPre  = (index == 0) ? m_points.Count - 1 : index - 1;
                    int      idxPost = (index == m_points.Count - 1) ? 0 : index + 1;
                    Point2d  p0      = m_points[idxPre];
                    Point2d  p1      = m_points[index];
                    Point2d  p2      = m_points[idxPost];
                    Vector2d v0      = new Vector2d(p0, p1).Normalize();
                    Vector2d v1      = new Vector2d(p0, p2).Normalize();
                    if (v0.Dot(v1).Compare(1))
                    {
                        m_points.RemoveAt(index);
                        removed = true;
                    }
                }
            }while (removed);

            m_bbox = null;
            foreach (Point2d point in points)
            {
                m_bbox = new Range2d(m_bbox, point);
            }
        }