From 423ea55410d86c8c8cc4fb5219941bcbdeab2a33 Mon Sep 17 00:00:00 2001 From: David Reveman Date: Tue, 4 May 2004 04:01:18 +0000 Subject: [PATCH] Corrected some confusing comments about the math used for radial gradients --- ChangeLog | 5 +++++ src/cairo-pattern.c | 24 ++++++++++++++++-------- src/cairo_pattern.c | 24 ++++++++++++++++-------- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index ace0e8ec6..54a85073e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-05-04 David Reveman + + * src/cairo_pattern.c (_cairo_image_data_set_radial): Corrected some + confusing comments about the math used for radial gradients. + 2004-05-01 David Reveman * src/cairo_gl_surface.c (_cairo_gl_surface_create_pattern): diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index ef32f0c2f..b81b1bd01 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -620,20 +620,28 @@ _cairo_image_data_set_radial (cairo_pattern_t *pattern, factor = (sqrt (ex * ex + ey * ey) - r0) * r1; } else { - /* Here we need to calulate distance c0 -> x; the distance from - the inner circle center c0, through point (ex, ey) to - point x where it crosses the outer circle. The gradient offset - can then be calculated within the distance of the inner and - outer circles. - - y y_x (ex, ey) + /* + y (ex, ey) c0 -------------------+---------- x \ | __-- \ | __-- - r0 \ | c1_y __-- + \ | __-- \ | __-- r1 \ | __-- c1 -- + + We need to calulate distance c0->x; the distance from + the inner circle center c0, through fragment position + (ex, ey) to point x where it crosses the outer circle. + + From points c0, c1 and (ex, ey) we get angle C0. With + angle C0 we calculate distance c1->y and c0->y and by + knowing c1->y and r1, we also know y->x. Adding y->x to + c0->y gives us c0->x. The gradient offset can then be + calculated as: + + offset = (c0->e - r0) / (c0->x - r0) + */ c0_e_x = ex - c0.x; diff --git a/src/cairo_pattern.c b/src/cairo_pattern.c index ef32f0c2f..b81b1bd01 100644 --- a/src/cairo_pattern.c +++ b/src/cairo_pattern.c @@ -620,20 +620,28 @@ _cairo_image_data_set_radial (cairo_pattern_t *pattern, factor = (sqrt (ex * ex + ey * ey) - r0) * r1; } else { - /* Here we need to calulate distance c0 -> x; the distance from - the inner circle center c0, through point (ex, ey) to - point x where it crosses the outer circle. The gradient offset - can then be calculated within the distance of the inner and - outer circles. - - y y_x (ex, ey) + /* + y (ex, ey) c0 -------------------+---------- x \ | __-- \ | __-- - r0 \ | c1_y __-- + \ | __-- \ | __-- r1 \ | __-- c1 -- + + We need to calulate distance c0->x; the distance from + the inner circle center c0, through fragment position + (ex, ey) to point x where it crosses the outer circle. + + From points c0, c1 and (ex, ey) we get angle C0. With + angle C0 we calculate distance c1->y and c0->y and by + knowing c1->y and r1, we also know y->x. Adding y->x to + c0->y gives us c0->x. The gradient offset can then be + calculated as: + + offset = (c0->e - r0) / (c0->x - r0) + */ c0_e_x = ex - c0.x;