pod: improve compare function

Use the area to compare two rectangles. Use the width to break a tie.

This way the sorting is at least a bit more predictable and independent
of the order of the arguments.
This commit is contained in:
Wim Taymans 2025-07-22 14:19:08 +02:00
parent 495d6ba796
commit 5b436abef7

View file

@ -56,12 +56,14 @@ SPA_API_POD_COMPARE int spa_pod_compare_value(uint32_t type, const void *r1, con
{ {
const struct spa_rectangle *rec1 = (struct spa_rectangle *) r1, const struct spa_rectangle *rec1 = (struct spa_rectangle *) r1,
*rec2 = (struct spa_rectangle *) r2; *rec2 = (struct spa_rectangle *) r2;
if (rec1->width == rec2->width && rec1->height == rec2->height) uint64_t a1, a2;
return 0; a1 = ((uint64_t) rec1->width) * rec1->height;
else if (rec1->width < rec2->width || rec1->height < rec2->height) a2 = ((uint64_t) rec2->width) * rec2->height;
if (a1 < a2)
return -1; return -1;
else if (a1 > a2)
return 1; return 1;
return SPA_CMP(rec1->width, rec2->width);
} }
case SPA_TYPE_Fraction: case SPA_TYPE_Fraction:
{ {