예제 #1
0
        private void OnIntersect(object sender, RoutedEventArgs args)
        {
            args.Handled = true;

            RectD  bounds = OutputBounds;
            double x      = bounds.Left + (double)LeftUpDown.Value;
            double y      = bounds.Top + (double)TopUpDown.Value;
            double dx     = (double)WidthUpDown.Value;
            double dy     = (double)HeightUpDown.Value;

            Subdivision rectangle;

            if (sender == RectangleButton)
            {
                rectangle = Subdivision.FromLines(new LineD[] {
                    new LineD(x, y, x + dx, y),
                    new LineD(x + dx, y, x + dx, y + dy),
                    new LineD(x + dx, y + dy, x, y + dy),
                    new LineD(x, y + dy, x, y)
                });
            }
            else if (sender == DiamondButton)
            {
                rectangle = Subdivision.FromLines(new LineD[] {
                    new LineD(x + dx / 2, y, x + dx, y + dy / 2),
                    new LineD(x + dx, y + dy / 2, x + dx / 2, y + dy),
                    new LineD(x + dx / 2, y + dy, x, y + dy / 2),
                    new LineD(x, y + dy / 2, x + dx / 2, y)
                });
            }
            else
            {
                return;
            }

            rectangle.Validate();
            _division = Subdivision.Intersection(_division, rectangle, out _faceKeys);
            _division.Validate();
            SubdivisionTest.DrawSubdivision(OutputBox, FontSize, _division);
        }
예제 #2
0
        private void SubdivisionTest()
        {
            Stopwatch timer     = new Stopwatch();
            var       testCases = _subdivisionTestCases;

            Output(String.Format("{0,6}", " "));
            foreach (TestCase test in testCases)
            {
                Output(String.Format("{0,12}", test.Name));
            }
            Output("\n");

            // ensure reasonable vertex spacing
            const double epsilon = 1e-6;
            const int    outerLoop = 20, innerLoop = 20;
            const int    iterations = outerLoop * innerLoop;

            Subdivision[] divisions = new Subdivision[2];

            for (int size = 20; size <= 240; size += 20)
            {
                for (int j = 0; j < outerLoop; j++)
                {
                    foreach (TestCase test in testCases)
                    {
                        for (int s = 0; s < 2; s++)
                        {
                            int count = (int)(size * (s == 0 ? test.Value : (1 - test.Value)));
                            divisions[s] = CreateSubdivision(count, epsilon);
                        }

                        // trigger JIT compilation and reset ticks
                        ValueTuple <Int32, Int32>[] faceKeys;
                        if (j == 0)
                        {
                            Subdivision.Intersection(divisions[0], divisions[1], out faceKeys);
                            test.Ticks = 0;
                        }

                        timer.Restart();
                        for (int k = 0; k < innerLoop; k++)
                        {
                            var division = Subdivision.Intersection(
                                divisions[0], divisions[1], out faceKeys);
                            division.Validate();
                        }

                        timer.Stop();
                        test.Ticks += timer.ElapsedTicks;
                    }
                }

                Output(String.Format("{0,6:N0}", size));
                foreach (TestCase test in testCases)
                {
                    Output(String.Format("{0,12:N2}", AverageMicrosecs(test.Ticks, iterations)));
                }
                Output("\n");
            }

            Output("\nTimes are µsec averages for two subdivisions with the indicated combined" +
                   "\nedge count, distributed as indicated between the two subdivisions.\n");
        }