8#ifndef skgpu_tessellate_WangsFormula_DEFINED
9#define skgpu_tessellate_WangsFormula_DEFINED
24#define AI [[maybe_unused]] SK_ALWAYS_INLINE
39template<
int Degree>
constexpr float length_term(
float precision) {
40 return (Degree * (Degree - 1) / 8.f) * precision;
43 return ((Degree * Degree) * ((Degree - 1) * (Degree - 1)) / 64.f) * (precision * precision);
47 return sqrtf(sqrtf(
x));
66 static constexpr uint32_t kDigitsAfterBinaryPoint = std::numeric_limits<float>::digits - 1;
72 bits += (1u << kDigitsAfterBinaryPoint) - 1u;
79 const int exp = ((
bits >> kDigitsAfterBinaryPoint) & 0b1111'1111) - 127;
82 return exp > 0 ? exp : 0;
113 fC0 = {
m.rc(0,0),
m.rc(1,0)};
114 fC1 = {
m.rc(0,1),
m.rc(1,1)};
118 SkASSERT(
m.rc(3,0) == 0.f &&
m.rc(3,1) == 0.f &&
m.rc(3,2) == 0.f &&
m.rc(3,3) == 1.f);
119 fC0 = {
m.rc(0,0),
m.rc(1,0)};
120 fC1 = {
m.rc(0,1),
m.rc(1,1)};
124 return fC0 * vector.x() + fC1 * vector.y();
127 return join(fC0 * vectors.x() + fC1 * vectors.y(),
128 fC0 * vectors.z() + fC1 * vectors.w());
143 return (vv[0] + vv[1]) * length_term_p2<2>(precision);
149 sk_bit_cast<skvx::float2>(pts[0]),
150 sk_bit_cast<skvx::float2>(pts[1]),
151 sk_bit_cast<skvx::float2>(pts[2]),
181 return std::max(vv[0] + vv[1], vv[2] + vv[3]) * length_term_p2<3>(precision);
187 sk_bit_cast<skvx::float2>(pts[0]),
188 sk_bit_cast<skvx::float2>(pts[1]),
189 sk_bit_cast<skvx::float2>(pts[2]),
190 sk_bit_cast<skvx::float2>(pts[3]),
215 float kk = length_term_p2<3>(precision);
216 return 4*kk * (devWidth * devWidth + devHeight * devHeight);
242 p0 = vectorXform(p0);
243 p1 = vectorXform(p1);
244 p2 = vectorXform(p2);
261 const float dw = fabsf(-2 *
w + 2);
265 const float rp_minus_1 =
std::max(0.f, max_len * precision - 1);
266 const float numer = sqrtf(
dot(dp, dp)) * precision + rp_minus_1 * dw;
267 const float denom = 4 *
std::min(
w, 1.f);
272 return numer / denom;
279 sk_bit_cast<skvx::float2>(pts[0]),
280 sk_bit_cast<skvx::float2>(pts[1]),
281 sk_bit_cast<skvx::float2>(pts[2]),
291 return sqrtf(
conic_p2(tolerance, pts,
w, vectorXform));
static uint32_t SkFloat2Bits(float value)
static float max(float r, float g, float b)
static float min(float r, float g, float b)
SINT T dot(const Vec< N, T > &a, const Vec< N, T > &b)
static SkString join(const CommandLineFlags::StringArray &)