Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 public void DebugPrint()
 {
     System.Console.WriteLine("biarc fit Pt0 {0} Pt1 {1}  Tan0 {2} Tan1 {3}", Point1, Point2, Tangent1, Tangent2);
     System.Console.WriteLine("  First: Start {0} End {1}  {2}",
                              (Arc1IsSegment) ? Segment1.P0 : Arc1.SampleT(0),
                              (Arc1IsSegment) ? Segment1.P1 : Arc1.SampleT(1),
                              (Arc1IsSegment) ? "segment" : "arc");
     System.Console.WriteLine("  Second: Start {0} End {1}  {2}",
                              (Arc2IsSegment) ? Segment2.P0 : Arc2.SampleT(0),
                              (Arc2IsSegment) ? Segment2.P1 : Arc2.SampleT(1),
                              (Arc2IsSegment) ? "segment" : "arc");
 }
Ejemplo n.º 3
0
        /// <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) ? math.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);
        }