コード例 #1
0
ファイル: Int128.cs プロジェクト: whztt07/mobahero_src
        public static Int128 Int128Mul(long lhs, long rhs)
        {
            bool flag = lhs < 0L != rhs < 0L;

            if (lhs < 0L)
            {
                lhs = -lhs;
            }
            if (rhs < 0L)
            {
                rhs = -rhs;
            }
            ulong num  = (ulong)lhs >> 32;
            ulong num2 = (ulong)(lhs & (long)((ulong)-1));
            ulong num3 = (ulong)rhs >> 32;
            ulong num4 = (ulong)(rhs & (long)((ulong)-1));
            ulong num5 = num * num3;
            ulong num6 = num2 * num4;
            ulong num7 = num * num4 + num2 * num3;
            long  num8 = (long)(num5 + (num7 >> 32));
            ulong num9 = (num7 << 32) + num6;

            if (num9 < num6)
            {
                num8 += 1L;
            }
            Int128 @int = new Int128(num8, num9);

            return((!flag) ? @int : (-@int));
        }
コード例 #2
0
        public static Int128 Int128Mul(long lhs, long rhs)
        {
            bool flag = (lhs < 0L) != (rhs < 0L);

            if (lhs < 0L)
            {
                lhs = -lhs;
            }
            if (rhs < 0L)
            {
                rhs = -rhs;
            }
            ulong num  = (ulong)(lhs >> 0x20);
            ulong num2 = ((ulong)lhs) & 0xffffffffL;
            ulong num3 = (ulong)(rhs >> 0x20);
            ulong num4 = ((ulong)rhs) & 0xffffffffL;
            ulong num5 = num * num3;
            ulong num6 = num2 * num4;
            ulong num7 = (num * num4) + (num2 * num3);
            long  num9 = (long)(num5 + (num7 >> 0x20));
            ulong num8 = (num7 << 0x20) + num6;

            if (num8 < num6)
            {
                num9 += 1L;
            }
            Int128 num10 = new Int128(num9, num8);

            return(!flag ? num10 : -num10);
        }
コード例 #3
0
ファイル: ClipperBase.cs プロジェクト: wujiangu/wanshiwu0.1
        internal bool PointInPolygon(IntPoint pt, OutPt pp, bool UseFullRange)
        {
            OutPt next = pp;
            bool  flag = false;

            if (UseFullRange)
            {
                do
                {
                    if ((next.Pt.Y > pt.Y) != (next.Prev.Pt.Y > pt.Y))
                    {
                        Int128 introduced2 = Int128.Int128Mul(next.Prev.Pt.X - next.Pt.X, pt.Y - next.Pt.Y);
                        if (new Int128(pt.X - next.Pt.X) < (introduced2 / new Int128(next.Prev.Pt.Y - next.Pt.Y)))
                        {
                            flag = !flag;
                        }
                    }
                    next = next.Next;
                }while (next != pp);
                return(flag);
            }
            do
            {
                if (((next.Pt.Y > pt.Y) != (next.Prev.Pt.Y > pt.Y)) && ((pt.X - next.Pt.X) < (((next.Prev.Pt.X - next.Pt.X) * (pt.Y - next.Pt.Y)) / (next.Prev.Pt.Y - next.Pt.Y))))
                {
                    flag = !flag;
                }
                next = next.Next;
            }while (next != pp);
            return(flag);
        }
コード例 #4
0
ファイル: ClipperBase.cs プロジェクト: wujiangu/wanshiwu0.1
 protected static bool SlopesEqual(IntPoint pt1, IntPoint pt2, IntPoint pt3, bool UseFullRange)
 {
     if (UseFullRange)
     {
         return(Int128.Int128Mul(pt1.Y - pt2.Y, pt2.X - pt3.X) == Int128.Int128Mul(pt1.X - pt2.X, pt2.Y - pt3.Y));
     }
     return((((pt1.Y - pt2.Y) * (pt2.X - pt3.X)) - ((pt1.X - pt2.X) * (pt2.Y - pt3.Y))) == 0L);
 }
コード例 #5
0
ファイル: ClipperBase.cs プロジェクト: whztt07/mobahero_src
 internal static bool SlopesEqual(TEdge e1, TEdge e2, bool UseFullRange)
 {
     if (UseFullRange)
     {
         return(Int128.Int128Mul(e1.Delta.Y, e2.Delta.X) == Int128.Int128Mul(e1.Delta.X, e2.Delta.Y));
     }
     return(e1.Delta.Y * e2.Delta.X == e1.Delta.X * e2.Delta.Y);
 }
コード例 #6
0
ファイル: ClipperBase.cs プロジェクト: wujiangu/wanshiwu0.1
 internal static bool SlopesEqual(TEdge e1, TEdge e2, bool UseFullRange)
 {
     if (UseFullRange)
     {
         Int128 introduced0 = Int128.Int128Mul(e1.Delta.Y, e2.Delta.X);
         return(introduced0 == Int128.Int128Mul(e1.Delta.X, e2.Delta.Y));
     }
     return((e1.Delta.Y * e2.Delta.X) == (e1.Delta.X * e2.Delta.Y));
 }
コード例 #7
0
ファイル: Int128.cs プロジェクト: whztt07/mobahero_src
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is Int128))
            {
                return(false);
            }
            Int128 @int = (Int128)obj;

            return(@int.hi == this.hi && @int.lo == this.lo);
        }
コード例 #8
0
        public override bool Equals(object obj)
        {
            if ((obj == null) || !(obj is Int128))
            {
                return(false);
            }
            Int128 num = (Int128)obj;

            return((num.hi == this.hi) && (num.lo == this.lo));
        }
コード例 #9
0
ファイル: Int128.cs プロジェクト: whztt07/mobahero_src
 public Int128(Int128 val)
 {
     this.hi = val.hi;
     this.lo = val.lo;
 }
コード例 #10
0
ファイル: Int128.cs プロジェクト: whztt07/mobahero_src
        public static Int128 operator /(Int128 lhs, Int128 rhs)
        {
            if (rhs.lo == 0uL && rhs.hi == 0L)
            {
                throw new ClipperException("Int128: divide by zero");
            }
            bool flag = rhs.hi < 0L != lhs.hi < 0L;

            if (lhs.hi < 0L)
            {
                lhs = -lhs;
            }
            if (rhs.hi < 0L)
            {
                rhs = -rhs;
            }
            if (rhs < lhs)
            {
                Int128 @int = new Int128(0L);
                Int128 int2 = new Int128(1L);
                while (rhs.hi >= 0L && !(rhs > lhs))
                {
                    rhs.hi <<= 1;
                    if (rhs.lo < 0uL)
                    {
                        rhs.hi += 1L;
                    }
                    rhs.lo  <<= 1;
                    int2.hi <<= 1;
                    if (int2.lo < 0uL)
                    {
                        int2.hi += 1L;
                    }
                    int2.lo <<= 1;
                }
                rhs.lo >>= 1;
                if ((rhs.hi & 1L) == 1L)
                {
                    rhs.lo |= 9223372036854775808uL;
                }
                rhs.hi    = (long)((ulong)rhs.hi >> 1);
                int2.lo >>= 1;
                if ((int2.hi & 1L) == 1L)
                {
                    int2.lo |= 9223372036854775808uL;
                }
                int2.hi >>= 1;
                while (int2.hi != 0L || int2.lo != 0uL)
                {
                    if (!(lhs < rhs))
                    {
                        lhs     -= rhs;
                        @int.hi |= int2.hi;
                        @int.lo |= int2.lo;
                    }
                    rhs.lo >>= 1;
                    if ((rhs.hi & 1L) == 1L)
                    {
                        rhs.lo |= 9223372036854775808uL;
                    }
                    rhs.hi  >>= 1;
                    int2.lo >>= 1;
                    if ((int2.hi & 1L) == 1L)
                    {
                        int2.lo |= 9223372036854775808uL;
                    }
                    int2.hi >>= 1;
                }
                return((!flag) ? @int : (-@int));
            }
            if (rhs == lhs)
            {
                return(new Int128(1L));
            }
            return(new Int128(0L));
        }
コード例 #11
0
ファイル: ClipperBase.cs プロジェクト: wujiangu/wanshiwu0.1
 internal bool PointOnLineSegment(IntPoint pt, IntPoint linePt1, IntPoint linePt2, bool UseFullRange)
 {
     if (UseFullRange)
     {
         return((((pt.X == linePt1.X) && (pt.Y == linePt1.Y)) || ((pt.X == linePt2.X) && (pt.Y == linePt2.Y))) || ((((pt.X > linePt1.X) == (pt.X < linePt2.X)) && ((pt.Y > linePt1.Y) == (pt.Y < linePt2.Y))) && (Int128.Int128Mul(pt.X - linePt1.X, linePt2.Y - linePt1.Y) == Int128.Int128Mul(linePt2.X - linePt1.X, pt.Y - linePt1.Y))));
     }
     return((((pt.X == linePt1.X) && (pt.Y == linePt1.Y)) || ((pt.X == linePt2.X) && (pt.Y == linePt2.Y))) || ((((pt.X > linePt1.X) == (pt.X < linePt2.X)) && ((pt.Y > linePt1.Y) == (pt.Y < linePt2.Y))) && (((pt.X - linePt1.X) * (linePt2.Y - linePt1.Y)) == ((linePt2.X - linePt1.X) * (pt.Y - linePt1.Y)))));
 }
コード例 #12
0
        public static Int128 operator /(Int128 lhs, Int128 rhs)
        {
            if ((rhs.lo == 0L) && (rhs.hi == 0L))
            {
                throw new ClipperException("Int128: divide by zero");
            }
            bool flag = (rhs.hi < 0L) != (lhs.hi < 0L);

            if (lhs.hi < 0L)
            {
                lhs = -lhs;
            }
            if (rhs.hi < 0L)
            {
                rhs = -rhs;
            }
            if (rhs < lhs)
            {
                Int128 num  = new Int128(0L);
                Int128 num2 = new Int128(1L);
                while ((rhs.hi >= 0L) && (rhs <= lhs))
                {
                    rhs.hi = rhs.hi << 1;
                    if (rhs.lo < 0L)
                    {
                        rhs.hi += 1L;
                    }
                    rhs.lo  = rhs.lo << 1;
                    num2.hi = num2.hi << 1;
                    if (num2.lo < 0L)
                    {
                        num2.hi += 1L;
                    }
                    num2.lo = num2.lo << 1;
                }
                rhs.lo = rhs.lo >> 1;
                if ((rhs.hi & 1L) == 1L)
                {
                    rhs.lo |= 9223372036854775808L;
                }
                rhs.hi  = rhs.hi >> 1;
                num2.lo = num2.lo >> 1;
                if ((num2.hi & 1L) == 1L)
                {
                    num2.lo |= 9223372036854775808L;
                }
                num2.hi = num2.hi >> 1;
                while ((num2.hi != 0L) || (num2.lo != 0L))
                {
                    if (lhs >= rhs)
                    {
                        lhs    -= rhs;
                        num.hi |= num2.hi;
                        num.lo |= num2.lo;
                    }
                    rhs.lo = rhs.lo >> 1;
                    if ((rhs.hi & 1L) == 1L)
                    {
                        rhs.lo |= 9223372036854775808L;
                    }
                    rhs.hi  = rhs.hi >> 1;
                    num2.lo = num2.lo >> 1;
                    if ((num2.hi & 1L) == 1L)
                    {
                        num2.lo |= 9223372036854775808L;
                    }
                    num2.hi = num2.hi >> 1;
                }
                return(!flag ? num : -num);
            }
            if (rhs == lhs)
            {
                return(new Int128(1L));
            }
            return(new Int128(0L));
        }
コード例 #13
0
ファイル: ClipperBase.cs プロジェクト: whztt07/mobahero_src
        internal bool PointInPolygon(IntPoint pt, OutPt pp, bool UseFullRange)
        {
            OutPt outPt = pp;
            bool  flag  = false;

            if (UseFullRange)
            {
                do
                {
                    if (outPt.Pt.Y > pt.Y != outPt.Prev.Pt.Y > pt.Y && new Int128(pt.X - outPt.Pt.X) < Int128.Int128Mul(outPt.Prev.Pt.X - outPt.Pt.X, pt.Y - outPt.Pt.Y) / new Int128(outPt.Prev.Pt.Y - outPt.Pt.Y))
                    {
                        flag = !flag;
                    }
                    outPt = outPt.Next;
                }while (outPt != pp);
            }
            else
            {
                do
                {
                    if (outPt.Pt.Y > pt.Y != outPt.Prev.Pt.Y > pt.Y && pt.X - outPt.Pt.X < (outPt.Prev.Pt.X - outPt.Pt.X) * (pt.Y - outPt.Pt.Y) / (outPt.Prev.Pt.Y - outPt.Pt.Y))
                    {
                        flag = !flag;
                    }
                    outPt = outPt.Next;
                }while (outPt != pp);
            }
            return(flag);
        }
コード例 #14
0
ファイル: clipper.cs プロジェクト: doctorpangloss/Cordon2
		public static Int128 operator /(Int128 lhs, Int128 rhs)
		{
			if (rhs.lo == 0 && rhs.hi == 0)
				throw new ClipperException("Int128: divide by zero");
			
			bool negate = (rhs.hi < 0) != (lhs.hi < 0);
			if (lhs.hi < 0) lhs = -lhs;
			if (rhs.hi < 0) rhs = -rhs;
			
			if (rhs < lhs)
			{
				Int128 result = new Int128(0);
				Int128 cntr = new Int128(1);
				while (rhs.hi >= 0 && !(rhs > lhs))
				{
					rhs.hi <<= 1;
					if ((Int64)rhs.lo < 0) rhs.hi++;
					rhs.lo <<= 1;
					
					cntr.hi <<= 1;
					if ((Int64)cntr.lo < 0) cntr.hi++;
					cntr.lo <<= 1;
				}
				rhs.lo >>= 1;
				if ((rhs.hi & 1) == 1)
					rhs.lo |= 0x8000000000000000;
				rhs.hi = (Int64)((UInt64)rhs.hi >> 1);
				
				cntr.lo >>= 1;
				if ((cntr.hi & 1) == 1)
					cntr.lo |= 0x8000000000000000;
				cntr.hi >>= 1;
				
				while (cntr.hi != 0 || cntr.lo != 0)
				{
					if (!(lhs < rhs))
					{
						lhs -= rhs;
						result.hi |= cntr.hi;
						result.lo |= cntr.lo;
					}
					rhs.lo >>= 1;
					if ((rhs.hi & 1) == 1)
						rhs.lo |= 0x8000000000000000;
					rhs.hi >>= 1;
					
					cntr.lo >>= 1;
					if ((cntr.hi & 1) == 1)
						cntr.lo |= 0x8000000000000000;
					cntr.hi >>= 1;
				}
				return negate ? -result : result;
			}
			else if (rhs == lhs)
				return new Int128(1);
			else
				return new Int128(0);
		}
コード例 #15
0
ファイル: clipper.cs プロジェクト: doctorpangloss/Cordon2
		//nb: Constructing two new Int128 objects every time we want to multiply longs  
		//is slow. So, although calling the Int128Mul method doesn't look as clean, the 
		//code runs significantly faster than if we'd used the * operator.
		
		public static Int128 Int128Mul(Int64 lhs, Int64 rhs)
		{
			bool negate = (lhs < 0) != (rhs < 0);
			if (lhs < 0) lhs = -lhs;
			if (rhs < 0) rhs = -rhs;
			UInt64 int1Hi = (UInt64)lhs >> 32;
			UInt64 int1Lo = (UInt64)lhs & 0xFFFFFFFF;
			UInt64 int2Hi = (UInt64)rhs >> 32;
			UInt64 int2Lo = (UInt64)rhs & 0xFFFFFFFF;
			
			//nb: see comments in clipper.pas
			UInt64 a = int1Hi * int2Hi;
			UInt64 b = int1Lo * int2Lo;
			UInt64 c = int1Hi * int2Lo + int1Lo * int2Hi;
			
			UInt64 lo;
			Int64 hi;
			hi = (Int64)(a + (c >> 32));
			
			unchecked { lo = (c << 32) + b; }
			if (lo < b) hi++;
			Int128 result = new Int128(hi, lo);
			return negate ? -result : result;
		}
コード例 #16
0
ファイル: clipper.cs プロジェクト: doctorpangloss/Cordon2
		public Int128(Int128 val)
		{
			hi = val.hi;
			lo = val.lo;
		}