/// <summary>
            /// Initializes a new instance of the <c>HatchBoundaryPath.Polyline</c> class.
            /// </summary>
            /// <param name="entity"><see cref="EntityObject">Entity</see> that represents the edge.</param>
            public Polyline(EntityObject entity)
                : base(EdgeType.Polyline)
            {
                if (entity == null)
                {
                    throw new ArgumentNullException(nameof(entity));
                }

                if (entity.Type == EntityType.Polyline2D)
                {
                    Entities.Polyline2D poly = (Entities.Polyline2D)entity;
                    this.IsClosed = poly.IsClosed;
                    this.Vertexes = new Vector3[poly.Vertexes.Count];
                    for (int i = 0; i < poly.Vertexes.Count; i++)
                    {
                        this.Vertexes[i] = new Vector3(poly.Vertexes[i].Position.X, poly.Vertexes[i].Position.Y, poly.Vertexes[i].Bulge);
                    }
                }
                else if (entity.Type == EntityType.Polyline3D)
                {
                    Matrix3 trans = MathHelper.ArbitraryAxis(entity.Normal).Transpose();

                    Entities.Polyline3D poly = (Entities.Polyline3D)entity;
                    this.IsClosed = poly.IsClosed;
                    this.Vertexes = new Vector3[poly.Vertexes.Count];
                    for (int i = 0; i < poly.Vertexes.Count; i++)
                    {
                        Vector3 point = trans * poly.Vertexes[i];
                        this.Vertexes[i] = new Vector3(point.X, point.Y, 0.0);
                    }
                }
                else
                {
                    throw new ArgumentException("The entity is not a Polyline2D or a Polyline3D", nameof(entity));
                }
            }
        private void SetInternalInfo(IEnumerable <EntityObject> contour, bool clearEdges)
        {
            bool containsPolyline = false;

            if (clearEdges)
            {
                this.edges.Clear();
            }

            foreach (EntityObject entity in contour)
            {
                if (containsPolyline)
                {
                    throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                }

                // it seems that AutoCad does not have problems on creating loops that theoretically does not make sense,
                // like, for example, an internal loop that is made of a single arc.
                // so if AutoCAD is OK with that I am too, the program that make use of this information will take care of this inconsistencies
                switch (entity.Type)
                {
                case EntityType.Arc:
                    this.edges.Add(Arc.ConvertFrom(entity));
                    break;

                case EntityType.Circle:
                    this.edges.Add(Arc.ConvertFrom(entity));
                    break;

                case EntityType.Ellipse:
                    this.edges.Add(Ellipse.ConvertFrom(entity));
                    break;

                case EntityType.Line:
                    this.edges.Add(Line.ConvertFrom(entity));
                    break;

                case EntityType.Polyline2D:
                    Entities.Polyline2D lwpoly = (Entities.Polyline2D)entity;
                    if (lwpoly.IsClosed)
                    {
                        if (this.edges.Count != 0)
                        {
                            throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                        }
                        this.edges.Add(Polyline.ConvertFrom(entity));
                        this.pathType   |= HatchBoundaryPathTypeFlags.Polyline;
                        containsPolyline = true;
                    }
                    else
                    {
                        this.SetInternalInfo(lwpoly.Explode(), false);     // open polylines will always be exploded, only one polyline can be present in a path
                    }
                    break;

                case EntityType.Polyline3D:
                    Entities.Polyline3D poly = (Entities.Polyline3D)entity;
                    if (poly.IsClosed)
                    {
                        if (this.edges.Count != 0)
                        {
                            throw new ArgumentException("Closed polylines cannot be combined with other entities to make a hatch boundary path.");
                        }
                        this.edges.Add(Polyline.ConvertFrom(entity));
                        this.pathType   |= HatchBoundaryPathTypeFlags.Polyline;
                        containsPolyline = true;
                    }
                    else
                    {
                        this.SetInternalInfo(poly.Explode(), false);     // open polylines will always be exploded, only one polyline can be present in a path
                    }
                    break;

                case EntityType.Spline:
                    this.edges.Add(Spline.ConvertFrom(entity));
                    break;

                default:
                    throw new ArgumentException(string.Format("The entity type {0} cannot be part of a hatch boundary. Only Arc, Circle, Ellipse, Line, Polyline2D, Polyline3D, and Spline entities are allowed.", entity.Type));
                }
            }
        }