[raster] Keep the interior of transformed rectangle clips (#6470)

The point-in-quad test rejected the interior side of each edge for
both winding orders. Reverse the comparisons for rectangle and mask
intersections, and clarify how the edge normal depends on winding.

Add a regression for skew, reflected skew, and rotation, with one or
two nested rectangle clips to exercise both intersection paths. The
center pixel was transparent before the fix. The full Meson suite
passes (293 tests).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-AM92X98M.

Assisted-by: OpenAI Codex
This commit is contained in:
Behdad Esfahbod authored and GitHub committed 2026-10-29 19:07:51 -06:00
1 parent be6b6ab2b5
commit df19e5053b
2 files changed
+50 -3

No files matched your search

+5 -3
View File
@@ -629,7 +629,9 @@ hb_raster_paint_push_clip_rectangle (hb_paint_funcs_t *pfuncs HB_UNUSED,
/* Precompute edge normals for point-in-quad test.
* Edge i goes from corner i to corner (i+1)%4.
* Normal = (dy, -dx); inside test: dot(normal, p-corner) >= 0 */
* Normal = (dy, -dx) points inward for a clockwise quad, so the
* inside test is dot(normal, p-corner) >= 0; a reflected transform
* yields a counter-clockwise quad and flips the sign. */
float enx[4], eny[4], ed[4];
for (unsigned i = 0; i < 4; i++)
{
@@ -658,7 +660,7 @@ hb_raster_paint_push_clip_rectangle (hb_paint_funcs_t *pfuncs HB_UNUSED,
for (unsigned i = 0; i < 4; i++)
{
float d = enx[i] * px_f + eny[i] * py_f;
if (ccw ? d < ed[i] : d > ed[i])
if (ccw ? d > ed[i] : d < ed[i])
{
inside = false;
break;
@@ -688,7 +690,7 @@ hb_raster_paint_push_clip_rectangle (hb_paint_funcs_t *pfuncs HB_UNUSED,
for (unsigned i = 0; i < 4; i++)
{
float d = enx[i] * px_f + eny[i] * py_f;
if (ccw ? d < ed[i] : d > ed[i])
if (ccw ? d > ed[i] : d < ed[i])
{
inside = false;
break;
+45
View File
@@ -601,6 +601,50 @@ test_set_extents_while_painting (void)
hb_raster_paint_destroy (paint);
}
static void
test_clip_rectangle_transformed (void)
{
const struct {
float xx, yx, xy, yy, dx, dy;
unsigned center_x;
} transforms[] = {
{1.f, 0.f, 0.2f, 1.f, 0.f, 0.f, 38},
{1.f, 0.f, 0.2f, -1.f, 0.f, 64.f, 38},
{0.f, 1.f, -1.f, 0.f, 64.f, 0.f, 32},
};
/* Cover both winding orders and intersecting with a rectangle or mask. */
for (const auto &t : transforms)
for (unsigned depth = 1; depth <= 2; depth++)
{
hb_raster_paint_t *paint = hb_raster_paint_create_or_fail ();
g_assert_nonnull (paint);
hb_raster_extents_t ext = {0, 0, 64, 64, 0};
hb_raster_paint_set_extents (paint, &ext);
hb_paint_funcs_t *funcs = hb_raster_paint_get_funcs (paint);
hb_paint_push_transform (funcs, paint, t.xx, t.yx, t.xy, t.yy, t.dx, t.dy);
for (unsigned i = 0; i < depth; i++)
hb_paint_push_clip_rectangle (funcs, paint, 16.f, 16.f, 48.f, 48.f);
hb_paint_color (funcs, paint, true, HB_COLOR (0, 0, 0, 255));
for (unsigned i = 0; i < depth; i++)
hb_paint_pop_clip (funcs, paint);
hb_paint_pop_transform (funcs, paint);
hb_raster_image_t *image = hb_raster_paint_render (paint);
g_assert_nonnull (image);
hb_raster_extents_t out_ext;
hb_raster_image_get_extents (image, &out_ext);
const uint8_t *buffer = hb_raster_image_get_buffer (image);
/* The transformed center is opaque; the corner is outside the clip. */
g_assert_cmpuint (buffer[32 * out_ext.stride + t.center_x * 4 + 3], ==, 255);
g_assert_cmpuint (buffer[3], ==, 0);
hb_raster_image_destroy (image);
hb_raster_paint_destroy (paint);
}
}
/* ── main ────────────────────────────────────────────────────────── */
int
@@ -622,6 +666,7 @@ main (int argc, char **argv)
hb_test_add (test_background_stride);
hb_test_add (test_paint_reset);
hb_test_add (test_set_extents_while_painting);
hb_test_add (test_clip_rectangle_transformed);
return hb_test_run ();
}