예제 #1
0
        private static Rect FindValuePosition(CircleSegment shape, System.Windows.Size size)
        {
            Vector offset = -(Vector)size / 2;
            double angle  = shape.Angle;

            int    numMaxIterations = Math.Max(1, (int)Math.Log(shape.Circle.Radius, 2));
            double minimum          = 0.5;
            double maximum          = 1;
            double current          = minimum;
            double fittinRadius     = current;

            for (int i = 0; i < numMaxIterations; ++i)
            {
                Rect rect = FindRectangle(shape.Circle, current, angle, offset, size);

                if (shape.Contains(rect))
                {
                    maximum      = current;
                    fittinRadius = current;
                }
                else
                {
                    minimum = current;
                }

                if (maximum == minimum)
                {
                    break;
                }

                current = minimum + (maximum - minimum) / 2;
            }

            return(FindRectangle(shape.Circle, fittinRadius, angle, offset, size));
        }
예제 #2
0
        public void TestContains2()
        {
            var segment = new CircleSegment
            {
                Circle =
                {
                    Center = new Point(0, 0),
                    Radius = 5
                },
                StartAngle = Math.PI,
                EndAngle   = Math.PI * 1.5
            };

            segment.Contains(new Rect(0, 0, 0, 0)).Should().BeTrue();
            segment.Contains(new Rect(0, -1.1, 1, 1)).Should().BeTrue();
        }
예제 #3
0
        public void TestContains4()
        {
            var segment = new CircleSegment
            {
                Circle =
                {
                    Radius = 1
                },
            };

            segment.Contains(new Point(0.5, 0.5)).Should().BeFalse();
        }
예제 #4
0
        public void TestContains3()
        {
            var segment = new CircleSegment
            {
                Circle =
                {
                    Center = new Point(300, 300),
                    Radius = 200
                },
                StartAngle = 0,
                EndAngle   = Math.PI / 2
            };

            segment.Contains(new Point(250, 350)).Should().BeTrue();
        }
예제 #5
0
        public void TestContains1()
        {
            var segment = new CircleSegment
            {
                Circle =
                {
                    Center = new Point(0, 0),
                    Radius = 5
                },
                StartAngle = Math.PI / 2,
                EndAngle   = Math.PI
            };

            segment.Contains(segment.Circle.Center).Should().BeTrue("because a circle segment should contain its center");
            segment.Contains(segment.StartPoint).Should().BeTrue("because a circle segment should contain its corners");
            segment.Contains(segment.EndPoint).Should().BeTrue("because a circle segment should contain its corners");

            segment.Contains(new Point(-2, -2)).Should().BeTrue("because the point lies in the center of the circle segment");
            segment.Contains(new Point(-3, -3)).Should().BeTrue("because the point lies in the center of the circle segment");

            segment.Contains(new Point(6, 0)).Should().BeFalse();
            segment.Contains(new Point(-6, 0)).Should().BeFalse();
            segment.Contains(new Point(0, 6)).Should().BeFalse();
            segment.Contains(new Point(0, -6)).Should().BeFalse();

            segment.Contains(new Point(2, 2)).Should().BeFalse("because the point lies in the wrong slice of the circle");
            segment.Contains(new Point(-2, 2)).Should().BeFalse("because the point lies in the wrong slice of the circle");
            segment.Contains(new Point(2, -2)).Should().BeFalse("because the point lies in the wrong slice of the circle");
        }