1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 870149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com#ifndef SkLineClipper_DEFINED 970149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com#define SkLineClipper_DEFINED 1070149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com 1170149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com#include "SkRect.h" 1270149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com#include "SkPoint.h" 1370149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com 1470149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.comclass SkLineClipper { 1570149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.compublic: 1670149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com enum { 17c8d640b1788822a8697816b645c327383a1d1f20reed@google.com kMaxPoints = 4, 18c8d640b1788822a8697816b645c327383a1d1f20reed@google.com kMaxClippedLineSegments = kMaxPoints - 1 1970149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com }; 2070149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com 2170149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com /* Clip the line pts[0]...pts[1] against clip, ignoring segments that 2270149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com lie completely above or below the clip. For portions to the left or 2370149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com right, turn those into vertical line segments that are aligned to the 2470149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com edge of the clip. 25fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 2670149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com Return the number of line segments that result, and store the end-points 2770149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com of those segments sequentially in lines as follows: 2870149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com 1st segment: lines[0]..lines[1] 2970149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com 2nd segment: lines[1]..lines[2] 3070149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com 3rd segment: lines[2]..lines[3] 3170149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com */ 3270149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com static int ClipLine(const SkPoint pts[2], const SkRect& clip, 3370149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com SkPoint lines[kMaxPoints]); 34e28ff55d980d2992618b6b721c848aba96cf759areed@android.com 35e28ff55d980d2992618b6b721c848aba96cf759areed@android.com /* Intersect the line segment against the rect. If there is a non-empty 36e28ff55d980d2992618b6b721c848aba96cf759areed@android.com resulting segment, return true and set dst[] to that segment. If not, 37e28ff55d980d2992618b6b721c848aba96cf759areed@android.com return false and ignore dst[]. 38fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 39e28ff55d980d2992618b6b721c848aba96cf759areed@android.com ClipLine is specialized for scan-conversion, as it adds vertical 40e28ff55d980d2992618b6b721c848aba96cf759areed@android.com segments on the sides to show where the line extended beyond the 41e28ff55d980d2992618b6b721c848aba96cf759areed@android.com left or right sides. IntersectLine does not. 42e28ff55d980d2992618b6b721c848aba96cf759areed@android.com */ 43e28ff55d980d2992618b6b721c848aba96cf759areed@android.com static bool IntersectLine(const SkPoint src[2], const SkRect& clip, 44e28ff55d980d2992618b6b721c848aba96cf759areed@android.com SkPoint dst[2]); 4570149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com}; 4670149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com 4770149060a74bb212e67eb140be7cbf97a7cd36a8reed@android.com#endif 48