blob: 2a28fa4495454a67dcbd59b16bb917314528ffd9 [file] [log] [blame]
reed@google.com603dbed2012-11-20 19:00:28 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "Test.h"
9#include "SkPaint.h"
10#include "SkPath.h"
11#include "SkRect.h"
12#include "SkStroke.h"
13
14static bool equal(const SkRect& a, const SkRect& b) {
15 return SkScalarNearlyEqual(a.left(), b.left()) &&
16 SkScalarNearlyEqual(a.top(), b.top()) &&
17 SkScalarNearlyEqual(a.right(), b.right()) &&
18 SkScalarNearlyEqual(a.bottom(), b.bottom());
19}
20
21static void test_strokerect(skiatest::Reporter* reporter) {
22 const SkScalar width = SkIntToScalar(10);
23 SkPaint paint;
24
25 paint.setStyle(SkPaint::kStroke_Style);
26 paint.setStrokeWidth(width);
27
28 SkRect r = { 0, 0, SkIntToScalar(200), SkIntToScalar(100) };
29
30 SkRect outer(r);
31 outer.outset(width/2, width/2);
32
33 static const SkPaint::Join joins[] = {
34 SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join
35 };
36
37 for (size_t i = 0; i < SK_ARRAY_COUNT(joins); ++i) {
38 paint.setStrokeJoin(joins[i]);
39
40 SkPath path, fillPath;
41 path.addRect(r);
42 paint.getFillPath(path, &fillPath);
43
44 REPORTER_ASSERT(reporter, equal(outer, fillPath.getBounds()));
skia.committer@gmail.comb0a327e2012-11-21 02:02:25 +000045
reed@google.com603dbed2012-11-20 19:00:28 +000046 bool isMiter = SkPaint::kMiter_Join == joins[i];
47 SkRect nested[2];
48 REPORTER_ASSERT(reporter, fillPath.isNestedRects(nested) == isMiter);
49 if (isMiter) {
50 SkRect inner(r);
51 inner.inset(width/2, width/2);
52 REPORTER_ASSERT(reporter, equal(nested[0], outer));
53 REPORTER_ASSERT(reporter, equal(nested[1], inner));
54 }
55 }
56}
57
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000058DEF_TEST(Stroke, reporter) {
reed@google.com603dbed2012-11-20 19:00:28 +000059 test_strokerect(reporter);
60}