Beispiel #1
0
        public static void Restore(out IParametricCurve2d curve, BinaryReader reader)
        {
            curve = null;
            int nType = reader.ReadInt32();

            if (nType == 1)
            {
                Segment2d segment = new Segment2d();
                Restore(ref segment, reader);
                curve = segment;
            }
            else if (nType == 2)
            {
                Circle2d circle = new Circle2d(Vector2d.Zero, 1.0);
                Restore(ref circle, reader);
                curve = circle;
            }
            else if (nType == 3)
            {
                Arc2d arc = new Arc2d(Vector2d.Zero, 1.0, 0, 1);
                Restore(ref arc, reader);
                curve = arc;
            }
            else if (nType == 100)
            {
                ParametricCurveSequence2 seq = new ParametricCurveSequence2();
                Restore(ref seq, reader);
                curve = seq;
            }
            else
            {
                throw new Exception("gSerialization.Restore: IParametricCurve2D : unknown curve type " + nType.ToString());
            }
        }
Beispiel #2
0
        Arc2d get_arc(int i)
        {
            Arc    a         = (i == 0) ? arc1 : arc2;
            double start_deg = a.AngleStartR * MathUtil.Rad2Deg;
            double end_deg   = a.AngleEndR * 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) > MathUtil.ZeroTolerance)
            {
                arc.Reverse();
            }
            if (i == 1 && arc.SampleT(1.0).DistanceSquared(Point2) > MathUtil.ZeroTolerance)
            {
                arc.Reverse();
            }

            return(arc);
        }
Beispiel #3
0
        // currently fit is computed in constructor
        public BiArcFit2(Vector2d point1, Vector2d tangent1, Vector2d point2, Vector2d tangent2)
        {
            Point1 = point1; Tangent1 = tangent1;
            Point2 = point2; Tangent2 = tangent2;
            Fit();

            if (arc1.IsSegment)
            {
                Arc1IsSegment = true;
                Segment1      = new Segment2d(arc1.P0, arc1.P1);
            }
            else
            {
                Arc1IsSegment = false;
                Arc1          = get_arc(0);
            }

            if (arc2.IsSegment)
            {
                Arc2IsSegment = true;
                Segment2      = new Segment2d(arc2.P0, arc2.P1);
            }
            else
            {
                Arc2IsSegment = false;
                Arc2          = get_arc(1);
            }
        }
Beispiel #4
0
 public static void Restore(ref Arc2d arc, BinaryReader reader)
 {
     arc.Center.x      = reader.ReadDouble();
     arc.Center.y      = reader.ReadDouble();
     arc.Radius        = reader.ReadDouble();
     arc.AngleStartDeg = reader.ReadDouble();
     arc.AngleEndDeg   = reader.ReadDouble();
     arc.IsReversed    = reader.ReadBoolean();
 }
Beispiel #5
0
 public static void Store(Arc2d arc, BinaryWriter writer)
 {
     writer.Write(arc.Center.x);
     writer.Write(arc.Center.y);
     writer.Write(arc.Radius);
     writer.Write(arc.AngleStartDeg);
     writer.Write(arc.AngleEndDeg);
     writer.Write(arc.IsReversed);
 }
        void write_arc(Arc2d arc, StreamWriter w)
        {
            StringBuilder b      = new StringBuilder();
            Vector2d      vStart = MapPt(arc.P0);
            Vector2d      vEnd   = MapPt(arc.P1);

            b.Append("<path ");
            b.Append("d=\"");

            // move to start coordinates
            b.Append("M");
            b.Append(Math.Round(vStart.x, Precision));
            b.Append(",");
            b.Append(Math.Round(vStart.y, Precision));
            b.Append(" ");

            // start arc
            b.Append("A");

            // radii (write twice because this is actually elliptical arc)
            b.Append(Math.Round(arc.Radius, Precision));
            b.Append(",");
            b.Append(Math.Round(arc.Radius, Precision));
            b.Append(" ");

            b.Append("0 ");     // x-axis-rotation

            int large = (arc.AngleEndDeg - arc.AngleStartDeg) > 180 ? 1 : 0;
            int sweep = (arc.IsReversed) ? 1 : 0;

            b.Append(large);
            b.Append(",");
            b.Append(sweep);

            // end coordinates
            b.Append(Math.Round(vEnd.x, Precision));
            b.Append(",");
            b.Append(Math.Round(vEnd.y, Precision));

            b.Append("\" ");     // close path

            append_style(b, arc, ref DefaultArcStyle);


            b.Append(" />");
            w.WriteLine(b);
        }
        /// <summary>
        /// This is a utility function that returns the set of border points, which
        /// is useful when we use a roundrect as a UI element and want the border
        /// </summary>
        public Vector3d[] GetBorderLoop()
        {
            int corner_v = 0;

            for (int k = 0; k < 4; ++k)
            {
                if (((int)SharpCorners & (1 << k)) != 0)
                {
                    corner_v += 1;
                }
                else
                {
                    corner_v += CornerSteps;
                }
            }

            float innerW = Width - 2 * Radius;
            float innerH = Height - 2 * Radius;

            Vector3d[] vertices = new Vector3d[4 + corner_v];
            int        vi       = 0;

            for (int i = 0; i < 4; ++i)
            {
                vertices[vi++] = new Vector3d(signx[i] * Width / 2, 0, signy[i] * Height / 2);

                bool  sharp = ((int)SharpCorners & (1 << i)) > 0;
                Arc2d arc   = new Arc2d(new Vector2d(signx[i] * innerW, signy[i] * innerH),
                                        (sharp) ? MathUtil.SqrtTwo * Radius : Radius,
                                        startangle[i], endangle[i]);
                int use_steps = (sharp) ? 1 : CornerSteps;
                for (int k = 0; k < use_steps; ++k)
                {
                    double   t   = (double)(i + 1) / (double)(use_steps + 1);
                    Vector2d pos = arc.SampleT(t);
                    vertices[vi++] = new Vector3d(pos.x, 0, pos.y);
                }
            }

            return(vertices);
        }
Beispiel #8
0
        void set_output()
        {
            if (arc1.IsSegment)
            {
                Arc1IsSegment = true;
                Segment1      = new Segment2d(arc1.P0, arc1.P1);
            }
            else
            {
                Arc1IsSegment = false;
                Arc1          = get_arc(0);
            }

            if (arc2.IsSegment)
            {
                Arc2IsSegment = true;
                Segment2      = new Segment2d(arc2.P1, arc2.P0);
            }
            else
            {
                Arc2IsSegment = false;
                Arc2          = get_arc(1);
            }
        }
 public void AddArc(Arc2d arc, Style style)
 {
     Objects.Add(arc);
     Styles[arc] = style;
     Bounds.Contain(arc.Bounds);
 }
Beispiel #10
0
 public void AddArc(Arc2d arc)
 {
     Objects.Add(arc);
     Bounds.Contain(arc.Bounds);
 }
 public void AddArc(Arc2d arc)
 {
     CurrentLayer.Objects.Add(arc);
     Bounds.Contain(arc.Bounds);
 }