/// <summary>
        /// Makes convex decomposition of the selected polygon if any.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void makeConvexDecompositionButton_Click(object sender, EventArgs e)
        {
            PolygonEditState polygonState = ShapesScreen.State as PolygonEditState;

            if (polygonState != null)
            {
                List <Polygon> newPolygons = polygonState.MakeConvexDecomposition();
                if (newPolygons != null && newPolygons.Count > 0)
                {
                    // remove actual polygon state
                    RemoveShape(polygonState);

                    // add new polygons
                    foreach (Polygon polygon in newPolygons)
                    {
                        shapesList.Items.Add(ShapesScreen.AddShape(polygon));
                    }

                    // select last added shape
                    shapesList.SelectedIndex = shapesList.Items.Count - 1;
                }
            }

            ShapesScreen.Invalidate();
        }
        /// <summary>
        /// Makes convex hull of the selected polygon if any.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void makeConvexHullButton_Click(object sender, EventArgs e)
        {
            PolygonEditState polygonState = ShapesScreen.State as PolygonEditState;

            if (polygonState != null)
            {
                polygonState.MakeConvexHull();
            }

            ShapesScreen.Invalidate();
        }
Beispiel #3
0
        /// <summary>
        /// Adds the specified shape to the screen.
        /// </summary>
        /// <param name="shape">Shape to add</param>
        /// <returns>Returns <see cref="ShapeState"/> of the added shape.</returns>
        public ShapeState AddShape(Shape shape)
        {
            ShapeState newState = null;

            switch (shape.Type)
            {
            case Shape.ShapeType.Polygon:
                newState = new PolygonEditState((Polygon)shape, this)
                {
                    Color = ColorSettings.GoodColors[goodColorsIndex]
                };
                State = newState;
                break;

            case Shape.ShapeType.Circle:
                newState = new CircleEditState((Circle)shape, this)
                {
                    Color = ColorSettings.GoodColors[goodColorsIndex]
                };
                State = newState;
                break;

            case Shape.ShapeType.Edge:
                newState = new EdgeEditState((Edge)shape, this)
                {
                    Color = ColorSettings.GoodColors[goodColorsIndex]
                };
                State = newState;
                break;
            }

            if (newState != null)
            {
                if (++goodColorsIndex >= ColorSettings.GoodColors.Length)
                {
                    goodColorsIndex = 0;
                }
                Shapes.Add(newState);
            }

            return(newState);
        }