Example #1
0
        /// <summary>
        /// Convert a set of spiro control points into a set of bézier curves.
        /// 
        /// As it does so it will call the appropriate routine in your bézier context with this information 
        /// – this should allow you to create your own internal representation of those curves.
        /// 
        /// Open contours do not need to start with '{', nor to end with '}'.
        /// 
        /// Close contours do not need to end with 'z'.
        /// 
        /// This function is kept for backwards compatibility for older programs. 
        /// Please use the function that return success/failure replies when done.	
        /// </summary>
        /// <param name="spiros">An array of input spiros.</param>
        /// <param name="n">The number of elements in the spiros array.</param>
        /// <param name="isClosed">Whether this describes a closed (True) or open (False) contour.</param>
        /// <param name="bc">A bézier results output context.</param>
        /// <returns>An boolean success flag. True = completed task and have valid bézier results, or False = unable to complete task, bézier results are invalid.</returns>
        /// <example>
        /// var points = new SpiroControlPoint[4];
        /// points[0].X = -100; points[0].Y = 0; points[0].Type = SpiroPointType.G4;
        /// points[1].X = 0; points[1].Y = 100; points[1].Type = SpiroPointType.G4;
        /// points[2].X = 100; points[2].Y = 0; points[2].Type = SpiroPointType.G4;
        /// points[3].X = 0; points[3].Y = -100; points[3].Type = SpiroPointType.G4;
        /// var bc = new PathBezierContext();
        /// var success = Spiro.SpiroCPsToBezier0(points, 4, true, bc);
        /// Console.WriteLine(bc);
        /// Console.WriteLine("Success: {0} ", success);
        /// </example>
        public static bool SpiroCPsToBezier0(SpiroControlPoint[] spiros, int n, bool isClosed, IBezierContext bc)
        {
            SpiroSegment[] s;

            if (n <= 0)
                return false;
            if (isClosed)
                s = SpiroImpl.run_spiro(spiros, n);
            else
            {
                SpiroPointType oldty_start = spiros[0].Type;
                SpiroPointType oldty_end = spiros[n - 1].Type;
                spiros[0].Type = SpiroPointType.OpenContour;
                spiros[n - 1].Type = SpiroPointType.EndOpenContour;
                s = SpiroImpl.run_spiro(spiros, n);
                spiros[n - 1].Type = oldty_end;
                spiros[0].Type = oldty_start;
            }

            if (s != null)
            {
                SpiroImpl.spiro_to_bpath(s, n, bc);
                return true; // success
            }

            return false; // spiro did not converge or encountered non-finite values
        }
Example #2
0
        private void NewPointAt(SpiroShape shape, double x, double y, int index)
        {
            var point = new SpiroControlPoint();

            point.X    = x;
            point.Y    = y;
            point.Type = _state.PointType;
            shape.Points.Insert(index, point);
        }
Example #3
0
        private void NewPoint(SpiroShape shape, double x, double y)
        {
            var point = new SpiroControlPoint();

            point.X    = x;
            point.Y    = y;
            point.Type = _state.PointType;
            shape.Points.Add(point);
        }
Example #4
0
        private static SpiroControlPoint NewPoint(SpiroPointType type, string x, string y)
        {
            var point = new SpiroControlPoint();

            point.X    = double.Parse(x, ToStringCulture.NumberFormat);
            point.Y    = double.Parse(y, ToStringCulture.NumberFormat);
            point.Type = type;
            return(point);
        }
Example #5
0
        private void SetPointType(SpiroShape shape, int index, SpiroPointType type)
        {
            var old   = shape.Points[index];
            var point = new SpiroControlPoint();

            point.X             = old.X;
            point.Y             = old.Y;
            point.Type          = type;
            shape.Points[index] = point;
        }
Example #6
0
        private void SetPointPosition(SpiroShape shape, int index, double x, double y)
        {
            var old   = shape.Points[index];
            var point = new SpiroControlPoint();

            point.X             = x;
            point.Y             = y;
            point.Type          = old.Type;
            shape.Points[index] = point;
        }
Example #7
0
        private void SetPointPositionDelta(SpiroShape shape, int index, double dx, double dy)
        {
            var    old   = shape.Points[index];
            double x     = old.X + dx;
            double y     = old.Y + dy;
            double sx    = _state.EnableSnap && _state.SnapX != 0 ? Snap(x, _state.SnapX) : x;
            double sy    = _state.EnableSnap && _state.SnapY != 0 ? Snap(y, _state.SnapY) : y;
            var    point = new SpiroControlPoint();

            point.X             = sx;
            point.Y             = sy;
            point.Type          = old.Type;
            shape.Points[index] = point;
        }
Example #8
0
        private void DrawSpiroPoint(DrawingContext dc, Brush brush, Pen pen, SpiroControlPoint point)
        {
            switch (point.Type)
            {
            case SpiroPointType.Corner:
                dc.DrawRectangle(brush, null, new Rect(point.X - 3.5, point.Y - 3.5, 7, 7));
                break;

            case SpiroPointType.G4:
            case SpiroPointType.G2:
            case SpiroPointType.Left:
            case SpiroPointType.Right:
            case SpiroPointType.End:
            case SpiroPointType.OpenContour:
            case SpiroPointType.EndOpenContour:
                dc.PushTransform(new TranslateTransform(point.X, point.Y));
                dc.DrawGeometry(null, pen, EndKnot);
                dc.Pop();
                break;
            }
        }
Example #9
0
        private void DrawSpiroPoint(DrawingContext dc, IBrush brush, Pen pen, SpiroControlPoint point)
        {
            switch (point.Type)
            {
            case SpiroPointType.Corner:
                dc.FillRectangle(brush, new Rect(point.X - 3.5, point.Y - 3.5, 7, 7));
                break;

            case SpiroPointType.G4:
            case SpiroPointType.G2:
            case SpiroPointType.Left:
            case SpiroPointType.Right:
            case SpiroPointType.End:
            case SpiroPointType.OpenContour:
            case SpiroPointType.EndOpenContour:
                var tm = Translate(point.X, point.Y);
                var tt = dc.PushPreTransform(tm);
                dc.DrawGeometry(null, pen, EndKnot);
                tt.Dispose();
                break;
            }
        }
Example #10
0
 private void SetPointType(SpiroShape shape, int index, SpiroPointType type)
 {
     var old = shape.Points[index];
     var point = new SpiroControlPoint();
     point.X = old.X;
     point.Y = old.Y;
     point.Type = type;
     shape.Points[index] = point;
 }
Example #11
0
 private static SpiroControlPoint NewPoint(SpiroPointType type, string x, string y)
 {
     var point = new SpiroControlPoint();
     point.X = double.Parse(x, ToStringCulture.NumberFormat);
     point.Y = double.Parse(y, ToStringCulture.NumberFormat);
     point.Type = type;
     return point;
 }
Example #12
0
 private void DrawSpiroPoint(DrawingContext dc, IBrush brush, Pen pen, SpiroControlPoint point)
 {
     switch (point.Type)
     {
         case SpiroPointType.Corner:
             dc.FillRectangle(brush, new Rect(point.X - 3.5, point.Y - 3.5, 7, 7));
             break;
         case SpiroPointType.G4:
         case SpiroPointType.G2:
         case SpiroPointType.Left:
         case SpiroPointType.Right:
         case SpiroPointType.End:
         case SpiroPointType.OpenContour:
         case SpiroPointType.EndOpenContour:
             var tm = Translate(point.X, point.Y);
             var tt = dc.PushPreTransform(tm);
             dc.DrawGeometry(null, pen, EndKnot);
             tt.Dispose();
             break;
     }
 }
Example #13
0
 private void NewPoint(SpiroShape shape, double x, double y)
 {
     var point = new SpiroControlPoint();
     point.X = x;
     point.Y = y;
     point.Type = _state.PointType;
     shape.Points.Add(point);
 }
Example #14
0
 /// <summary>
 /// Convert a set of spiro control points into a set of bézier curves.
 /// 
 /// As it does so it will call the appropriate routine in your bézier context with this information 
 /// – this should allow you to create your own internal representation of those curves.
 /// 
 /// Open contours do not need to start with '{', nor to end with '}'.
 /// 
 /// Close contours do not need to end with 'z'.
 /// 
 /// This function is kept for backwards compatibility for older programs. 
 /// Please use the function that return success/failure replies when done.	
 /// </summary>
 /// <param name="spiros">An array of input spiros.</param>
 /// <param name="n">The number of elements in the spiros array.</param>
 /// <param name="isClosed">Whether this describes a closed (True) or open (False) contour.</param>
 /// <param name="bc">A bézier results output context.</param>
 public static void SpiroCPsToBezier(SpiroControlPoint[] spiros, int n, bool isClosed, IBezierContext bc)
 {
     SpiroCPsToBezier0(spiros, n, isClosed, bc);
 }
Example #15
0
 /// <summary>
 /// Convert a tagged set of spiro control points into a set of bézier curves.
 /// 
 /// As it does so it will call the appropriate routine in your bézier context with this information 
 /// – this should allow you to create your own internal representation of those curves.
 /// 
 /// The spiros array should indicate it's own end.
 /// 
 /// Open contours must have the ty field of the first cp set to '{' and have the ty field of the last cp set to '}'.
 /// 
 /// Closed contours must have an extra cp at the end whose ty is 'z' the x and y values of this extra cp are ignored.
 /// 
 /// If you can't use TaggedSpiroCPsToBezier0() this function is enhanced version of the original function, 
 /// where spiro success/failure replies are passd back through done output parameter. 
 /// </summary>
 /// <param name="spiros">An array of input spiros.</param>
 /// <param name="bc">A bézier results output context.</param>
 /// <param name="done">An boolean success flag.True = completed task and have valid bézier results, or False = unable to complete task, bézier results are invalid.</param>
 public static void TaggedSpiroCPsToBezier1(SpiroControlPoint[] spiros, IBezierContext bc, out bool done)
 {
     done = TaggedSpiroCPsToBezier0(spiros, bc);
 }
Example #16
0
        /// <summary>
        /// Convert a tagged set of spiro control points into a set of bézier curves.
        /// 
        /// As it does so it will call the appropriate routine in your bézier context with this information 
        /// – this should allow you to create your own internal representation of those curves.
        /// 
        /// The spiros array should indicate it's own end.
        /// 
        /// Open contours must have the ty field of the first cp set to '{' and have the ty field of the last cp set to '}'.
        /// 
        /// Closed contours must have an extra cp at the end whose ty is 'z' the x and y values of this extra cp are ignored.
        /// </summary>
        /// <param name="spiros">An array of input spiros.</param>
        /// <param name="bc">A bézier results output context.</param>
        /// <returns>An boolean success flag.True = completed task and have valid bézier results, or False = unable to complete task, bézier results are invalid.</returns>
        /// <example>
        /// var points = new SpiroControlPoint[5];
        /// points[0].X = -100; points[0].Y = 0; points[0].Type = SpiroPointType.G4;
        /// points[1].X = 0; points[1].Y = 100; points[1].Type = SpiroPointType.G4;
        /// points[2].X = 100; points[2].Y = 0; points[2].Type = SpiroPointType.G4;
        /// points[3].X = 0; points[3].Y = -100; points[3].Type = SpiroPointType.G4;
        /// points[4].X = 0; points[4].Y = 0; points[4].Type = SpiroPointType.End;
        /// var bc = new PathBezierContext();
        /// var success = Spiro.TaggedSpiroCPsToBezier0(points, bc);
        /// Console.WriteLine(bc);
        /// Console.WriteLine("Success: {0} ", success);
        /// 
        /// var points = new SpiroControlPoint[5];
        /// points[0].X = -100; points[0].Y = 0; points[0].Type = SpiroPointType.G4;
        /// points[1].X = 0; points[1].Y = 100; points[1].Type = SpiroPointType.G4;
        /// points[2].X = 100; points[2].Y = 0; points[2].Type = SpiroPointType.G4;
        /// points[3].X = 0; points[3].Y = -100; points[3].Type = SpiroPointType.G4;
        /// points[4].X = 0; points[4].Y = 0; points[4].Type = SpiroPointType.End;
        /// var bc = new PathBezierContext();
        /// var success = Spiro.TaggedSpiroCPsToBezier0(points, bc);
        /// Console.WriteLine(bc);
        /// Console.WriteLine("Success: {0} ", success);
        /// </example>
        public static bool TaggedSpiroCPsToBezier0(SpiroControlPoint[] spiros, IBezierContext bc)
        {
            SpiroSegment[] s;
            int n;

            n = 0;
            while (true)
            {
                if (spiros[n].Type == SpiroPointType.End || spiros[n].Type == SpiroPointType.EndOpenContour)
                    break;

                // invalid input
                if (n >= spiros.Length)
                    return false;

                ++n;
            }

            if (spiros[n].Type == SpiroPointType.EndOpenContour)
                ++n;

            if (n <= 0)
                return false; // invalid input

            s = SpiroImpl.run_spiro(spiros, n);

            if (s != null)
            {
                SpiroImpl.spiro_to_bpath(s, n, bc);
                return true; // success
            }

            return false; // spiro did not converge or encountered non-finite values
        }
Example #17
0
 /// <summary>
 /// Convert a tagged set of spiro control points into a set of bézier curves.
 ///
 /// As it does so it will call the appropriate routine in your bézier context with this information 
 /// – this should allow you to create your own internal representation of those curves.
 ///
 /// The spiros array should indicate it's own end.
 ///
 /// Open contours must have the ty field of the first cp set to '{' and have the ty field of the last cp set to '}'.
 ///
 /// Closed contours must have an extra cp at the end whose ty is 'z' the x and y values of this extra cp are ignored.
 ///
 /// This function is kept for backwards compatibility for older programs. 
 /// Please use the functions that return success/failure replies when done.
 /// </summary>
 /// <param name="spiros">An array of input spiros.</param>
 /// <param name="bc">A bézier results output context.</param>
 public static void TaggedSpiroCPsToBezier(SpiroControlPoint[] spiros, IBezierContext bc)
 {
     TaggedSpiroCPsToBezier0(spiros, bc);
 }
Example #18
0
 private void NewPointAt(SpiroShape shape, double x, double y, int index)
 {
     var point = new SpiroControlPoint();
     point.X = x;
     point.Y = y;
     point.Type = _state.PointType;
     shape.Points.Insert(index, point);
 }
Example #19
0
 private void SetPointPositionDelta(SpiroShape shape, int index, double dx, double dy)
 {
     var old = shape.Points[index];
     double x = old.X + dx;
     double y = old.Y + dy;
     double sx = _state.EnableSnap && _state.SnapX != 0 ? Snap(x, _state.SnapX) : x;
     double sy = _state.EnableSnap && _state.SnapY != 0 ? Snap(y, _state.SnapY) : y;
     var point = new SpiroControlPoint();
     point.X = sx;
     point.Y = sy;
     point.Type = old.Type;
     shape.Points[index] = point;
 }
Example #20
0
 private void SetPointPosition(SpiroShape shape, int index, double x, double y)
 {
     var old = shape.Points[index];
     var point = new SpiroControlPoint();
     point.X = x;
     point.Y = y;
     point.Type = old.Type;
     shape.Points[index] = point;
 }
Example #21
0
 /// <summary>
 /// Convert a set of spiro control points into a set of bézier curves.
 /// 
 /// As it does so it will call the appropriate routine in your bézier context with this information 
 /// – this should allow you to create your own internal representation of those curves.
 /// 
 /// Open contours do not need to start with '{', nor to end with '}'.
 /// 
 /// Close contours do not need to end with 'z'.
 /// 
 /// If you can't use SpiroCPsToBezier0() this function is enhanced version of the original function, 
 /// where spiro success/failure replies are passd back through done output parameter. 
 /// </summary>
 /// <param name="spiros">An array of input spiros.</param>
 /// <param name="n">The number of elements in the spiros array.</param>
 /// <param name="isClosed">Whether this describes a closed (True) or open (False) contour.</param>
 /// <param name="bc">A bézier results output context.</param>
 /// <param name="done">An boolean success flag. True = completed task and have valid bézier results, or False = unable to complete task, bézier results are invalid.</param>
 public static void SpiroCPsToBezier1(SpiroControlPoint[] spiros, int n, bool isClosed, IBezierContext bc, out bool done)
 {
     done = SpiroCPsToBezier0(spiros, n, isClosed, bc);
 }
Example #22
0
 private void DrawSpiroPoint(DrawingContext dc, Brush brush, Pen pen, SpiroControlPoint point)
 {
     switch (point.Type)
     {
         case SpiroPointType.Corner:
             dc.DrawRectangle(brush, null, new Rect(point.X - 3.5, point.Y - 3.5, 7, 7));
             break;
         case SpiroPointType.G4:
         case SpiroPointType.G2:
         case SpiroPointType.Left:
         case SpiroPointType.Right:
         case SpiroPointType.End:
         case SpiroPointType.OpenContour:
         case SpiroPointType.EndOpenContour:
             dc.PushTransform(new TranslateTransform(point.X, point.Y));
             dc.DrawGeometry(null, pen, EndKnot);
             dc.Pop();
             break;
     }
 }