blob: fdd1a9c6976deabe06d60493846523a5db82be0b [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#include "SkCurve.h"
9
10#include "SkRandom.h"
11#include "SkReflected.h"
12
13SkScalar SkCurve::eval(float x, SkRandom& random) const {
14 float ix = (1 - x);
15 float y0 = fMin[0] * ix*ix*ix + fMin[1] * 3 * ix*ix*x + fMin[2] * 3 * ix*x*x + fMin[3] * x*x*x;
16 float y1 = fMax[0] * ix*ix*ix + fMax[1] * 3 * ix*ix*x + fMax[2] * 3 * ix*x*x + fMax[3] * x*x*x;
17 return fRanged ? y0 + (y1 - y0) * random.nextF() : y0;
18}
19
20void SkCurve::visitFields(SkFieldVisitor* v) {
21 v->visit("Ranged", fRanged);
22 v->visit("A0", fMin[0]);
23 v->visit("B0", fMin[1]);
24 v->visit("C0", fMin[2]);
25 v->visit("D0", fMin[3]);
26 v->visit("A1", fMax[0]);
27 v->visit("B1", fMax[1]);
28 v->visit("C1", fMax[2]);
29 v->visit("D1", fMax[3]);
30}
31
32float SkRangedFloat::eval(SkRandom& random) const {
33 return random.nextRangeF(fMin, fMax);
34}
35
36void SkRangedFloat::visitFields(SkFieldVisitor* v) {
37 v->visit("min", fMin);
38 v->visit("max", fMax);
39}