Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPathMakers.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 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#ifndef SkPathMakers_DEFINED
9#define SkPathMakers_DEFINED
10
14
15template <unsigned N> class SkPath_PointIterator {
16public:
17 SkPath_PointIterator(SkPathDirection dir, unsigned startIndex)
18 : fCurrent(startIndex % N)
19 , fAdvance(dir == SkPathDirection::kCW ? 1 : N - 1) { }
20
21 const SkPoint& current() const {
22 SkASSERT(fCurrent < N);
23 return fPts[fCurrent];
24 }
25
26 const SkPoint& next() {
27 fCurrent = (fCurrent + fAdvance) % N;
28 return this->current();
29 }
30
31 protected:
33
34 private:
35 unsigned fCurrent;
36 unsigned fAdvance;
37};
38
40public:
41 SkPath_RectPointIterator(const SkRect& rect, SkPathDirection dir, unsigned startIndex)
42 : SkPath_PointIterator(dir, startIndex) {
43
44 fPts[0] = SkPoint::Make(rect.fLeft, rect.fTop);
45 fPts[1] = SkPoint::Make(rect.fRight, rect.fTop);
46 fPts[2] = SkPoint::Make(rect.fRight, rect.fBottom);
47 fPts[3] = SkPoint::Make(rect.fLeft, rect.fBottom);
48 }
49};
50
52public:
53 SkPath_OvalPointIterator(const SkRect& oval, SkPathDirection dir, unsigned startIndex)
54 : SkPath_PointIterator(dir, startIndex) {
55
56 const SkScalar cx = oval.centerX();
57 const SkScalar cy = oval.centerY();
58
59 fPts[0] = SkPoint::Make(cx, oval.fTop);
60 fPts[1] = SkPoint::Make(oval.fRight, cy);
61 fPts[2] = SkPoint::Make(cx, oval.fBottom);
62 fPts[3] = SkPoint::Make(oval.fLeft, cy);
63 }
64};
65
67public:
68 SkPath_RRectPointIterator(const SkRRect& rrect, SkPathDirection dir, unsigned startIndex)
69 : SkPath_PointIterator(dir, startIndex) {
70
71 const SkRect& bounds = rrect.getBounds();
72 const SkScalar L = bounds.fLeft;
73 const SkScalar T = bounds.fTop;
74 const SkScalar R = bounds.fRight;
75 const SkScalar B = bounds.fBottom;
76
85 }
86};
87
88#endif
#define SkASSERT(cond)
Definition SkAssert.h:116
SkPathDirection
Definition SkPathTypes.h:34
#define N
Definition beziers.cpp:19
SkPath_OvalPointIterator(const SkRect &oval, SkPathDirection dir, unsigned startIndex)
const SkPoint & current() const
const SkPoint & next()
SkPath_PointIterator(SkPathDirection dir, unsigned startIndex)
SkPath_RRectPointIterator(const SkRRect &rrect, SkPathDirection dir, unsigned startIndex)
SkPath_RectPointIterator(const SkRect &rect, SkPathDirection dir, unsigned startIndex)
SkVector radii(Corner corner) const
Definition SkRRect.h:271
@ kUpperLeft_Corner
index of top-left corner radii
Definition SkRRect.h:252
@ kLowerRight_Corner
index of bottom-right corner radii
Definition SkRRect.h:254
@ kUpperRight_Corner
index of top-right corner radii
Definition SkRRect.h:253
@ kLowerLeft_Corner
index of bottom-left corner radii
Definition SkRRect.h:255
const SkRect & getBounds() const
Definition SkRRect.h:279
float SkScalar
Definition extension.cpp:12
#define R(r)
#define T
float fX
x-axis value
static constexpr SkPoint Make(float x, float y)
float fY
y-axis value
SkScalar fBottom
larger y-axis bounds
Definition extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition extension.cpp:16
constexpr float centerX() const
Definition SkRect.h:776
constexpr float centerY() const
Definition SkRect.h:785
SkScalar fTop
smaller y-axis bounds
Definition extension.cpp:15