NewTOAPIA.Drawing.ClipLiangBarsky.clip_line_segment C# (CSharp) Method

clip_line_segment() public static method

public static clip_line_segment ( int &x1, int &y1, int &x2, int &y2, RectangleI clip_box ) : int
x1 int
y1 int
x2 int
y2 int
clip_box RectangleI
return int
        public static int clip_line_segment(ref int x1, ref int y1, ref int x2, ref int y2,
                                   RectangleI clip_box)
        {
            int f1 = clipping_flags(x1, y1, clip_box);
            int f2 = clipping_flags(x2, y2, clip_box);
            int ret = 0;

            if ((f2 | f1) == 0)
            {
                // Fully visible
                return 0;
            }

            if ((f1 & (int)clipping_flags_e.clipping_flags_x_clipped) != 0 &&
               (f1 & (int)clipping_flags_e.clipping_flags_x_clipped) == (f2 & (int)clipping_flags_e.clipping_flags_x_clipped))
            {
                // Fully clipped
                return 4;
            }

            if ((f1 & (int)clipping_flags_e.clipping_flags_y_clipped) != 0 &&
               (f1 & (int)clipping_flags_e.clipping_flags_y_clipped) == (f2 & (int)clipping_flags_e.clipping_flags_y_clipped))
            {
                // Fully clipped
                return 4;
            }

            int tx1 = x1;
            int ty1 = y1;
            int tx2 = x2;
            int ty2 = y2;
            if (f1 != 0)
            {
                if (!clip_move_point(tx1, ty1, tx2, ty2, clip_box, ref x1, ref y1, f1))
                {
                    return 4;
                }
                if (x1 == x2 && y1 == y2)
                {
                    return 4;
                }
                ret |= 1;
            }
            if (f2 != 0)
            {
                if (!clip_move_point(tx1, ty1, tx2, ty2, clip_box, ref x2, ref y2, f2))
                {
                    return 4;
                }
                if (x1 == x2 && y1 == y2)
                {
                    return 4;
                }
                ret |= 2;
            }
            return ret;
        }
    }