Esempio n. 1
0
        public static ComplexShape ToTrianglesLegacy(this ComplexShape p_polygon)
        {
            ComplexShape v_trianglesShape = new ComplexShape();

            if (p_polygon != null)
            {
                foreach (var v_shape in p_polygon.Shapes)
                {
                    if (v_shape != null)
                    {
                        v_trianglesShape.AddShape(v_shape.ToTrianglesLegacy(), false);
                    }
                }
            }
            return(v_trianglesShape);
        }
Esempio n. 2
0
        /// <summary>
        /// Converts image data transfer object to an entity
        /// </summary>
        /// <returns>Entity object</returns>
        private ComplexShape ConvertDTOToComponent(CreateComplexShapeRequestDTO complexShapeDto)
        {
            var complexShape = new ComplexShape();

            complexShape.Id   = complexShapeDto.Id;
            complexShape.Name = complexShapeDto.Name;

            if (complexShape.Effects != null)
            {
                foreach (var effect in complexShapeDto.Effects)
                {
                    complexShape.Effects.Add(effect);
                }
            }

            foreach (var shape in complexShapeDto.Shapes)
            {
                BaseObject component = null;

                switch (shape.Type)
                {
                case "Square":
                {
                    component = new Square()
                    {
                        Effects   = shape.Effects,
                        PositionX = shape.StartPositionX,
                        PositionY = shape.StartPositionY,
                        Width     = shape.Width
                    };
                    break;
                }

                case "Circle":
                {
                    component = new Circle()
                    {
                        Effects   = shape.Effects,
                        PositionX = shape.StartPositionX,
                        PositionY = shape.StartPositionY,
                        Radius    = shape.Width
                    };
                    break;
                }

                case "Line":
                {
                    component = new Line()
                    {
                        Effects      = shape.Effects,
                        PositionX    = shape.StartPositionX,
                        PositionY    = shape.StartPositionY,
                        EndPositionX = shape.EndPositionX,
                        EndPositionY = shape.EndPositionY
                    };
                    break;
                }

                default:
                    break;
                }
                if (component != null)
                {
                    complexShape.AddShape(component);
                }
            }

            return(complexShape);
        }
        public static ComplexShape ToTriangles(this ComplexShape p_polygon)
        {
            var v_trianglesShape           = new ComplexShape();
            List <PolygonShape> v_holes    = p_polygon.GetHoles();
            List <PolygonShape> v_nonHoles = p_polygon.GetNonHoles();
            Dictionary <PolygonShape, List <PolygonShape> > v_shapeAndHoles = new Dictionary <PolygonShape, List <PolygonShape> >();

            foreach (var v_shape in v_nonHoles)
            {
                if (!v_shapeAndHoles.ContainsKey(v_shape))
                {
                    v_shapeAndHoles.Add(v_shape, new List <PolygonShape>());
                }
            }
            //Build dictionary that contains Hole Hierarchy per Shape
            foreach (var v_hole in v_holes)
            {
                foreach (var v_shape in v_nonHoles)
                {
                    bool v_isInsideShape = true;
                    //Detect if Point is in Shape
                    foreach (var v_holeVertice in v_hole.Vertices)
                    {
                        if (!v_shape.PointInShape(v_holeVertice))
                        {
                            v_isInsideShape = false;
                            break;
                        }
                    }
                    if (v_isInsideShape)
                    {
                        if (!v_shapeAndHoles[v_shape].Contains(v_hole))
                        {
                            v_shapeAndHoles[v_shape].Add(v_hole);
                        }
                        break;
                    }
                }
            }

            if (v_shapeAndHoles.Count > 0)
            {
                PolygonSet v_polygonSet = new PolygonSet();

                foreach (var v_shape in v_shapeAndHoles.Keys)
                {
                    var v_P2TPolygon = v_shape.ToP2TPolygon(v_shapeAndHoles[v_shape]);
                    if (v_P2TPolygon != null)
                    {
                        v_polygonSet.Add(v_P2TPolygon);
                    }
                }
                P2T.Triangulate(v_polygonSet);

                foreach (var v_P2TPolygon in v_polygonSet.Polygons)
                {
                    foreach (var v_P2TTriangle in v_P2TPolygon.Triangles)
                    {
                        PolygonShape v_triangle = new PolygonShape();
                        foreach (var v_point in v_P2TTriangle.Points)
                        {
                            v_triangle.Vertices.Add(new Vector2((float)v_point.X, (float)v_point.Y));
                        }
                        if (v_triangle.GetPolygonArea() != 0)
                        {
                            v_triangle.RecalcBounds();
                            if (!v_triangle.IsOrientedClockwise())
                            {
                                v_triangle.ReverseOrientation();
                            }
                            v_trianglesShape.AddShape(v_triangle, false);
                        }
                    }
                }
            }
            return(v_trianglesShape);
        }