SortVisualsByDepth

ceramic.SortVisualsByDepth (Class)

Simplified high-performance stable merge sort for Visual arrays based on depth only.

SortVisualsByDepth provides a streamlined sorting algorithm that orders visuals purely by their depth property, ignoring other rendering criteria like texture or blending mode. This makes it faster than SortVisuals when you only need depth-based ordering.

Key characteristics:

  • Sorts by depth only (higher depth values render on top)
  • Stable sort: preserves relative order of visuals with equal depth
  • Same optimizations as SortVisuals (inlining, unsafe access, insertion sort for small arrays)
  • Faster than full SortVisuals when texture batching is not a concern

Use cases:

  • UI elements where depth is the primary ordering criterion
  • Debug visualizations
  • Scenarios where draw call batching is less important than simplicity

Example usage:

var visuals:Array<Visual> = [...];
SortVisualsByDepth.sort(visuals); // Sorts in place by depth only
See: ceramic.SortVisuals For complete rendering order sorting, ceramic.Visual.depth For the depth property

Static Members

sort(a: Array<Visual>): Void

Sorts an array of Visual objects in place by depth value only.

This is a simplified version of SortVisuals.sort() that only considers the depth property. Visuals with higher depth values will be sorted after (rendered on top of) visuals with lower depth values.

The sort is stable, preserving the relative order of visuals with equal depth values. This operation modifies the array in place.

Name Type Description
a Array<Visual> The array of visuals to sort by depth. Modified in place. If null, behavior is undefined.

Private Members

cmp(a: Visual, b: Visual): Int

Compares two visuals by depth only.

Name Type Description
a Visual First visual to compare
b Visual Second visual to compare
Returns Description
Int -1 if a has lower depth, 1 if a has higher depth, 0 if equal

rec(a: Array<Visual>, from: Int, to: Int): Void
Name Type
a Array<Visual>
from Int
to Int

doMerge(a: Array<Visual>, from: Int, pivot: Int, to: Int, len1: Int, len2: Int): Void
Name Type
a Array<Visual>
from Int
pivot Int
to Int
len1 Int
len2 Int

rotate(a: Array<Visual>, from: Int, mid: Int, to: Int): Void
Name Type
a Array<Visual>
from Int
mid Int
to Int

gcd(m: Int, n: Int): Int
Name Type
m Int
n Int
Returns
Int

upper(a: Array<Visual>, from: Int, to: Int, val: Int): Int
Name Type
a Array<Visual>
from Int
to Int
val Int
Returns
Int

lower(a: Array<Visual>, from: Int, to: Int, val: Int): Int
Name Type
a Array<Visual>
from Int
to Int
val Int
Returns
Int

swap(a: Array<Visual>, i: Int, j: Int): Void
Name Type
a Array<Visual>
i Int
j Int

compare(a: Array<Visual>, i: Int, j: Int): Int
Name Type
a Array<Visual>
i Int
j Int
Returns
Int