forked from AuroraMiddleware/gtk
cssimagelinear: Avoid computing the length if we know it
We handlet the common easy cases manually anyway, so don't bother sqrt()ing the x/y coords in those cases.
This commit is contained in:
parent
cee8f78c6e
commit
59111d100f
@ -76,37 +76,43 @@ static void
|
|||||||
gtk_css_image_linear_compute_start_point (double angle_in_degrees,
|
gtk_css_image_linear_compute_start_point (double angle_in_degrees,
|
||||||
double width,
|
double width,
|
||||||
double height,
|
double height,
|
||||||
double *x,
|
double *out_x,
|
||||||
double *y)
|
double *out_y,
|
||||||
|
double *out_length)
|
||||||
{
|
{
|
||||||
double angle, c, slope, perpendicular;
|
double angle, c, slope, perpendicular;
|
||||||
|
double x, y, length;
|
||||||
|
|
||||||
angle = fmod (angle_in_degrees, 360);
|
angle = fmod (angle_in_degrees, 360);
|
||||||
if (angle < 0)
|
if (angle < 0)
|
||||||
angle += 360;
|
angle += 360;
|
||||||
|
|
||||||
if (angle == 0)
|
if (angle == 0)
|
||||||
{
|
{
|
||||||
*x = 0;
|
*out_x = 0;
|
||||||
*y = -height;
|
*out_y = -height;
|
||||||
|
*out_length = height;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (angle == 90)
|
else if (angle == 90)
|
||||||
{
|
{
|
||||||
*x = width;
|
*out_x = width;
|
||||||
*y = 0;
|
*out_y = 0;
|
||||||
|
*out_length = width;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (angle == 180)
|
else if (angle == 180)
|
||||||
{
|
{
|
||||||
*x = 0;
|
*out_x = 0;
|
||||||
*y = height;
|
*out_y = height;
|
||||||
|
*out_length = height;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (angle == 270)
|
else if (angle == 270)
|
||||||
{
|
{
|
||||||
*x = -width;
|
*out_x = -width;
|
||||||
*y = 0;
|
*out_y = 0;
|
||||||
|
*out_length = width;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,12 +125,18 @@ gtk_css_image_linear_compute_start_point (double angle_in_degrees,
|
|||||||
width = - width;
|
width = - width;
|
||||||
if (angle < 90 || angle > 270)
|
if (angle < 90 || angle > 270)
|
||||||
height = - height;
|
height = - height;
|
||||||
|
|
||||||
/* Compute c (of y = mx + c) of perpendicular */
|
/* Compute c (of y = mx + c) of perpendicular */
|
||||||
c = height - perpendicular * width;
|
c = height - perpendicular * width;
|
||||||
|
|
||||||
*x = c / (slope - perpendicular);
|
x = c / (slope - perpendicular);
|
||||||
*y = perpendicular * *x + c;
|
y = perpendicular * x + c;
|
||||||
|
|
||||||
|
length = sqrt (x * x + y * y);
|
||||||
|
|
||||||
|
*out_x = x;
|
||||||
|
*out_y = y;
|
||||||
|
*out_length = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -173,9 +185,9 @@ gtk_css_image_linear_snapshot (GtkCssImage *image,
|
|||||||
|
|
||||||
gtk_css_image_linear_compute_start_point (angle,
|
gtk_css_image_linear_compute_start_point (angle,
|
||||||
width, height,
|
width, height,
|
||||||
&x, &y);
|
&x, &y,
|
||||||
|
&length);
|
||||||
|
|
||||||
length = sqrt (x * x + y * y);
|
|
||||||
gtk_css_image_linear_get_start_end (linear, length, &start, &end);
|
gtk_css_image_linear_get_start_end (linear, length, &start, &end);
|
||||||
|
|
||||||
if (start == end)
|
if (start == end)
|
||||||
|
Loading…
Reference in New Issue
Block a user