Example #1
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values.Count() == 3)
            {
                if ((values[0] is double) && (values[1] is LfDragablePointViewModel) && (values[2] is TriangleViewModel))
                {
                    LfDragablePointViewModel origVertex = (LfDragablePointViewModel)values[1];
                    LfPolygonViewModel       polygon    = origVertex.Parent;
                    TriangleViewModel        tvm        = (TriangleViewModel)values[2];

                    int i = tvm.PointVms.IndexOf(origVertex);

                    if (i == -1)
                    {
                        return(null);
                    }

                    LfDragablePointViewModel vertex;

                    if (i > 0)
                    {
                        vertex = tvm.PointVms[i - 1];
                    }
                    else
                    {
                        vertex = tvm.PointVms[tvm.PointVms.Count() - 1];
                    }

                    Point p  = new Point(vertex.PosX, vertex.PosY);
                    Point rp = polygon.RotatedPointFromLocal(p);

                    if (parameter as string == "x")
                    {
                        return(rp.X);
                    }
                    else
                    {
                        return(rp.Y);
                    }
                }
            }

            return(null);
        }
Example #2
0
        public void GenerateTriangles()
        {
            GeometryUtility.CPoint2D[] polyVertices = new GeometryUtility.CPoint2D[PointVms.Count];

            int i = 0;

            foreach (LfDragablePointViewModel dpvm in PointVms)
            {
                // Before triangles are generated we must reorder the identities of the
                // vertices to make them consequtive
                dpvm.Id = (uint)(i + 1);

                polyVertices[i] = new GeometryUtility.CPoint2D(dpvm.PosX, dpvm.PosY, dpvm.Id);

                i++;
            }

            PolygonCuttingEar.CPolygonShape poly = new PolygonCuttingEar.CPolygonShape(polyVertices);

            poly.CutEar();

            if (LocalModelObject != null)
            {
                LocalModelObject.Triangles.Clear();
                _triangles.Clear();

                for (int n = 0; n < poly.NumberOfPolygons; n++)
                {
                    Triangle nt = new Triangle((uint)n + 1, poly.Polygons(n)[0].Id, poly.Polygons(n)[1].Id, poly.Polygons(n)[2].Id);
                    LocalModelObject.Triangles.Add(nt);

                    TriangleViewModel ntvm = new TriangleViewModel(this, nt);
                    _triangles.Add(ntvm);
                }
            }
        }