Simplify GskPathPoint

Use simple representation of just
{ contour index, segment index, t value }
This commit is contained in:
Matthias Clasen
2023-08-08 18:14:27 -04:00
parent cc19781d27
commit c35bb11c18
4 changed files with 33 additions and 32 deletions

View File

@@ -420,8 +420,8 @@ gsk_standard_contour_get_closest_point (const GskContour *contour,
if (dist <= threshold)
{
*out_dist = dist;
result->data.std.idx = 0;
result->data.std.t = 0;
result->idx = 0;
result->t = 0;
return TRUE;
}
@@ -448,8 +448,8 @@ gsk_standard_contour_get_closest_point (const GskContour *contour,
if (best_idx != G_MAXUINT)
{
*out_dist = threshold;
result->data.std.idx = best_idx;
result->data.std.t = best_t;
result->idx = best_idx;
result->t = best_t;
return TRUE;
}
@@ -464,14 +464,14 @@ gsk_standard_contour_get_position (const GskContour *contour,
GskStandardContour *self = (GskStandardContour *) contour;
GskCurve curve;
if (G_UNLIKELY (point->data.std.idx == 0))
if (G_UNLIKELY (point->idx == 0))
{
*position = self->points[0];
return;
}
gsk_curve_init (&curve, self->ops[point->data.std.idx]);
gsk_curve_get_point (&curve, point->data.std.t, position);
gsk_curve_init (&curve, self->ops[point->idx]);
gsk_curve_get_point (&curve, point->t, position);
}
static void
@@ -485,14 +485,14 @@ gsk_standard_contour_get_tangent (const GskContour *contour,
gsize idx;
float t;
if (G_UNLIKELY (point->data.std.idx == 0))
if (G_UNLIKELY (point->idx == 0))
{
graphene_vec2_init (tangent, 1, 0);
return;
}
idx = point->data.std.idx;
t = point->data.std.t;
idx = point->idx;
t = point->t;
if (t == 0 && direction == GSK_PATH_START)
{
@@ -535,11 +535,11 @@ gsk_standard_contour_get_curvature (const GskContour *contour,
GskStandardContour *self = (GskStandardContour *) contour;
GskCurve curve;
if (G_UNLIKELY (point->data.std.idx == 0))
if (G_UNLIKELY (point->idx == 0))
return 0;
gsk_curve_init (&curve, self->ops[point->data.std.idx]);
return gsk_curve_get_curvature (&curve, point->data.std.t, center);
gsk_curve_init (&curve, self->ops[point->idx]);
return gsk_curve_get_curvature (&curve, point->t, center);
}
static const GskContourClass GSK_STANDARD_CONTOUR_CLASS =

View File

@@ -532,7 +532,6 @@ gsk_path_get_closest_point (GskPath *self,
{
found = TRUE;
res->contour = i;
res->path = self;
threshold = distance;
}
}

View File

@@ -81,11 +81,14 @@ gsk_path_point_get_position (GskPath *path,
graphene_point_t *position)
{
GskRealPathPoint *self = (GskRealPathPoint *) point;
const GskContour *contour = gsk_path_get_contour (path, self->contour);
const GskContour *contour;
g_return_if_fail (path == self->path);
g_return_if_fail (contour != NULL);
g_return_if_fail (path != NULL);
g_return_if_fail (point != NULL);
g_return_if_fail (position != NULL);
g_return_if_fail (self->contour < gsk_path_get_n_contours (path));
contour = gsk_path_get_contour (path, self->contour),
gsk_contour_get_position (contour, self, position);
}
@@ -114,11 +117,14 @@ gsk_path_point_get_tangent (GskPath *path,
graphene_vec2_t *tangent)
{
GskRealPathPoint *self = (GskRealPathPoint *) point;
const GskContour *contour = gsk_path_get_contour (path, self->contour);
const GskContour *contour;
g_return_if_fail (path == self->path);
g_return_if_fail (contour != NULL);
g_return_if_fail (path != NULL);
g_return_if_fail (point != NULL);
g_return_if_fail (tangent != NULL);
g_return_if_fail (self->contour < gsk_path_get_n_contours (path));
contour = gsk_path_get_contour (path, self->contour),
gsk_contour_get_tangent (contour, self, direction, tangent);
}
@@ -126,7 +132,7 @@ gsk_path_point_get_tangent (GskPath *path,
* gsk_path_point_get_curvature:
* @path: a `GskPath`
* @point: a `GskPathPoint` on @path
* @center: (out caller-allocates): Return location for
* @center: (out caller-allocates) (nullable): Return location for
* the center of the osculating circle
*
* Calculates the curvature of the path at the point.
@@ -146,10 +152,12 @@ gsk_path_point_get_curvature (GskPath *path,
graphene_point_t *center)
{
GskRealPathPoint *self = (GskRealPathPoint *) point;
const GskContour *contour = gsk_path_get_contour (path, self->contour);
const GskContour *contour;
g_return_val_if_fail (path == self->path, 0);
g_return_val_if_fail (contour != NULL, 0);
g_return_val_if_fail (path != NULL, 0);
g_return_val_if_fail (point != NULL, 0);
g_return_val_if_fail (self->contour < gsk_path_get_n_contours (path), 0);
contour = gsk_path_get_contour (path, self->contour);
return gsk_contour_get_curvature (contour, self, center);
}

View File

@@ -7,15 +7,9 @@ G_BEGIN_DECLS
struct _GskRealPathPoint
{
GskPath *path;
gsize contour;
union {
struct {
unsigned int idx;
float t;
} std;
} data;
unsigned int idx;
float t;
};
G_STATIC_ASSERT (sizeof (GskRealPathPoint) <= sizeof (GskPathPoint));