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 bool SnapToHorizontal(PointF pt, float yVal, float snapDistance)
        {
            bool  flag = false;
            float num1 = snapDistance;

            if (this.IsModified)
            {
                return(false);
            }
            for (int index = 0; index < this.points.Length - 1; ++index)
            {
                float num2 = this.points[index + 1].Y - this.points[index].Y;
                if ((double)num2 != 0.0)
                {
                    float num3 = this.points[index + 1].X - this.points[index].X;
                    float x    = this.points[index].X + (yVal - this.points[index].Y) * num3 / num2;
                    if (ShapeBezier.IsPointOnSegment(x, yVal, this.points[index], this.points[index + 1]) && (double)Math.Abs(x - pt.X) <= (double)num1)
                    {
                        this.snappedPoint.Y = yVal;
                        this.snappedPoint.X = x;
                        flag = true;
                    }
                }
            }
            return(flag);
        }
Esempio n. 3
0
        private void DrawControlPoints(PaintEventArgs e, ShapeBezier b)
        {
            //if (!drawGuideLines) return;
            RectangleF rect = new RectangleF();

            rect.Location = zoom.PtToVisible(b.ControlPoints[1].Location);

            rect.Inflate(2, 2);

            e.Graphics.DrawLine(PenControlLines,
                                zoom.PtToVisible(b.ControlPoints[0].Location),
                                zoom.PtToVisible(b.ControlPoints[1].Location)
                                );

            e.Graphics.FillEllipse(BrushControlLinesPts, rect);

            rect.Width    = rect.Height = 0;
            rect.Location = zoom.PtToVisible(b.ControlPoints[2].Location);
            rect.Inflate(2, 2);

            e.Graphics.DrawLine(PenControlLines,
                                zoom.PtToVisible(b.ControlPoints[3].Location),
                                zoom.PtToVisible(b.ControlPoints[2].Location)
                                );

            e.Graphics.FillEllipse(BrushControlLinesPts, rect);
        }
Esempio n. 4
0
        public bool SnapToCurve(PointF pt, float snapDistance)
        {
            bool   flag      = false;
            PointF pointF    = new PointF();
            PointF snapPoint = new PointF();
            float  num       = snapDistance * snapDistance;
            float  dist      = 0.0f;

            if (this.IsModified)
            {
                return(false);
            }
            for (int index = 0; index < this.detailLevel - 1; ++index)
            {
                if (ShapeBezier.SnapToCurveSegment(ref snapPoint, pt, this.points[index], this.points[index + 1], snapDistance, ref dist))
                {
                    dist = ShapePoint.DistSquared(pt, snapPoint);
                    if ((double)num >= (double)dist)
                    {
                        num    = dist;
                        pointF = snapPoint;
                        this.snapSegmentNum = index;
                        flag = true;
                    }
                }
            }
            if (!flag)
            {
                return(false);
            }
            this.snappedPoint = pointF;
            return(true);
        }
Esempio n. 5
0
        public void AddBezier(PointF from, PointF ctrl1, PointF ctrl2, PointF to)
        {
            ShapeBezier curve = new ShapeBezier(
                new ShapePoint(from),
                new ShapePoint(ctrl1),
                new ShapePoint(ctrl2),
                new ShapePoint(to)
                );

            shape.Add(curve);
        }
Esempio n. 6
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;
            }
        }
        private void DrawControlPoints(PaintEventArgs e, ShapeBezier b)
        {
            RectangleF rect = new RectangleF();

            rect.Location = this.zoom.PtToVisible(b.ControlPoints[1].Location);
            rect.Inflate(2f, 2f);
            e.Graphics.DrawLine(this.PenControlLines, this.zoom.PtToVisible(b.ControlPoints[0].Location), this.zoom.PtToVisible(b.ControlPoints[1].Location));
            e.Graphics.FillEllipse(this.BrushControlLinesPts, rect);
            rect.Width    = rect.Height = 0.0f;
            rect.Location = this.zoom.PtToVisible(b.ControlPoints[2].Location);
            rect.Inflate(2f, 2f);
            e.Graphics.DrawLine(this.PenControlLines, this.zoom.PtToVisible(b.ControlPoints[3].Location), this.zoom.PtToVisible(b.ControlPoints[2].Location));
            e.Graphics.FillEllipse(this.BrushControlLinesPts, rect);
        }
Esempio n. 8
0
 private static bool SnapToCurveSegment(
     ref PointF snapPoint,
     PointF pt,
     ShapePoint from,
     ShapePoint to,
     float snapDistance,
     ref float dist)
 {
     if (!ShapeBezier.SnapToExtension(ref snapPoint, pt, from, to, snapDistance, ref dist))
     {
         return(false);
     }
     return(ShapeBezier.IsPointOnSegment(snapPoint.X, snapPoint.Y, from, to));
 }
Esempio n. 9
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. 10
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. 11
0
        public bool AppendBezier(PointF ctrl1, PointF ctrl2, PointF to)
        {
            ShapePoint pt = shape.GetLastPoint();

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

            ShapeBezier curve = new ShapeBezier(
                pt,
                new ShapePoint(ctrl1),
                new ShapePoint(ctrl2),
                new ShapePoint(to)
                );

            shape.Add(curve);

            return(true);
        }
Esempio n. 12
0
        public bool CloseFigureUsingBezier(PointF ctrl1, PointF ctrl2)
        {
            ShapePoint first = shape.GetFirstPoint();
            ShapePoint last  = shape.GetLastPoint();

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

            ShapeBezier curve = new ShapeBezier(
                last,
                new ShapePoint(ctrl1),
                new ShapePoint(ctrl2),
                first
                );

            shape.Add(curve);

            return(true);
        }
Esempio n. 13
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. 14
0
        public bool SnapToCurveExtension(PointF pt, float snapDistance)
        {
            PointF snapPoint1 = new PointF();
            PointF snapPoint2 = new PointF();
            bool   flag       = true;
            int    num        = 0;
            float  dist1      = 0.0f;
            float  dist2      = 0.0f;

            if (!this.ctrl[0].IsModified && !this.ctrl[1].IsModified)
            {
                num += ShapeBezier.SnapToExtension(ref snapPoint1, pt, this.ctrl[0], this.ctrl[1], snapDistance, ref dist1) ? 1 : 0;
            }
            if (!this.ctrl[3].IsModified && !this.ctrl[2].IsModified)
            {
                num += ShapeBezier.SnapToExtension(ref snapPoint2, pt, this.ctrl[3], this.ctrl[2], snapDistance, ref dist2) ? 2 : 0;
            }
            switch (num)
            {
            case 1:
                this.snappedPoint = snapPoint1;
                break;

            case 2:
                this.snappedPoint = snapPoint2;
                break;

            case 3:
                this.snappedPoint = (double)ShapePoint.DistSquared(pt, snapPoint1) > (double)ShapePoint.DistSquared(pt, snapPoint2) ? snapPoint2 : snapPoint1;
                break;

            default:
                flag = false;
                break;
            }
            return(flag);
        }