Beispiel #1
0
 public virtual void TestEllipseNotSweepNotLarge()
 {
     EllipticalCurveTo.EllipseArc arc = EllipticalCurveTo.EllipseArc.GetEllipse(new Point(0, 0), new Point(20,
                                                                                                           0), 30, 10, false, false);
     AssertPointEqual(new Point(-20, -19.428090), arc.ll);
     AssertPointEqual(new Point(40, 0.5719095), arc.ur);
     NUnit.Framework.Assert.AreEqual(38.942441, arc.extent, DELTA);
     NUnit.Framework.Assert.AreEqual(70.528779, arc.startAng, DELTA);
 }
Beispiel #2
0
 public virtual void TestCircleNotSweepNotLarge()
 {
     EllipticalCurveTo.EllipseArc arc = EllipticalCurveTo.EllipseArc.GetEllipse(new Point(0, 0), new Point(20,
                                                                                                           0), 10, 10, false, false);
     AssertPointEqual(new Point(0, -10), arc.ll);
     AssertPointEqual(new Point(20, 10), arc.ur);
     NUnit.Framework.Assert.AreEqual(180, arc.extent, DELTA);
     NUnit.Framework.Assert.AreEqual(0, arc.startAng, DELTA);
 }
Beispiel #3
0
 public virtual void TestEllipseNotSweepLarge()
 {
     EllipticalCurveTo.EllipseArc arc = EllipticalCurveTo.EllipseArc.GetEllipse(new Point(0, 0), new Point(20,
                                                                                                           0), 30, 10, false, true);
     AssertPointEqual(new Point(-20, -0.571909), arc.ll);
     AssertPointEqual(new Point(40, 19.428090), arc.ur);
     NUnit.Framework.Assert.AreEqual(321.057558, arc.extent, DELTA);
     NUnit.Framework.Assert.AreEqual(289.4712206344907, arc.startAng, DELTA);
 }
            internal static EllipticalCurveTo.EllipseArc GetEllipse(Point start, Point end, double a, double b, bool sweep
                                                                    , bool largeArc)
            {
                double r1     = (start.x - end.x) / (-2.0 * a);
                double r2     = (start.y - end.y) / (2.0 * b);
                double factor = Math.Sqrt(r1 * r1 + r2 * r2);

                if (factor > 1)
                {
                    /* If rx, ry and φ are such that there is no solution (basically, the ellipse is not big enough
                     * to reach from (x1, y1) to (x2, y2)) then the ellipse's semi-axes are scaled up uniformly
                     * until there is exactly one solution (until the ellipse is just big enough).
                     */
                    return(GetEllipse(start, end, a * factor, b * factor, sweep, largeArc));
                }
                double between1 = Math.Atan(r1 / r2);
                double between2 = Math.Asin(factor);

                EllipticalCurveTo.EllipseArc result = CalculatePossibleMiddle(start, end, a, b, between1 + between2, sweep
                                                                              , largeArc);
                if (result != null)
                {
                    return(result);
                }
                result = CalculatePossibleMiddle(start, end, a, b, Math.PI + between1 - between2, sweep, largeArc);
                if (result != null)
                {
                    return(result);
                }
                result = CalculatePossibleMiddle(start, end, a, b, Math.PI + between1 + between2, sweep, largeArc);
                if (result != null)
                {
                    return(result);
                }
                result = CalculatePossibleMiddle(start, end, a, b, between1 - between2, sweep, largeArc);
                if (result != null)
                {
                    return(result);
                }
                throw new SvgProcessingException(SvgExceptionMessageConstant.COULD_NOT_DETERMINE_MIDDLE_POINT_OF_ELLIPTICAL_ARC
                                                 );
            }