GA_GUIHelper.segment_rect_intersection C# (CSharp) Method

segment_rect_intersection() protected static method

protected static segment_rect_intersection ( Rect bounds, Vector2 &p1, Vector2 &p2 ) : bool
bounds Rect
p1 Vector2
p2 Vector2
return bool
    protected static bool segment_rect_intersection(Rect bounds, ref Vector2 p1, ref Vector2 p2)
    {
        float u1 = 0.0f, u2 = 1.0f, dx = p2.x - p1.x, dy;

        if (clip_test(-dx, p1.x - bounds.xMin, ref u1, ref u2))
            if (clip_test(dx, bounds.xMax - p1.x, ref u1, ref u2))
            {
                dy = p2.y - p1.y;

                if (clip_test(-dy, p1.y - bounds.yMin, ref u1, ref u2))
                    if (clip_test(dy, bounds.yMax - p1.y, ref u1, ref u2))
                    {
                        if (u2 < 1.0)
                        {
                            p2.x = p1.x + u2 * dx;

                            p2.y = p1.y + u2 * dy;
                        }

                        if (u1 > 0.0)
                        {
                            p1.x += u1 * dx;

                            p1.y += u1 * dy;
                        }

                        return true;
                    }
            }

        return false;
    }