Example #1
0
        public float Angle(LPoint pt)
        {
            float dx = this.X - pt.X;
            float dy = this.Y - pt.Y;

            return((float)Math.Atan2(dy, dx));
        }
Example #2
0
        public float DistSquared(LPoint pt)
        {
            float dx = this.X - pt.X;
            float dy = this.Y - pt.Y;

            return(dx * dx + dy * dy);
        }
Example #3
0
        public float Dist(LPoint pt)
        {
            float dx = this.X - pt.X;
            float dy = this.Y - pt.Y;

            return((float)Math.Sqrt(dx * dx + dy * dy));
        }
Example #4
0
 void renderSegment(Renderer.BaseRenderer g, LPoint p1, LPoint p2, float quality, float border)
 {
     if (p1.Outside && p2.Outside)
     {
         return;
     }
     if (Spline != null)
     {
         int   n  = (int)(p1.Dist(p2) * quality);
         float dx = (p2.X - p1.X) / n;
         float dy = (p2.Y - p1.Y) / n;
         float dr = (p2.Rad - p1.Rad) / n;
         for (int i = 0; i < n; i++)
         {
             double x, y;
             Spline.GetPoint(p1.Index + i / (float)n, out x, out y);
             LPoint p = new LPoint((float)x, (float)y, p1.Rad + dr * i);
             renderPoint(g, p, border);
         }
     }
     else
     {
         int   n  = (int)(p1.Dist(p2) * quality);
         float dx = (p2.X - p1.X) / n;
         float dy = (p2.Y - p1.Y) / n;
         float dr = (p2.Rad - p1.Rad) / n;
         for (int i = 0; i < n; i++)
         {
             LPoint p = new LPoint(p1.X + dx * i, p1.Y + dy * i, p1.Rad + dr * i);
             renderPoint(g, p, border);
         }
     }
 }
Example #5
0
        public static void Transform(this Matrix mat, LPoint p)
        {
            // [a*x + c*y, b*x + d*y, 0]
            float a = mat.Elements[0];
            float b = mat.Elements[1];
            float c = mat.Elements[2];
            float d = mat.Elements[3];
            float e = mat.Elements[4];
            float f = mat.Elements[5];
            float x = p.X;
            float y = p.Y;

            x   = e + a * x + c * y;
            y   = f + b * x + d * y;
            p.X = x;
            p.Y = y;
        }
Example #6
0
 public virtual void FromParamString(string txt)
 {
     Points.Clear();
     string[] pts = txt.Split(';');
     foreach (string pt in pts)
     {
         if (pt == "")
         {
             continue;
         }
         string[] dats = pt.Split(',');
         float    x    = Util.SToF(dats[0]);
         float    y    = Util.SToF(dats[1]);
         float    rad  = Util.SToF(dats[2]);
         LPoint   lp   = new LPoint(x, y, rad);
         Points.Add(lp);
     }
 }
Example #7
0
 void renderFull(Renderer.BaseRenderer g, PBrush brush, float border, float quality, int start, bool simple)
 {
     if (Points.Count == 1)
     {
         g.BeginCircles(brush);
         LPoint pt = Points[0];
         renderPoint(g, pt, border);
         g.EndCircle();
     }
     else if (Points.Count > 1 && !simple)
     {
         g.BeginCircles(brush);
         renderPoint(g, Points[0], border);
         if (start < 1)
         {
             start = 1;
         }
         for (int i = start; i < Points.Count; i++)
         {
             if (Points[i] == null)
             {
                 continue;
             }
             renderPoint(g, Points[i], border);
             renderSegment(g, Points[i - 1], Points[i], quality,
                           border);
             PointF p1 = new PointF(Points[i].X - Points[i].dX * 16,
                                    Points[i].Y - Points[i].dY * 16);
             PointF p2 = new PointF(Points[i].X + Points[i].dX * 16,
                                    Points[i].Y + Points[i].dY * 16);
             //g.DrawLine(Color.Lime, 1, p1, p2, false, true);
         }
         RenderPos = Points.Count - 1;
         g.EndCircle();
     }
     else if (Points.Count > 1)
     {
         for (int i = start + 1; i < Points.Count; i++)
         {
             g.DrawLine(Color.Black, 1, Points[i - 1].ToPointF(), Points[i].ToPointF());
         }
     }
 }
Example #8
0
        public virtual bool Collision(LPoint pt)
        {
            if (!Bounds.Expand(pt.Rad).Contains(pt.X, pt.Y))
            {
                return(false);
            }

            double x, y;

            if (Points.Count > 1)
            {
                for (int i = 0; i < Points.Count - 1; i++)
                {
                    float dist = Points[i].Dist(Points[i + 1]);
                    float rad  = Math.Max(Points[i].Rad, Points[i + 1].Rad);
                    for (float t = i; t < i + 1; t += 10f / dist)
                    {
                        if (Spline != null)
                        {
                            Spline.GetPoint(t, out x, out y);
                        }
                        else
                        {
                            x = Points[i].X * (t - i) + Points[i + 1].X * (1 - t + i);
                            y = Points[i].Y * (t - i) + Points[i + 1].Y * (1 - t + i);
                        }
                        if (pt.Dist((float)x, (float)y) < rad + pt.Rad)
                        {
                            return(true);
                        }
                    }
                }
            }
            else if (Points.Count == 1)
            {
                if (pt.Dist(Points[0]) < pt.Rad + pt.Rad)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #9
0
        public virtual void AddPoint(float x, float y, float pressure)
        {
            if (Points.Count == 0)
            {
                bounds = new RectangleF(x, y, 1, 1);
            }

            if (checkDist && Points.Count > 0 && Points.Last().DistSquared(x, y) < 4)
            {
                return;
            }

            if (x < bounds.Left)
            {
                bounds.Width += bounds.X - x; bounds.X = x;
            }
            if (x > bounds.Right)
            {
                bounds.Width = x - bounds.X;
            }
            if (y < bounds.Top)
            {
                bounds.Height += bounds.Y - y; bounds.Y = y;
            }
            if (y > bounds.Bottom)
            {
                bounds.Height = y - bounds.Y;
            }

            LPoint n = new LPoint(x, y, pressure);

            Points.Add(n);
            if (Configuration.CalculateSplinesDuringDrawing)
            {
                CalcSpline();
            }
        }
Example #10
0
 void renderPoint(Renderer.BaseRenderer g, LPoint pt, float border)
 {
     g.Circle(pt.X, pt.Y, pt.Rad + border);
 }