Beispiel #1
0
        public EditorState()
        {
            _tool = EditorTool.Spiro;
            _mode = EditorMode.Create;

            _displayKnots  = true;
            _displayGuides = true;

            _snapX      = 15.0;
            _snapY      = 15.0;
            _enableSnap = true;

            _shape              = null;
            _hitTreshold        = 7;
            _hitTresholdSquared = 49;
            _hitSetShapes       = new HashSet <SpiroShape>();
            _hitSetPoints       = new HashSet <int>();
            _hitListShapes      = new ObservableCollection <SpiroShape>();
            _hitListPoints      = new ObservableCollection <int>();
            _isStroked          = true;
            _isFilled           = false;
            _isClosed           = true;
            _isTagged           = false;
            _pointType          = SpiroPointType.G4;

            _isCaptured      = false;
            _snapTreshold    = 10.0;
            _snapMode        = GuideSnapMode.Point | GuideSnapMode.Middle | GuideSnapMode.Intersection | GuideSnapMode.Horizontal | GuideSnapMode.Vertical;
            _snapPointRadius = 3.5;
            _snapPoint       = default(GuidePoint);
            _haveSnapPoint   = false;
        }
Beispiel #2
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
        }
Beispiel #3
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);
        }
Beispiel #4
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;
        }
Beispiel #5
0
 /// <summary>
 /// Mark current control point knot.
 /// Currenlty not implemented, may be usefull for marking generated curves to original spiro code points.
 /// </summary>
 /// <param name="index">The spiros control point knot index.</param>
 /// <param name="theta">The spiros control point knot theta angle.</param>
 /// <param name="x">The spiros control point X location.</param>
 /// <param name="y">The spiros control point Y location.</param>
 /// <param name="type">The spiros control point type.</param>
 public void MarkKnot(int index, double theta, double x, double y, SpiroPointType type)
 {
     _knots.Add(new SpiroKnot()
     {
         Index = index,
         Theta = theta * 180 / Math.PI,
         X     = x,
         Y     = y,
         Type  = type
     });
 }
Beispiel #6
0
 public static int compute_jinc(SpiroPointType ty0, SpiroPointType ty1)
 {
     if (ty0 == SpiroPointType.G4 || ty1 == SpiroPointType.G4 || ty0 == SpiroPointType.Right || ty1 == SpiroPointType.Left)
     {
         return(4);
     }
     else if (ty0 == SpiroPointType.G2 && ty1 == SpiroPointType.G2)
     {
         return(2);
     }
     else if (((ty0 == SpiroPointType.OpenContour || ty0 == SpiroPointType.Corner || ty0 == SpiroPointType.Left) && ty1 == SpiroPointType.G2) || (ty0 == SpiroPointType.G2 && (ty1 == SpiroPointType.EndOpenContour || ty1 == SpiroPointType.Corner || ty1 == SpiroPointType.Right)))
     {
         return(1);
     }
     else
     {
         return(0);
     }
 }
Beispiel #7
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>
 /// <returns>SpiroSegment array or null on failure.</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 SpiroSegment[]? SpiroCPsToSegments(SpiroControlPoint[] spiros, int n, bool isClosed)
 {
     if (n <= 0)
     {
         return(null);
     }
     if (isClosed)
     {
         return(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;
         SpiroSegment[]? s;
         s = SpiroImpl.run_spiro(spiros, n);
         spiros[n - 1].Type = oldty_end;
         spiros[0].Type     = oldty_start;
         return(s);
     }
 }
 public void MarkKnot(int index, double theta, double x, double y, SpiroPointType type)
 {
 }
Beispiel #9
0
        public EditorState()
        {
            _tool = EditorTool.Spiro;
            _mode = EditorMode.Create;

            _displayKnots = true;
            _displayGuides = true;

            _snapX = 15.0;
            _snapY = 15.0;
            _enableSnap = true;

            _shape = null;
            _hitTreshold = 7;
            _hitTresholdSquared = 49;
            _hitSetShapes = new HashSet<SpiroShape>();
            _hitSetPoints = new HashSet<int>();
            _hitListShapes = new ObservableCollection<SpiroShape>();
            _hitListPoints = new ObservableCollection<int>();
            _isStroked = true;
            _isFilled = false;
            _isClosed = true;
            _isTagged = false;
            _pointType = SpiroPointType.G4;

            _isCaptured = false;
            _snapTreshold = 10.0;
            _snapMode = GuideSnapMode.Point | GuideSnapMode.Middle | GuideSnapMode.Intersection | GuideSnapMode.Horizontal | GuideSnapMode.Vertical;
            _snapPointRadius = 3.5;
            _snapPoint = default(GuidePoint);
            _haveSnapPoint = false;
        }
Beispiel #10
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;
 }
 public void MarkKnot(int index, double theta, double x, double y, SpiroPointType type)
 {
     _state.knot_idx = index;
 }
 /// <summary>
 /// Mark current control point knot. 
 /// Currenlty not implemented, may be usefull for marking generated curves to original spiro code points.
 /// </summary>
 /// <param name="index">The spiros control point knot index.</param>
 /// <param name="theta">The spiros control point knot theta angle.</param>
 /// <param name="x">The spiros control point X location.</param>
 /// <param name="y">The spiros control point Y location.</param>
 /// <param name="type">The spiros control point type.</param>
 public void MarkKnot(int index, double theta, double x, double y, SpiroPointType type)
 {
     _knots.Add(new SpiroKnot()
     {
         Index = index,
         Theta = theta * 180 / Math.PI,
         X = x,
         Y = y,
         Type = type
     });
 }
 public void MarkKnot(int index, double theta, double x, double y, SpiroPointType type)
 {
 }
Beispiel #14
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;
 }
Beispiel #15
0
 public static int compute_jinc(SpiroPointType ty0, SpiroPointType ty1)
 {
     if (ty0 == SpiroPointType.G4 || ty1 == SpiroPointType.G4 || ty0 == SpiroPointType.Right || ty1 == SpiroPointType.Left)
         return 4;
     else if (ty0 == SpiroPointType.G2 && ty1 == SpiroPointType.G2)
         return 2;
     else if (((ty0 == SpiroPointType.OpenContour || ty0 == SpiroPointType.Corner || ty0 == SpiroPointType.Left) && ty1 == SpiroPointType.G2) || (ty0 == SpiroPointType.G2 && (ty1 == SpiroPointType.EndOpenContour || ty1 == SpiroPointType.Corner || ty1 == SpiroPointType.Right)))
         return 1;
     else
         return 0;
 }
 public void MarkKnot(int index, double theta, double x, double y, SpiroPointType type)
 {
     _state.knot_idx = index;
 }