Esempio n. 1
0
        public void ConvertCurve(IShapeCurve curve)
        {
            if (curve is ShapeLine)
            {
                ShapePoint c1 = new ShapePoint(
                    (2 * snappedCurve.Points[0].X + snappedCurve.Points[1].X) / 3,
                    (2 * snappedCurve.Points[0].Y + snappedCurve.Points[1].Y) / 3
                    );
                ShapePoint c2 = new ShapePoint(
                    (snappedCurve.Points[0].X + 2 * snappedCurve.Points[1].X) / 3,
                    (snappedCurve.Points[0].Y + 2 * snappedCurve.Points[1].Y) / 3
                    );

                ShapeBezier bezier = new ShapeBezier(snappedCurve.FirstPoint, c1, c2, snappedCurve.LastPoint);

                lines[lines.IndexOf(curve)] = bezier;
            }
            else
            {
                ShapeLine line = new ShapeLine(snappedCurve.FirstPoint, snappedCurve.LastPoint);

                lines[lines.IndexOf(curve)] = line;
            }
            snappedCurve = null;
        }
Esempio n. 2
0
        public void DeserializeProperties(string propertiesString)
        {
            string[] tokens = propertiesString.Split(':');

            IShapeCurve curve = null;

            ShapePoint startPt = new ShapePoint();
            ShapePoint endPt   = startPt;



            for (int i = 1; i < tokens.Length - 1; i++)
            {
                string[] strpt = tokens[i].Split(',');

                endPt.Set(float.Parse(strpt[0], CultureInfo.InvariantCulture), float.Parse(strpt[1], CultureInfo.InvariantCulture));

                if (bool.Parse(strpt[2]))
                {
                    // Bezier curve
                    curve = new ShapeBezier();

                    curve.ControlPoints[0] = endPt;
                    //bool b = CultureInfo.CurrentCulture.UseUserOverride;
                    NumberFormatInfo nfi = CultureInfo.CurrentCulture.NumberFormat;
                    curve.ControlPoints[1] = new ShapePoint(float.Parse(strpt[3], CultureInfo.InvariantCulture), float.Parse(strpt[4], CultureInfo.InvariantCulture));
                    curve.ControlPoints[2] = new ShapePoint(float.Parse(strpt[5], CultureInfo.InvariantCulture), float.Parse(strpt[6], CultureInfo.InvariantCulture));

                    endPt = new ShapePoint();
                    curve.ControlPoints[3] = endPt;
                }
                else
                {
                    // Straight Line
                    curve = new ShapeLine();

                    curve.ControlPoints[0] = endPt;

                    endPt = new ShapePoint();
                    curve.ControlPoints[1] = endPt;
                }
                this.Add(curve);
            }

            // Attach the end of the last line to the first point to close the shape
            if (curve != null)
            {
                curve.LastPoint = startPt;
            }
        }
Esempio n. 3
0
 public void ConvertCurve(IShapeCurve curve)
 {
     if (curve is ShapeLine)
     {
         ShapeBezier shapeBezier = new ShapeBezier(this.snappedCurve.FirstPoint, new ShapePoint((float)((2.0 * (double)this.snappedCurve.Points[0].X + (double)this.snappedCurve.Points[1].X) / 3.0), (float)((2.0 * (double)this.snappedCurve.Points[0].Y + (double)this.snappedCurve.Points[1].Y) / 3.0)), new ShapePoint((float)(((double)this.snappedCurve.Points[0].X + 2.0 * (double)this.snappedCurve.Points[1].X) / 3.0), (float)(((double)this.snappedCurve.Points[0].Y + 2.0 * (double)this.snappedCurve.Points[1].Y) / 3.0)), this.snappedCurve.LastPoint);
         this.lines[this.lines.IndexOf(curve)] = (IShapeCurve)shapeBezier;
     }
     else
     {
         ShapeLine shapeLine = new ShapeLine(this.snappedCurve.FirstPoint, this.snappedCurve.LastPoint);
         this.lines[this.lines.IndexOf(curve)] = (IShapeCurve)shapeLine;
     }
     this.snappedCurve = (IShapeCurve)null;
 }
Esempio n. 4
0
        public bool AppendLine(PointF to)
        {
            ShapePoint pt = shape.GetLastPoint();

            if (pt == null)
            {
                return(false);
            }

            ShapeLine line = new ShapeLine(pt, new ShapePoint(to));

            shape.Add(line);

            return(true);
        }
Esempio n. 5
0
        public bool CloseFigureUsingLine()
        {
            ShapePoint first = shape.GetFirstPoint();
            ShapePoint last  = shape.GetLastPoint();

            if ((first == null) || (last == null))
            {
                return(false);
            }

            ShapeLine line = new ShapeLine(last, first);

            shape.Add(line);

            return(true);
        }
Esempio n. 6
0
        public void InsertPoint(IShapeCurve curve, PointF atPoint)
        {
            if (curve == null)
            {
                return;
            }

            if (curve is ShapeLine)
            {
                ShapePoint end     = curve.LastPoint;
                ShapePoint middle  = new ShapePoint(atPoint);
                ShapeLine  newLine = new ShapeLine(middle, end);
                curve.LastPoint = middle;
                lines.Insert(lines.IndexOf(curve) + 1, newLine);
                return;
            }

            if (curve is ShapeBezier)
            {
                PointF tg1 = new PointF(), tg2 = new PointF();

                ShapePoint end    = snappedCurve.LastPoint;
                ShapePoint middle = new ShapePoint(snappedPoint);

                if (!(curve as ShapeBezier).TangentAt(snappedPoint, ref tg1, ref tg2))
                {
                    return;
                }

                ShapeBezier newBezier = new ShapeBezier();

                newBezier.ControlPoints[0] = middle;
                newBezier.ControlPoints[1] = new ShapePoint(tg2);
                newBezier.ControlPoints[2] = curve.ControlPoints[2];
                newBezier.ControlPoints[3] = curve.LastPoint;

                curve.ControlPoints[2] = new ShapePoint(tg1);
                curve.ControlPoints[3] = middle;

                curve.Update();
                newBezier.Update();

                lines.Insert(lines.IndexOf(curve) + 1, newBezier);

                return;
            }
        }
Esempio n. 7
0
 public void InsertPoint(IShapeCurve curve, PointF atPoint)
 {
     if (curve == null)
     {
         return;
     }
     if (curve is ShapeLine)
     {
         ShapePoint lastPoint = curve.LastPoint;
         ShapePoint from      = new ShapePoint(atPoint);
         ShapeLine  shapeLine = new ShapeLine(from, lastPoint);
         curve.LastPoint = from;
         this.lines.Insert(this.lines.IndexOf(curve) + 1, (IShapeCurve)shapeLine);
     }
     else
     {
         if (!(curve is ShapeBezier))
         {
             return;
         }
         PointF     from       = new PointF();
         PointF     to         = new PointF();
         ShapePoint lastPoint  = this.snappedCurve.LastPoint;
         ShapePoint shapePoint = new ShapePoint(this.snappedPoint);
         if (!(curve as ShapeBezier).TangentAt(this.snappedPoint, ref from, ref to))
         {
             return;
         }
         ShapeBezier shapeBezier = new ShapeBezier();
         shapeBezier.ControlPoints[0] = shapePoint;
         shapeBezier.ControlPoints[1] = new ShapePoint(to);
         shapeBezier.ControlPoints[2] = curve.ControlPoints[2];
         shapeBezier.ControlPoints[3] = curve.LastPoint;
         curve.ControlPoints[2]       = new ShapePoint(from);
         curve.ControlPoints[3]       = shapePoint;
         curve.Update();
         shapeBezier.Update();
         this.lines.Insert(this.lines.IndexOf(curve) + 1, (IShapeCurve)shapeBezier);
     }
 }
Esempio n. 8
0
        public void AddLine(PointF from, PointF to)
        {
            ShapeLine line = new ShapeLine(new ShapePoint(from), new ShapePoint(to));

            shape.Add(line);
        }