You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Backport retail's UnitDistanceSquared(unit) -> (distanceSquared,
checkedPosition): the squared world distance from the player to the unit,
plus a flag for whether both positions were readable. Squared because
almost all distance logic is a threshold compare or nearest-unit sort,
neither of which needs the sqrt — which is why retail never shipped a plain
UnitDistance.
Added to the existing Unit::Range module alongside UnitInRange (both now
share one PlayerToUnitDistSq compute off the CGObject::GetPosition vtable
virtual). Center-to-center, self-contained (reads the position in C — no
SuperWoW dependency, and leaves SuperWoW's own UnitPosition untouched).
Verified in-game to match SuperWoW UnitPosition math to float precision.
On a position miss returns (0, false); no self-quirk, so
UnitDistanceSquared("player") is a legitimate (0, true).
|`distanceSquared`| Squared distance player→unit. `0` when `checkedPosition` is `false` (a placeholder — matches retail's "always a number" shape). |
10231
+
|`checkedPosition`|`true` when both positions were read. `false` when `unit`'s position isn't available (empty `partyN` slot, no target, raid member outside the sync window, etc.). |
10232
+
10233
+
The value is **squared** on purpose: nearly all distance logic is a
10234
+
threshold compare (`distSq <= range * range`) or a nearest-unit sort,
10235
+
neither of which needs the square root — so retail exposes only the
10236
+
squared form (added 5.0.4) and never a plain `UnitDistance`. Take
10237
+
`math.sqrt(distanceSquared)` only when you need a yard number to show a
10238
+
human.
10239
+
10240
+
Reads world positions via the `CGObject::GetPosition` vtable virtual
10241
+
(slot 5, offset `+0x14`) — the same path `UnitInRange` /
10242
+
`CheckInteractDistance` use. **Center-to-center**, not reach-aware (that
10243
+
edge-to-edge nicety is UnitXP_SP3's niche); the value equals what you'd
10244
+
compute from SuperWoW's `UnitPosition`, but it's self-contained (no
10245
+
sibling-DLL dependency, and no clash with SuperWoW's own `UnitPosition`,
10246
+
which is left untouched).
10247
+
10248
+
> No self-quirk (unlike `UnitInRange`): `UnitDistanceSquared("player")`
10249
+
> returns a legitimate `(0, true)`. Because a real `0` (self, or two
10250
+
> exactly co-located units) is indistinguishable by value from the miss
10251
+
> placeholder, always branch on `checkedPosition`.
10252
+
10214
10253
### `UnitClassBase(unit)`
10215
10254
10216
10255
Returns `(classFile, classID)` — the locale-independent class
0 commit comments