mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-09 10:20:07 +00:00
path: Tweak printing a bit more
We are dealing with floats here, so using g_ascii_dtostr isn't really the best. Update affected tests.
This commit is contained in:
parent
957d494090
commit
9c159cf129
@ -27,6 +27,13 @@
|
||||
#include "gskpathpoint.h"
|
||||
#include "gskstrokeprivate.h"
|
||||
|
||||
#include <float.h>
|
||||
|
||||
/* This is C11 */
|
||||
#ifndef FLT_DECIMAL_DIG
|
||||
#define FLT_DECIMAL_DIG 9
|
||||
#endif
|
||||
|
||||
typedef struct _GskContourClass GskContourClass;
|
||||
|
||||
struct _GskContour
|
||||
@ -98,15 +105,12 @@ struct _GskContourClass
|
||||
#define RAD_TO_DEG(x) ((x) / (G_PI / 180.f))
|
||||
|
||||
static void
|
||||
_g_string_append_double (GString *string,
|
||||
const char *prefix,
|
||||
double d)
|
||||
_g_string_append_float (GString *string,
|
||||
const char *prefix,
|
||||
float f)
|
||||
{
|
||||
char buf[G_ASCII_DTOSTR_BUF_SIZE];
|
||||
|
||||
g_ascii_dtostr (buf, G_ASCII_DTOSTR_BUF_SIZE, d);
|
||||
g_string_append (string, prefix);
|
||||
g_string_append (string, buf);
|
||||
g_string_append_printf (string, "%.*g", FLT_DECIMAL_DIG, f);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -114,8 +118,8 @@ _g_string_append_point (GString *string,
|
||||
const char *prefix,
|
||||
const graphene_point_t *pt)
|
||||
{
|
||||
_g_string_append_double (string, prefix, pt->x);
|
||||
_g_string_append_double (string, " ", pt->y);
|
||||
_g_string_append_float (string, prefix, pt->x);
|
||||
_g_string_append_float (string, " ", pt->y);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -481,7 +485,7 @@ foreach_print (GskPathOperation op,
|
||||
case GSK_PATH_CONIC:
|
||||
_g_string_append_point (string, " O ", &pts[1]);
|
||||
_g_string_append_point (string, ", ", &pts[2]);
|
||||
_g_string_append_double (string, ", ", weight);
|
||||
_g_string_append_float (string, ", ", weight);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -1347,7 +1351,6 @@ gsk_circle_contour_print (const GskContour *contour,
|
||||
{
|
||||
const GskCircleContour *self = (const GskCircleContour *) contour;
|
||||
float radius, radius_neg;
|
||||
float weight = M_SQRT1_2;
|
||||
|
||||
if (self->radius > 0)
|
||||
{
|
||||
@ -1364,16 +1367,16 @@ gsk_circle_contour_print (const GskContour *contour,
|
||||
_g_string_append_point (string, "M ", &GRAPHENE_POINT_INIT (self->center.x + radius, self->center.y));
|
||||
_g_string_append_point (string, " o ", &GRAPHENE_POINT_INIT (0, radius));
|
||||
_g_string_append_point (string, ", ", &GRAPHENE_POINT_INIT (radius_neg, radius));
|
||||
_g_string_append_double (string, ", ", weight);
|
||||
_g_string_append_float (string, ", ", M_SQRT1_2);
|
||||
_g_string_append_point (string, " o ", &GRAPHENE_POINT_INIT (radius_neg, 0));
|
||||
_g_string_append_point (string, ", ", &GRAPHENE_POINT_INIT (radius_neg, radius_neg));
|
||||
_g_string_append_double (string, ", ", weight);
|
||||
_g_string_append_float (string, ", ", M_SQRT1_2);
|
||||
_g_string_append_point (string, " o ", &GRAPHENE_POINT_INIT (0, radius_neg));
|
||||
_g_string_append_point (string, ", ", &GRAPHENE_POINT_INIT (radius, radius_neg));
|
||||
_g_string_append_double (string, ", ", weight);
|
||||
_g_string_append_float (string, ", ", M_SQRT1_2);
|
||||
_g_string_append_point (string, " o ", &GRAPHENE_POINT_INIT (radius, 0));
|
||||
_g_string_append_point (string, ", ", &GRAPHENE_POINT_INIT (radius, radius));
|
||||
_g_string_append_double (string, ", ", weight);
|
||||
_g_string_append_float (string, ", ", M_SQRT1_2);
|
||||
g_string_append (string, " z");
|
||||
}
|
||||
|
||||
@ -1804,9 +1807,9 @@ gsk_rect_contour_print (const GskContour *contour,
|
||||
const GskRectContour *self = (const GskRectContour *) contour;
|
||||
|
||||
_g_string_append_point (string, "M ", &GRAPHENE_POINT_INIT (self->x, self->y));
|
||||
_g_string_append_double (string, " h ", self->width);
|
||||
_g_string_append_double (string, " v ", self->height);
|
||||
_g_string_append_double (string, " h ", - self->width);
|
||||
_g_string_append_float (string, " h ", self->width);
|
||||
_g_string_append_float (string, " v ", self->height);
|
||||
_g_string_append_float (string, " h ", - self->width);
|
||||
g_string_append (string, " z");
|
||||
}
|
||||
|
||||
|
@ -1 +1,14 @@
|
||||
fill { }
|
||||
fill {
|
||||
child: color {
|
||||
bounds: 1.22359 0 47.5528 45.2254;
|
||||
color: rgb(255,0,204);
|
||||
}
|
||||
path: "\
|
||||
M 25 0\
|
||||
L 39.6946297 45.2254257\
|
||||
L 1.22358704 17.2745743\
|
||||
L 48.776413 17.2745743\
|
||||
L 10.3053684 45.2254257\
|
||||
Z";
|
||||
fill-rule: winding;
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ fill {
|
||||
}
|
||||
path: "\
|
||||
M 25 0\
|
||||
L 39.694629669189453 45.225425720214844\
|
||||
L 1.2235870361328125 17.274574279785156\
|
||||
L 48.776412963867188 17.274574279785156\
|
||||
L 10.305368423461914 45.225425720214844\
|
||||
L 39.6946297 45.2254257\
|
||||
L 1.22358704 17.2745743\
|
||||
L 48.776413 17.2745743\
|
||||
L 10.3053684 45.2254257\
|
||||
Z";
|
||||
fill-rule: winding;
|
||||
}
|
||||
|
@ -1 +1,16 @@
|
||||
stroke { }
|
||||
stroke {
|
||||
child: color {
|
||||
bounds: -2.77641 -4 55.5528 53.2254;
|
||||
color: rgb(255,0,204);
|
||||
}
|
||||
path: "\
|
||||
M 25 0\
|
||||
L 39.6946297 45.2254257\
|
||||
L 1.22358704 17.2745743\
|
||||
L 48.776413 17.2745743\
|
||||
L 10.3053684 45.2254257\
|
||||
Z";
|
||||
line-width: 1;
|
||||
line-cap: butt;
|
||||
line-join: miter;
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ stroke {
|
||||
}
|
||||
path: "\
|
||||
M 25 0\
|
||||
L 39.694629669189453 45.225425720214844\
|
||||
L 1.2235870361328125 17.274574279785156\
|
||||
L 48.776412963867188 17.274574279785156\
|
||||
L 10.305368423461914 45.225425720214844\
|
||||
L 39.6946297 45.2254257\
|
||||
L 1.22358704 17.2745743\
|
||||
L 48.776413 17.2745743\
|
||||
L 10.3053684 45.2254257\
|
||||
Z";
|
||||
line-width: 1;
|
||||
line-cap: butt;
|
||||
|
@ -1309,7 +1309,7 @@ test_rounded_rect_plain (void)
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
|
||||
s = gsk_path_to_string (path);
|
||||
g_assert_cmpstr (s, ==, "M 20 10 L 100 10 O 110 10, 110 20, 0.70710676908493042 L 110 200 O 110 210, 100 210, 0.70710676908493042 L 20 210 O 10 210, 10 200, 0.70710676908493042 L 10 20 O 10 10, 20 10, 0.70710676908493042 Z");
|
||||
g_assert_cmpstr (s, ==, "M 20 10 L 100 10 O 110 10, 110 20, 0.707106769 L 110 200 O 110 210, 100 210, 0.707106769 L 20 210 O 10 210, 10 200, 0.707106769 L 10 20 O 10 10, 20 10, 0.707106769 Z");
|
||||
g_free (s);
|
||||
|
||||
measure = gsk_path_measure_new (path);
|
||||
@ -1453,7 +1453,7 @@ test_rounded_rect_tricky (void)
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
|
||||
s = gsk_path_to_string (path);
|
||||
g_assert_cmpstr (s, ==, "M 10 10 L 110 10 L 110 110 L 110 210 L 20 210 O 10 210, 10 200, 0.70710676908493042 L 10 10 Z");
|
||||
g_assert_cmpstr (s, ==, "M 10 10 L 110 10 L 110 110 L 110 210 L 20 210 O 10 210, 10 200, 0.707106769 L 10 10 Z");
|
||||
g_free (s);
|
||||
|
||||
measure = gsk_path_measure_new (path);
|
||||
@ -1556,13 +1556,13 @@ test_rounded_rect_parse (void)
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
|
||||
s = gsk_path_to_string (path);
|
||||
g_assert_cmpstr (s, ==, "M 12 10 L 104 10 O 110 10, 110 18, 0.70710676908493042 L 110 109 O 110 121, 100 121, 0.70710676908493042 L 24 121 O 10 121, 10 105, 0.70710676908493042 L 10 14 O 10 10, 12 10, 0.70710676908493042 Z");
|
||||
g_assert_cmpstr (s, ==, "M 12 10 L 104 10 O 110 10, 110 18, 0.707106769 L 110 109 O 110 121, 100 121, 0.707106769 L 24 121 O 10 121, 10 105, 0.707106769 L 10 14 O 10 10, 12 10, 0.707106769 Z");
|
||||
|
||||
path2 = gsk_path_parse (s);
|
||||
g_free (s);
|
||||
|
||||
s = gsk_path_to_string (path2);
|
||||
g_assert_cmpstr (s, ==, "M 12 10 L 104 10 O 110 10, 110 18, 0.70710676908493042 L 110 109 O 110 121, 100 121, 0.70710676908493042 L 24 121 O 10 121, 10 105, 0.70710676908493042 L 10 14 O 10 10, 12 10, 0.70710676908493042 Z");
|
||||
g_assert_cmpstr (s, ==, "M 12 10 L 104 10 O 110 10, 110 18, 0.707106769 L 110 109 O 110 121, 100 121, 0.707106769 L 24 121 O 10 121, 10 105, 0.707106769 L 10 14 O 10 10, 12 10, 0.707106769 Z");
|
||||
g_free (s);
|
||||
|
||||
gsk_path_unref (path);
|
||||
@ -1589,7 +1589,7 @@ test_circle_plain (void)
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
|
||||
s = gsk_path_to_string (path);
|
||||
g_assert_cmpstr (s, ==, "M 110 100 o 0 10, -10 10, 0.70710676908493042 o -10 0, -10 -10, 0.70710676908493042 o 0 -10, 10 -10, 0.70710676908493042 o 10 0, 10 10, 0.70710676908493042 z");
|
||||
g_assert_cmpstr (s, ==, "M 110 100 o 0 10, -10 10, 0.707106769 o -10 0, -10 -10, 0.707106769 o 0 -10, 10 -10, 0.707106769 o 10 0, 10 10, 0.707106769 z");
|
||||
g_free (s);
|
||||
|
||||
measure = gsk_path_measure_new (path);
|
||||
@ -1642,7 +1642,7 @@ test_circle_zero (void)
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
|
||||
s = gsk_path_to_string (path);
|
||||
g_assert_cmpstr (s, ==, "M 100 100 o 0 0, 0 0, 0.70710676908493042 o 0 0, 0 0, 0.70710676908493042 o 0 0, 0 0, 0.70710676908493042 o 0 0, 0 0, 0.70710676908493042 z");
|
||||
g_assert_cmpstr (s, ==, "M 100 100 o 0 0, 0 0, 0.707106769 o 0 0, 0 0, 0.707106769 o 0 0, 0 0, 0.707106769 o 0 0, 0 0, 0.707106769 z");
|
||||
g_free (s);
|
||||
|
||||
measure = gsk_path_measure_new (path);
|
||||
|
Loading…
Reference in New Issue
Block a user