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