Exemplo n.º 1
0
        /// <summary>
        /// Creates a Graph by a set of boundary and internal polygons.
        /// </summary>
        /// <param name="boundaries">Boundary polygons</param>
        /// <param name="internals">Internal polygons</param>
        /// <returns name="baseGraph">Base graph</returns>
        public static BaseGraph ByBoundaryAndInternalPolygons(List <Polygon> boundaries, [DefaultArgument("[]")] List <Polygon> internals)
        {
            if (boundaries == null)
            {
                throw new NullReferenceException("boundaryPolygons");
            }
            if (internals == null)
            {
                throw new NullReferenceException("internalPolygons");
            }
            List <Polygon> input = new List <Polygon>();

            foreach (Polygon pol in boundaries)
            {
                var     vertices = pol.Vertices.Select(pt => Vertex.ByCoordinates(pt.X, pt.Y, pt.Z)).ToList();
                Polygon gPol     = Polygon.ByVertices(vertices, true);
                input.Add(gPol);
            }

            foreach (Polygon pol in internals)
            {
                var     vertices = pol.Vertices.Select(pt => Vertex.ByCoordinates(pt.X, pt.Y, pt.Z)).ToList();
                Polygon gPol     = Polygon.ByVertices(vertices, false);
                input.Add(gPol);
            }

            return(new BaseGraph(input));
        }
Exemplo n.º 2
0
        internal static bool PolygonContainsPoint(Polygon polygon, DSPoint point)
        {
            Vertex  vertex   = Points.ToVertex(point);
            var     vertices = polygon.Vertices.Select(p => Points.ToVertex(point)).ToList();
            Polygon gPolygon = null;

            gPolygon = Polygon.ByVertices(vertices, false);

            return(gPolygon.ContainsVertex(vertex));
        }
Exemplo n.º 3
0
        public static Dictionary <string, object> BuildPolygons(List <Line> lines)
        {
            if (lines == null)
            {
                throw new ArgumentNullException("lines");
            }
            if (lines.Count < 2)
            {
                throw new ArgumentException("Needs 2 or more lines", "lines");
            }

            BaseGraph g = BaseGraph.ByLines(lines);

            g.graph.BuildPolygons();

            var            gPolygons    = g.graph.Polygons;
            List <Polygon> dsPolygons   = new List <Polygon>();
            List <Line>    dsLines      = new List <Line>();
            List <Edge>    polygonEdges = new List <Edge>();

            foreach (Polygon gP in gPolygons)
            {
                var vertices = gP.Vertices.Select(v => Vertex.ByCoordinates(v.X, v.Y, v.Z)).ToList();
                if (gP.IsClosed)
                {
                    dsPolygons.Add(Polygon.ByVertices(vertices));
                }
                else if (gP.Edges.Count > 1)
                {
                    foreach (Edge edge in gP.Edges)
                    {
                        DSPoint start = Points.ToPoint(edge.StartVertex);
                        DSPoint end   = Points.ToPoint(edge.EndVertex);
                        dsLines.Add(Line.ByStartPointEndPoint(start, end));
                    }
                }
                else
                {
                    DSPoint start = Points.ToPoint(gP.Edges.First().StartVertex);
                    DSPoint end   = Points.ToPoint(gP.Edges.First().EndVertex);
                    dsLines.Add(Line.ByStartPointEndPoint(start, end));
                }
            }

            return(new Dictionary <string, object>()
            {
                { "polygons", dsPolygons },
                { "ungrouped", dsLines }
            });
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a graph by a set of closed polygons
        /// </summary>
        /// <param name="polygons">Polygons</param>
        /// <returns name="baseGraph">Base graph</returns>
        public static BaseGraph ByPolygons(List <Polygon> polygons)
        {
            if (polygons == null)
            {
                throw new NullReferenceException("polygons");
            }
            List <Polygon> input = new List <Polygon>();

            foreach (Polygon pol in polygons)
            {
                var     vertices = pol.Vertices.Select(pt => Vertex.ByCoordinates(pt.X, pt.Y, pt.Z)).ToList();
                Polygon gPol     = Polygon.ByVertices(vertices, false);
                input.Add(gPol);
            }

            return(new BaseGraph(input));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Performes a Intersection boolean operation between this polygon and a clipping one.
        /// </summary>
        /// <param name="clip"></param>
        /// <returns></returns>
        public List <Polygon> Intersection(Polygon clip)
        {
            var swLine = new SweepLine(this, clip, SweepLineType.Boolean);

            return(swLine.ComputeBooleanOperation(BooleanType.Intersection));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Performes a Difference boolean operation between this polygon and a clipping one.
        /// </summary>
        /// <param name="clip"></param>
        /// <returns></returns>
        public List <Polygon> Difference(Polygon clip)
        {
            var swLine = new SweepLine(this, clip, SweepLineType.Boolean);

            return(swLine.ComputeBooleanOperation(BooleanType.Differenece));
        }