1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkCullPoints_DEFINED
18#define SkCullPoints_DEFINED
19
20#include "SkRect.h"
21
22class SkCullPoints {
23public:
24    SkCullPoints();
25    SkCullPoints(const SkIRect& r);
26
27    void    reset(const SkIRect& r);
28
29    /** Start a contour at (x,y). Follow this with call(s) to lineTo(...)
30    */
31    void    moveTo(int x, int y);
32
33    enum LineToResult {
34        kNo_Result,             //!< line segment was completely clipped out
35        kLineTo_Result,         //!< path.lineTo(pts[1]);
36        kMoveToLineTo_Result    //!< path.moveTo(pts[0]); path.lineTo(pts[1]);
37    };
38    /** Connect a line to the previous call to lineTo (or moveTo).
39    */
40    LineToResult lineTo(int x, int y, SkIPoint pts[2]);
41
42private:
43    SkIRect      fR;             // the caller's rectangle
44    SkIPoint     fAsQuad[4];     // cache of fR as 4 points
45    SkIPoint     fPrevPt;        // private state
46    LineToResult fPrevResult;   // private state
47
48    bool sect_test(int x0, int y0, int x1, int y1) const;
49};
50
51/////////////////////////////////////////////////////////////////////////////////
52
53class SkPath;
54
55/** \class SkCullPointsPath
56
57    Similar to SkCullPoints, but this class handles the return values
58    from lineTo, and automatically builds a SkPath with the result(s).
59*/
60class SkCullPointsPath {
61public:
62    SkCullPointsPath();
63    SkCullPointsPath(const SkIRect& r, SkPath* dst);
64
65    void reset(const SkIRect& r, SkPath* dst);
66
67    void    moveTo(int x, int y);
68    void    lineTo(int x, int y);
69
70private:
71    SkCullPoints    fCP;
72    SkPath*         fPath;
73};
74
75#endif
76