コード例 #1
0
        public CircleSegment FindSegment(float dX, float dY)
        {
            double rad   = Math.Sqrt(dX * dX + dY * dY);
            double angle = SysUtils.RadiansToDegrees(Math.Atan2(dY, dX));

            if (angle <= -90)
            {
                angle += 360.0f;
            }

            CircleSegment result = null;

            int numberOfSegments = fSegments.Count;

            for (int i = 0; i < numberOfSegments; i++)
            {
                CircleSegment segment  = fSegments[i];
                double        startAng = segment.StartAngle;
                double        endAng   = startAng + segment.WedgeAngle;

                if ((segment.IntRad <= rad && rad < segment.ExtRad) &&
                    (startAng <= angle && angle < endAng))
                {
                    result = segment;
                    break;
                }
            }

            return(result);
        }
コード例 #2
0
        public void GfxHelper_Tests()
        {
            Assert.AreEqual(57.295779513, SysUtils.RadiansToDegrees(1.0), 0.0000000001);
            Assert.AreEqual(1.0, SysUtils.DegreesToRadians(57.295779513), 0.0000000001);

            Assert.AreEqual(2.0, SysUtils.ZoomToFit(50, 20, 100, 50));
            Assert.AreEqual(3.0, SysUtils.ZoomToFit(15, 40, 45, 120));

            Assert.AreEqual(1.0, SysUtils.ZoomToFit(0, 40, 45, 120));
            Assert.AreEqual(1.0, SysUtils.ZoomToFit(15, 0, 45, 120));
        }
コード例 #3
0
        public override void DrawArcText(string text, float centerX, float centerY, float radius,
                                         float startAngle, float wedgeAngle,
                                         bool inside, bool clockwise, IFont font, IBrush brush)
        {
            ExtSizeF size = GetTextSize(text, font);

            radius = radius + size.Height / 2.0f;

            float textAngle  = Math.Min((float)SysUtils.RadiansToDegrees((size.Width * 1.75f) / radius), wedgeAngle);
            float deltaAngle = (wedgeAngle - textAngle) / 2.0f;

            if (clockwise)
            {
                startAngle += deltaAngle;
            }
            else
            {
                startAngle += wedgeAngle - deltaAngle;
            }
            startAngle = -startAngle;

            Matrix previousTransformation = fCanvas.Transform;

            for (int i = 0; i < text.Length; ++i)
            {
                float offset = (textAngle * ((float)(i) / text.Length));
                float angle  = clockwise ? startAngle - offset : startAngle + offset;

                double radAngle     = angle * (Math.PI / 180.0d);
                float  x            = (float)(centerX + Math.Cos(radAngle) * radius);
                float  y            = (float)(centerY - Math.Sin(radAngle) * radius);
                float  charRotation = 90 - (inside ? angle : angle + 180);
                charRotation *= (float)(Math.PI / 180.0f);
                float cosine = (float)(Math.Cos(charRotation));
                float sine   = (float)(Math.Sin(charRotation));

                Matrix m = new Matrix(cosine, sine, -sine, cosine, x, y);
                m.Multiply(previousTransformation, MatrixOrder.Append);
                fCanvas.Transform = m;

                string chr = new string(text[i], 1);
                DrawString(chr, font, brush, 0, 0);
            }

            fCanvas.Transform = previousTransformation;
        }