示例#1
0
        private void CopyCommandExecuted(object sender, ExecutedRoutedEventArgs args)
        {
            args.Handled = true;

            try {
                LineD[] lines = _division.ToLines();
                string  text  = XmlSerialization.Serialize <LineD[]>(lines);
                Clipboard.SetText(text);
            }
            catch (Exception e) {
                MessageDialog.Show(this,
                                   "An error occurred while attempting to copy\n" +
                                   "the current subdivision to the clipboard.",
                                   Strings.ClipboardCopyError, e, MessageBoxButton.OK,
                                   WindowsUtility.GetSystemBitmap(MessageBoxImage.Error));
            }
        }
        public static Subdivision CreateTriforce(bool test)
        {
            PointD[] points =
            {
                new PointD(-5, -4), new PointD(0,  6), new PointD(5, -4),
                new PointD(0,   0), new PointD(-1, 2), new PointD(1, 2)
            };
            LineD[] lines =
            {
                new LineD(points[0], points[1]), new LineD(points[2], points[1]),
                new LineD(points[0], points[2]), new LineD(points[3], points[4]),
                new LineD(points[3], points[5]), new LineD(points[4], points[5])
            };

            Subdivision division = Subdivision.FromLines(lines);

            division.Validate();
            if (!test)
            {
                return(division);
            }

            CollectionAssert.AreEquivalent(lines, division.ToLines());
            var edges = division.Edges.Values;
            var faces = division.Faces.Values;

            CollectionAssert.AreEqual(new[] {
                new VertexPair(points[0], edges[0]),
                new VertexPair(points[2], edges[2]),
                new VertexPair(points[3], edges[6]),
                new VertexPair(points[4], edges[7]),
                new VertexPair(points[5], edges[9]),
                new VertexPair(points[1], edges[1]),
            }, division.Vertices);

            CollectionAssert.AreEqual(new[] {
                new SubdivisionEdge(0, points[0], edges[1], faces[0], edges[3], edges[5]),
                new SubdivisionEdge(1, points[1], edges[0], faces[1], edges[4], edges[2]),
                new SubdivisionEdge(2, points[2], edges[3], faces[1], edges[1], edges[4]),
                new SubdivisionEdge(3, points[1], edges[2], faces[0], edges[5], edges[0]),
                new SubdivisionEdge(4, points[0], edges[5], faces[1], edges[2], edges[1]),
                new SubdivisionEdge(5, points[2], edges[4], faces[0], edges[0], edges[3]),
                new SubdivisionEdge(6, points[3], edges[7], faces[1], edges[10], edges[9]),
                new SubdivisionEdge(7, points[4], edges[6], faces[2], edges[8], edges[11]),
                new SubdivisionEdge(8, points[3], edges[9], faces[2], edges[11], edges[7]),
                new SubdivisionEdge(9, points[5], edges[8], faces[1], edges[6], edges[10]),
                new SubdivisionEdge(10, points[4], edges[11], faces[1], edges[9], edges[6]),
                new SubdivisionEdge(11, points[5], edges[10], faces[2], edges[7], edges[8]),
            }, edges);

            CollectionAssert.AreEqual(new[] {
                new SubdivisionFace(division, 0, null, new[] { edges[0] }),
                new SubdivisionFace(division, 1, edges[1], new[] { edges[6] }),
                new SubdivisionFace(division, 2, edges[7], null),
            }, faces);

            PointD centroid = new PointD(0, -2 / 3.0);

            CheckFace(edges[0], new[] { points[0], points[1], points[2] }, -50, centroid);
            CheckFace(edges[1], new[] { points[1], points[0], points[2] }, +50, centroid);

            centroid = new PointD(0, 4 / 3.0);
            CheckFace(edges[6], new[] { points[3], points[4], points[5] }, -2, centroid);
            CheckFace(edges[7], new[] { points[4], points[3], points[5] }, +2, centroid);

            var cycles = division.GetZeroAreaCycles();

            Assert.AreEqual(0, cycles.Count);
            return(division);
        }