xref: /aosp_15_r20/external/skia/docs/examples/Path_isRect.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(Path_isRect, 256, 256, true, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     auto debugster = [](const char* prefix, const SkPath& path) -> void {
7         SkRect rect;
8         SkPathDirection direction;
9         bool isClosed;
10         path.isRect(&rect, &isClosed, &direction) ?
11                 SkDebugf("%s is rect (%g, %g, %g, %g); is %s" "closed; direction %s\n", prefix,
12                          rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, isClosed ? "" : "not ",
13                          SkPathDirection::kCW == direction ? "CW" : "CCW") :
14                 SkDebugf("%s is not rect\n", prefix);
15     };
16     SkPath path;
17     debugster("empty", path);
18     path.addRect({10, 20, 30, 40});
19     debugster("addRect", path);
20     path.moveTo(60, 70);
21     debugster("moveTo", path);
22     path.lineTo(60, 70);
23     debugster("lineTo", path);
24     path.reset();
25     const SkPoint pts[] = { {0, 0}, {0, 80}, {80, 80}, {80, 0}, {40, 0}, {20, 0} };
26     path.addPoly(pts, std::size(pts), false);
27     debugster("addPoly", path);
28 }
29 }  // END FIDDLE
30