ArcadeSortGroupTopBottom

ceramic.ArcadeSortGroupTopBottom (Class)

Specialized merge sort implementation for sorting physics bodies.

This class provides a stable, high-performance sort specifically optimized for Arcade physics collision detection. The implementation is based on Haxe's standard library merge sort but has been heavily optimized with inlined functions and specialized comparison logic for physics bodies.

Four different sort orders are provided:

  • ArcadeSortGroupLeftRight: Sort by X position ascending (left to right)
  • ArcadeSortGroupRightLeft: Sort by X position descending (right to left)
  • ArcadeSortGroupTopBottom: Sort by Y position ascending (top to bottom)
  • ArcadeSortGroupBottomTop: Sort by Y position descending (bottom to top)
See: ArcadeWorld for usage in collision detection

Static Members

arcade
sort(a: Array<Visual>): Void

Sorts an array of visuals by their physics body position.

This operation modifies the array in place and preserves the relative order of visuals with the same position (stable sort). Visuals without physics bodies are treated as having position 0.

Name Type Description
a Array<Visual> The array of visuals to sort

Private Members

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

Compares two visuals based on their physics body Y position.

Name Type Description
a Visual First visual to compare
b Visual Second visual to compare
Returns Description
Int 1 if a.body.y >= b.body.y, -1 otherwise, 0 if either has no body

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

arcade
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

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

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

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

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

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

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