private void createPolygon(PointCollection points)
        {
            pcvoPolygon p = new pcvoPolygon();
            p.points = points;

            polygons.Add(p);
            canvas.Children.Add(p.getPolygon());
        }
        private void canvas_clickHandler(object sender, MouseButtonEventArgs e)
        {
            Point position = e.GetPosition(canvas);

            points.Add(new Point(position.X, position.Y));

            if (points.Count > 1)
            {
                Point begin = points[0];
                Point end = points[points.Count - 1];

                if (withinRange(begin, end))
                {
                    PointCollection polygonPoints = points.Clone();
                    polygonPoints.RemoveAt(points.Count - 1);
                    createPolygon(polygonPoints);

                    points.Clear();
                    refreshCanvas(canvas);

                    pcvoPolygon a = new pcvoPolygon();

                }
                else
                {
                    Line line = new Line();
                    line.Visibility = System.Windows.Visibility.Visible;
                    line.StrokeThickness = 4;
                    line.Stroke = System.Windows.Media.Brushes.Black;
                    line.X1 = points[points.Count - 2].X;
                    line.X2 = points[points.Count - 1].X;
                    line.Y1 = points[points.Count - 2].Y;
                    line.Y2 = points[points.Count - 1].Y;
                    canvas.Children.Add(line);
                }
            }
        }