• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef SkLineClipper_DEFINED
2 #define SkLineClipper_DEFINED
3 
4 #include "SkRect.h"
5 #include "SkPoint.h"
6 
7 class SkLineClipper {
8 public:
9     enum {
10         kMaxPoints = 4
11     };
12 
13     /*  Clip the line pts[0]...pts[1] against clip, ignoring segments that
14         lie completely above or below the clip. For portions to the left or
15         right, turn those into vertical line segments that are aligned to the
16         edge of the clip.
17 
18         Return the number of line segments that result, and store the end-points
19         of those segments sequentially in lines as follows:
20             1st segment: lines[0]..lines[1]
21             2nd segment: lines[1]..lines[2]
22             3rd segment: lines[2]..lines[3]
23      */
24     static int ClipLine(const SkPoint pts[2], const SkRect& clip,
25                         SkPoint lines[kMaxPoints]);
26 
27     /*  Intersect the line segment against the rect. If there is a non-empty
28         resulting segment, return true and set dst[] to that segment. If not,
29         return false and ignore dst[].
30 
31         ClipLine is specialized for scan-conversion, as it adds vertical
32         segments on the sides to show where the line extended beyond the
33         left or right sides. IntersectLine does not.
34      */
35     static bool IntersectLine(const SkPoint src[2], const SkRect& clip,
36                               SkPoint dst[2]);
37 };
38 
39 #endif
40 
41