Exemplo n.º 1
0
    public static bool IntersectSegment(ref VInt2 seg1Src, ref VInt2 seg1Vec, ref VInt2 seg2Src, ref VInt2 seg2Vec, out VInt2 interPoint)
    {
        long num;
        long num2;
        long num3;

        IntMath.SegvecToLinegen(ref seg1Src, ref seg1Vec, out num, out num2, out num3);
        long num4;
        long num5;
        long num6;

        IntMath.SegvecToLinegen(ref seg2Src, ref seg2Vec, out num4, out num5, out num6);
        long num7 = num * num5 - num4 * num2;

        if (num7 != 0L)
        {
            long num8   = IntMath.Divide(num2 * num6 - num5 * num3, num7);
            long num9   = IntMath.Divide(num4 * num3 - num * num6, num7);
            bool result = IntMath.IsPointOnSegment(ref seg1Src, ref seg1Vec, num8, num9) && IntMath.IsPointOnSegment(ref seg2Src, ref seg2Vec, num8, num9);
            interPoint.x = (int)num8;
            interPoint.y = (int)num9;
            return(result);
        }
        interPoint = VInt2.zero;
        return(false);
    }