From 5b436abef700b74b8e51082af2dab4c29762a5ca Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 22 Jul 2025 14:19:08 +0200 Subject: [PATCH] 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. --- spa/include/spa/pod/compare.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spa/include/spa/pod/compare.h b/spa/include/spa/pod/compare.h index cb8d5d3b1..144bd4a5a 100644 --- a/spa/include/spa/pod/compare.h +++ b/spa/include/spa/pod/compare.h @@ -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, *rec2 = (struct spa_rectangle *) r2; - if (rec1->width == rec2->width && rec1->height == rec2->height) - return 0; - else if (rec1->width < rec2->width || rec1->height < rec2->height) + uint64_t a1, a2; + a1 = ((uint64_t) rec1->width) * rec1->height; + a2 = ((uint64_t) rec2->width) * rec2->height; + if (a1 < a2) return -1; - else + if (a1 > a2) return 1; + return SPA_CMP(rec1->width, rec2->width); } case SPA_TYPE_Fraction: {