void ValueTraits<VectorValue>::Lerp(const VectorValue& v0, const VectorValue& v1, float t, VectorValue* result) { SkASSERT(v0.size() == v1.size()); result->resize(v0.size()); for (size_t i = 0; i < v0.size(); ++i) { ValueTraits<ScalarValue>::Lerp(v0[i], v1[i], t, &(*result)[i]); } }
SkColor ValueTraits<VectorValue>::As<SkColor>(const VectorValue& v) { // best effort to turn this into a color const auto r = v.size() > 0 ? v[0] : 0, g = v.size() > 1 ? v[1] : 0, b = v.size() > 2 ? v[2] : 0, a = v.size() > 3 ? v[3] : 1; return SkColorSetARGB(SkScalarRoundToInt(SkTPin(a, 0.0f, 1.0f) * 255), SkScalarRoundToInt(SkTPin(r, 0.0f, 1.0f) * 255), SkScalarRoundToInt(SkTPin(g, 0.0f, 1.0f) * 255), SkScalarRoundToInt(SkTPin(b, 0.0f, 1.0f) * 255)); }
SkColor ValueTraits<VectorValue>::As<SkColor>(const VectorValue& v) { // best effort to turn this into a color const auto r = v.size() > 0 ? v[0] : 0, g = v.size() > 1 ? v[1] : 0, b = v.size() > 2 ? v[2] : 0, a = v.size() > 3 ? v[3] : 1; return SkColorSetARGB(SkTPin<SkScalar>(a, 0, 1) * 255, SkTPin<SkScalar>(r, 0, 1) * 255, SkTPin<SkScalar>(g, 0, 1) * 255, SkTPin<SkScalar>(b, 0, 1) * 255); }
SkPoint ValueTraits<VectorValue>::As<SkPoint>(const VectorValue& vec) { // best effort to turn this into a point const auto x = vec.size() > 0 ? vec[0] : 0, y = vec.size() > 1 ? vec[1] : 0; return SkPoint::Make(x, y); }
bool ValueTraits<VectorValue>::CanLerp(const VectorValue& v1, const VectorValue& v2) { return v1.size() == v2.size(); }
size_t ValueTraits<VectorValue>::Cardinality(const VectorValue& vec) { return vec.size(); }