blob: cca41a1a90cffd45629c48410ed5c7d15d077e53 [file] [log] [blame]
Brian Osman7c979f52019-02-12 13:27:51 -05001/*
2* Copyright 2019 Google LLC
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 SkCurve_DEFINED
9#define SkCurve_DEFINED
10
11#include "SkScalar.h"
Brian Osman8b6283f2019-02-14 16:55:21 -050012#include "SkTArray.h"
Brian Osman7c979f52019-02-12 13:27:51 -050013
14class SkFieldVisitor;
15class SkRandom;
16
Brian Osman8b6283f2019-02-14 16:55:21 -050017struct SkCurveSegment {
18 SkScalar eval(SkScalar x, SkRandom& random) const;
19 void visitFields(SkFieldVisitor* v);
20
21 void setConstant(SkScalar c) {
22 fConstant = true;
23 fRanged = false;
24 fMin[0] = c;
25 }
26
27 SkScalar fMin[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
28 SkScalar fMax[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
29
30 bool fConstant = true;
31 bool fRanged = false;
32 bool fBidirectional = false;
33};
Brian Osman7c979f52019-02-12 13:27:51 -050034
35struct SkCurve {
36 SkCurve(SkScalar c = 0.0f) {
Brian Osman8b6283f2019-02-14 16:55:21 -050037 fSegments.push_back().setConstant(c);
Brian Osman7c979f52019-02-12 13:27:51 -050038 }
39
Brian Osman8b6283f2019-02-14 16:55:21 -050040 SkScalar eval(SkScalar x, SkRandom& random) const;
Brian Osman7c979f52019-02-12 13:27:51 -050041 void visitFields(SkFieldVisitor* v);
42
Brian Osman8b6283f2019-02-14 16:55:21 -050043 SkTArray<SkScalar, true> fXValues;
44 SkTArray<SkCurveSegment, true> fSegments;
Brian Osman7c979f52019-02-12 13:27:51 -050045};
46
47#endif // SkCurve_DEFINED