]> O.S.I.I.S - jp/vkvg.git/commitdiff
limit check for radial grad
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 17 Dec 2021 02:42:01 +0000 (03:42 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 17 Dec 2021 02:42:01 +0000 (03:42 +0100)
src/vkvg_pattern.c

index 202f4d45f61934ae97abd61e8e3b647802cc36b8..128c596181e286b179a7f425af04b628c632d21d 100644 (file)
@@ -58,8 +58,20 @@ VkvgPattern vkvg_pattern_create_radial (float cx0, float cy0, float radius0,
 
        vkvg_gradient_t* grad = (vkvg_gradient_t*)calloc(1,sizeof(vkvg_gradient_t));
 
-       grad->cp[0] = (vec4){{cx0}, {cy0},{radius0},{0}};
-       grad->cp[1] = (vec4){{cx1}, {cy1},{radius1},{0}};
+       vec2 c0 = {cx0, cy0};
+       vec2 c1 = {cx1, cy1};
+
+       if (radius0 > radius1 - 1.0f)
+               radius0 = radius1 - 1.0f;
+       vec2 u = vec2_sub (c0, c1);
+       float l = vec2_length(u);
+       if (l + radius0 + 1.0f >= radius1) {
+               vec2 v = vec2_div_s(u, l);
+               c0 = vec2_add(c1, vec2_mult_s (v, radius1 - radius0 - 1.0f));
+       }
+
+       grad->cp[0] = (vec4){{c0.x}, {c0.y},{radius0},{0}};
+       grad->cp[1] = (vec4){{c1.x}, {c1.y},{radius1},{0}};
 
        pat->data = grad;