Example #1
0
        public static bool PointInPolygon(ref FixVector2 pnt, FixVector2[] plg)
        {
            if ((plg == null) || (plg.Length < 3))
            {
                return(false);
            }
            bool flag  = false;
            int  index = 0;

            for (int i = plg.Length - 1; index < plg.Length; i = index++)
            {
                FixVector2 num3 = plg[index];
                FixVector2 num4 = plg[i];
                if (((num3.y <= pnt.y) && (pnt.y < num4.y)) || ((num4.y <= pnt.y) && (pnt.y < num3.y)))
                {
                    int  num5 = num4.y - num3.y;
                    long num6 = ((pnt.y - num3.y) * (num4.x - num3.x)) - ((pnt.x - num3.x) * num5);
                    if (num5 > 0)
                    {
                        if (num6 > 0L)
                        {
                            flag = !flag;
                        }
                    }
                    else if (num6 < 0L)
                    {
                        flag = !flag;
                    }
                }
            }
            return(flag);
        }
Example #2
0
        public static bool IntersectSegment(ref FixVector2 seg1Src, ref FixVector2 seg1Vec, ref FixVector2 seg2Src, ref FixVector2 seg2Vec, out FixVector2 interPoint)
        {
            long num;
            long num2;
            long num3;
            long num4;
            long num5;
            long num6;

            SegvecToLinegen(ref seg1Src, ref seg1Vec, out num, out num2, out num3);
            SegvecToLinegen(ref seg2Src, ref seg2Vec, out num4, out num5, out num6);
            long b = (num * num5) - (num4 * num2);

            if (b != 0)
            {
                long x    = Divide((long)((num2 * num6) - (num5 * num3)), b);
                long y    = Divide((long)((num4 * num3) - (num * num6)), b);
                bool flag = IsPointOnSegment(ref seg1Src, ref seg1Vec, x, y) && IsPointOnSegment(ref seg2Src, ref seg2Vec, x, y);
                interPoint.x = (int)x;
                interPoint.y = (int)y;
                return(flag);
            }
            interPoint = FixVector2.zero;
            return(false);
        }
Example #3
0
        private static bool IsPointOnSegment(ref FixVector2 segSrc, ref FixVector2 segVec, long x, long y)
        {
            long num  = x - segSrc.x;
            long num2 = y - segSrc.y;

            return((((segVec.x * num) + (segVec.y * num2)) >= 0L) && (((num * num) + (num2 * num2)) <= segVec.sqrMagnitudeLong));
        }
Example #4
0
        public override bool Equals(object o)
        {
            if (o == null)
            {
                return(false);
            }
            FixVector2 num = (FixVector2)o;

            return((this.x == num.x) && (this.y == num.y));
        }
Example #5
0
        public static FixVector2 ClampMagnitude(FixVector2 v, int maxLength)
        {
            long sqrMagnitudeLong = v.sqrMagnitudeLong;
            long num2             = maxLength;

            if (sqrMagnitudeLong > (num2 * num2))
            {
                long b = Fix32Math.Sqrt(sqrMagnitudeLong);
                int  x = (int)Fix32Math.Divide((long)(v.x * maxLength), b);
                return(new FixVector2(x, (int)Fix32Math.Divide((long)(v.x * maxLength), b)));
            }
            return(v);
        }
Example #6
0
        public static bool SegIntersectPlg(ref FixVector2 segSrc, ref FixVector2 segVec, FixVector2[] plg, out FixVector2 nearPoint, out FixVector2 projectVec)
        {
            nearPoint  = FixVector2.zero;
            projectVec = FixVector2.zero;
            if ((plg == null) || (plg.Length < 2))
            {
                return(false);
            }
            bool flag  = false;
            long num2  = -1L;
            int  index = -1;

            for (int i = 0; i < plg.Length; i++)
            {
                FixVector2 num;
                FixVector2 num5 = plg[(i + 1) % plg.Length] - plg[i];
                if (IntersectSegment(ref segSrc, ref segVec, ref plg[i], ref num5, out num))
                {
                    FixVector2 num11            = num - segSrc;
                    long       sqrMagnitudeLong = num11.sqrMagnitudeLong;
                    if ((num2 < 0L) || (sqrMagnitudeLong < num2))
                    {
                        nearPoint = num;
                        num2      = sqrMagnitudeLong;
                        index     = i;
                        flag      = true;
                    }
                }
            }
            if (index >= 0)
            {
                FixVector2 num7 = plg[(index + 1) % plg.Length] - plg[index];
                FixVector2 num8 = (segSrc + segVec) - nearPoint;
                long       num9 = (num8.x * num7.x) + (num8.y * num7.y);
                if (num9 < 0L)
                {
                    num9 = -num9;
                    num7 = -num7;
                }
                long b = num7.sqrMagnitudeLong;
                projectVec.x = (int)Divide((long)(num7.x * num9), b);
                projectVec.y = (int)Divide((long)(num7.y * num9), b);
            }
            return(flag);
        }
Example #7
0
 public static FixVector2 Divide(FixVector2 a, long m, long b)
 {
     a.x = (int)Divide((long)(a.x * m), b);
     a.y = (int)Divide((long)(a.y * m), b);
     return(a);
 }
Example #8
0
 public static FixVector2 Divide(FixVector2 a, long b)
 {
     a.x = (int)Divide((long)a.x, b);
     a.y = (int)Divide((long)a.y, b);
     return(a);
 }
Example #9
0
 public static FixVector2 Rotate(FixVector2 v, int r)
 {
     r = r % 4;
     return(new FixVector2((v.x * Rotations[r * 4]) + (v.y * Rotations[(r * 4) + 1]), (v.x * Rotations[(r * 4) + 2]) + (v.y * Rotations[(r * 4) + 3])));
 }
Example #10
0
 public static FixVector2 Max(FixVector2 a, FixVector2 b)
 {
     return(new FixVector2(Math.Max(a.x, b.x), Math.Max(a.y, b.y)));
 }
Example #11
0
 public static long DetLong(FixVector2 a, FixVector2 b)
 {
     return((a.x * b.y) - (a.y * b.x));
 }
Example #12
0
 public static long DotLong(ref FixVector2 a, ref FixVector2 b)
 {
     return((a.x * b.x) + (a.y * b.y));
 }
Example #13
0
 public static int Dot(FixVector2 a, FixVector2 b)
 {
     return((a.x * b.x) + (a.y * b.y));
 }
Example #14
0
 static FixVector2()
 {
     zero      = new FixVector2();
     Rotations = new int[] { 1, 0, 0, 1, 0, 1, -1, 0, -1, 0, 0, -1, 0, -1, 1, 0 };
 }
Example #15
0
 public void Max(ref FixVector2 r)
 {
     this.x = Mathf.Max(this.x, r.x);
     this.y = Mathf.Max(this.y, r.y);
 }
Example #16
0
 public static FixVector3 ToInt3XZ(FixVector2 o)
 {
     return(new FixVector3(o.x, 0, o.y));
 }
Example #17
0
 public static void SegvecToLinegen(ref FixVector2 segSrc, ref FixVector2 segVec, out long a, out long b, out long c)
 {
     a = segVec.y;
     b = -segVec.x;
     c = (segVec.x * segSrc.y) - (segSrc.x * segVec.y);
 }
Example #18
0
 public bool Contains(FixVector2 point)
 {
     return((((point.x >= this.xMin) && (point.x < this.xMax)) && (point.y >= this.yMin)) && (point.y < this.yMax));
 }