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