]> git.nega.tv - josh/narcissus/commitdiff
Make rect_height_compare a stable sort
authorJoshua Simmons <josh@nega.tv>
Sun, 26 Feb 2023 09:47:01 +0000 (10:47 +0100)
committerJoshua Simmons <josh@nega.tv>
Sun, 26 Feb 2023 09:47:01 +0000 (10:47 +0100)
stb_rect_pack was producing different results on different platforms due to differing qsort implementations.

This change uses the existing was_packed field to make the sort stable.

libs/ffi/stb_truetype-sys/src/stb_rect_pack.h

index 0d88cb56f70a8346f7a20c79dc9a6a3bfeaf9982..9ab59238ab34c51ac030658da3ec0af2877a11e3 100644 (file)
@@ -555,7 +555,11 @@ static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
         return -1;
     if (p->h < q->h)
         return 1;
-    return (p->w > q->w) ? -1 : (p->w < q->w);
+    if (p->w > q->w)
+      return -1;
+    if (p->w < q->w)
+      return  1;
+   return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
 }
 
 static int STBRP__CDECL rect_original_order(const void *a, const void *b)