[haiku-bugs] [Haiku] #10773: Gradient color stop sorting is not stable.

  • From: "pulkomandy" <trac@xxxxxxxxxxxx>
  • Date: Tue, 22 Apr 2014 08:38:04 -0000

#10773: Gradient color stop sorting is not stable.
--------------------------------+------------------------------
 Reporter:  pulkomandy          |        Owner:  stippi
     Type:  bug                 |       Status:  new
 Priority:  normal              |    Milestone:  R1
Component:  Kits/Interface Kit  |      Version:  R1/Development
 Keywords:                      |   Blocked By:
 Blocking:                      |  Has a Patch:  0
 Platform:  All                 |
--------------------------------+------------------------------
 Consider the following code used to create a stripped pattern using a
 BGradient:
 {{{
 gradient.AddColor(black, 0);
 gradient.AddColor(black, 127);
 gradient.AddColor(white, 127);
 gradient.AddColor(white, 255);
 }}}

 In ConvertToScreenForDrawing, the gradient stops will be sorted using
 BList.Sort. The sorting algorithm is not stable, so the two middle stops
 may be swapped. There are two ways to fix this:
 * Implement a stable sorting algorithm
 (http://en.wikipedia.org/wiki/Category:Stable_sorts)
 * Remove the AddColorStop method index parameter and use code similar to
 AddColor to find the proper index, or make that method private. This would
 allow BGradient to keep the list sorted, and remove the need for sorting
 it later. The method is used only in app_server (for reading the gradient
 data from app_server link) and when unarchiving a gradient.

 What is the preferred solution?

--
Ticket URL: <https://dev.haiku-os.org/ticket/10773>
Haiku <https://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: