mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
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:
parent
495d6ba796
commit
5b436abef7
1 changed files with 6 additions and 4 deletions
|
|
@ -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:
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue