예제 #1
0
        Arc2d Get_arc(int i)
        {
            Arc    a         = (i == 0) ? arc1 : arc2;
            double start_deg = a.AngleStartR * math.MathUtil.Rad2Deg;
            double end_deg   = a.AngleEndR * math.MathUtil.Rad2Deg;

            if (a.PositiveRotation == true)
            {
                double tmp = start_deg;
                start_deg = end_deg;
                end_deg   = tmp;
            }
            Arc2d arc = new Arc2d(a.Center, a.Radius, start_deg, end_deg);

            // [RMS] code above does not preserve CW/CCW of arcs.
            //  It would be better to fix that. But for now, just check if
            //  we preserved start and end points, and if not reverse curves.
            if (i == 0 && arc.SampleT(0.0).DistanceSquared(Point1) > math.MathUtil.ZeroTolerance)
            {
                arc.Reverse();
            }
            if (i == 1 && arc.SampleT(1.0).DistanceSquared(Point2) > math.MathUtil.ZeroTolerance)
            {
                arc.Reverse();
            }

            return(arc);
        }
예제 #2
0
        public static void test_svg()
        {
            Polygon2d  poly  = Polygon2d.MakeCircle(100.0f, 10);
            PolyLine2d pline = new PolyLine2d();

            pline.AppendVertex(Vector2d.Zero);
            pline.AppendVertex(200 * Vector2d.AxisX);
            pline.AppendVertex(200 * Vector2d.One);
            Circle2d  circ = new Circle2d(33 * Vector2d.One, 25);
            Segment2d seg  = new Segment2d(Vector2d.Zero, -50 * Vector2d.AxisY);

            SVGWriter writer = new SVGWriter();

            writer.AddPolygon(poly, SVGWriter.Style.Filled("lime", "black", 0.25f));
            writer.AddPolyline(pline, SVGWriter.Style.Outline("orange", 2.0f));
            writer.AddCircle(circ, SVGWriter.Style.Filled("yellow", "red", 5.0f));
            writer.AddLine(seg, SVGWriter.Style.Outline("blue", 10.0f));

            int      astep = 29;
            Vector2d c     = new Vector2d(-200, 100);

            for (int k = 1; k <= 12; ++k)
            {
                Arc2d arc = new Arc2d(c + k * 45 * Vector2d.AxisX, 20, 0, k * astep);
                writer.AddArc(arc);
                writer.AddBox(arc.Bounds, SVGWriter.Style.Outline("red", 0.5f));
            }
            c.y += 50;
            for (int k = 1; k <= 12; ++k)
            {
                Arc2d arc = new Arc2d(c + k * 45 * Vector2d.AxisX, 20, k * astep, (k + 5) * astep);
                writer.AddArc(arc);
                writer.AddBox(arc.Bounds, SVGWriter.Style.Outline("red", 0.5f));
            }
            c.y += 50;
            for (int k = 1; k <= 12; ++k)
            {
                Arc2d arc = new Arc2d(c + k * 45 * Vector2d.AxisX, 20, k * astep, (k + 10) * astep);
                writer.AddArc(arc);
                writer.AddBox(arc.Bounds, SVGWriter.Style.Outline("red", 0.5f));
            }
            c.y += 50;
            for (int k = 1; k <= 12; ++k)
            {
                Arc2d arc = new Arc2d(c + k * 45 * Vector2d.AxisX, 20, k * astep, (k + 10) * astep);
                arc.Reverse();
                writer.AddArc(arc);
                writer.AddBox(arc.Bounds, SVGWriter.Style.Outline("red", 0.5f));
            }

            writer.Write(TestUtil.GetTestOutputPath("test.svg"));
        }