michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: #ifndef SkLineClipper_DEFINED michael@0: #define SkLineClipper_DEFINED michael@0: michael@0: #include "SkRect.h" michael@0: #include "SkPoint.h" michael@0: michael@0: class SkLineClipper { michael@0: public: michael@0: enum { michael@0: kMaxPoints = 4, michael@0: kMaxClippedLineSegments = kMaxPoints - 1 michael@0: }; michael@0: michael@0: /* Clip the line pts[0]...pts[1] against clip, ignoring segments that michael@0: lie completely above or below the clip. For portions to the left or michael@0: right, turn those into vertical line segments that are aligned to the michael@0: edge of the clip. michael@0: michael@0: Return the number of line segments that result, and store the end-points michael@0: of those segments sequentially in lines as follows: michael@0: 1st segment: lines[0]..lines[1] michael@0: 2nd segment: lines[1]..lines[2] michael@0: 3rd segment: lines[2]..lines[3] michael@0: */ michael@0: static int ClipLine(const SkPoint pts[2], const SkRect& clip, michael@0: SkPoint lines[kMaxPoints]); michael@0: michael@0: /* Intersect the line segment against the rect. If there is a non-empty michael@0: resulting segment, return true and set dst[] to that segment. If not, michael@0: return false and ignore dst[]. michael@0: michael@0: ClipLine is specialized for scan-conversion, as it adds vertical michael@0: segments on the sides to show where the line extended beyond the michael@0: left or right sides. IntersectLine does not. michael@0: */ michael@0: static bool IntersectLine(const SkPoint src[2], const SkRect& clip, michael@0: SkPoint dst[2]); michael@0: }; michael@0: michael@0: #endif