Ejemplo n.º 1
0
 public void Translate(ref TSVector2 vector)
 {
     for (int i = 0; i < this.ControlPoints.Count; i++)
     {
         this.ControlPoints[i] = TSVector2.Add(this.ControlPoints[i], vector);
     }
 }
Ejemplo n.º 2
0
        public static FP DistanceBetweenPointAndLineSegment(ref TSVector2 point, ref TSVector2 start, ref TSVector2 end)
        {
            if (start == end)
            {
                return(TSVector2.Distance(point, start));
            }

            TSVector2 v = TSVector2.Subtract(end, start);
            TSVector2 w = TSVector2.Subtract(point, start);

            FP c1 = TSVector2.Dot(w, v);

            if (c1 <= 0)
            {
                return(TSVector2.Distance(point, start));
            }

            FP c2 = TSVector2.Dot(v, v);

            if (c2 <= c1)
            {
                return(TSVector2.Distance(point, end));
            }

            FP        b           = c1 / c2;
            TSVector2 pointOnLine = TSVector2.Add(start, TSVector2.Multiply(v, b));

            return(TSVector2.Distance(point, pointOnLine));
        }
Ejemplo n.º 3
0
        public static FP DistanceBetweenPointAndLineSegment(ref TSVector2 point, ref TSVector2 start, ref TSVector2 end)
        {
            bool flag = start == end;
            FP   result;

            if (flag)
            {
                result = TSVector2.Distance(point, start);
            }
            else
            {
                TSVector2 tSVector = TSVector2.Subtract(end, start);
                TSVector2 value    = TSVector2.Subtract(point, start);
                FP        fP       = TSVector2.Dot(value, tSVector);
                bool      flag2    = fP <= 0;
                if (flag2)
                {
                    result = TSVector2.Distance(point, start);
                }
                else
                {
                    FP   fP2   = TSVector2.Dot(tSVector, tSVector);
                    bool flag3 = fP2 <= fP;
                    if (flag3)
                    {
                        result = TSVector2.Distance(point, end);
                    }
                    else
                    {
                        FP        scaleFactor = fP / fP2;
                        TSVector2 value2      = TSVector2.Add(start, TSVector2.Multiply(tSVector, scaleFactor));
                        result = TSVector2.Distance(point, value2);
                    }
                }
            }
            return(result);
        }