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