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
Copy file name to clipboardExpand all lines: docs/SPATIAL_WARFARE.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,66 @@ Welcome to the Spatial Warfare Division, pilot. You've been equipped with Active
8
8
9
9
## 🎯 The Advanced Weapons Systems
10
10
11
+
### The <-> Operator - Quantum Targeting System
12
+
13
+
Before we dive into the standard weapons, let me introduce you to the most powerful targeting system in the fleet: the K-Nearest Neighbor operator, `<->`. While other systems calculate distances in real-time (burning precious CPU cycles), this quantum targeting array uses spatial indexes to lock onto targets at warp speed.
14
+
15
+
```ruby
16
+
# Traditional targeting (slow, scans entire space)
# "The <-> operator doesn't calculate distances—it uses the spatial index
50
+
# to teleport directly to the answer. It's the difference between searching
51
+
# every star in the galaxy versus knowing exactly which ones are closest."
52
+
```
53
+
54
+
**Critical Intelligence**: The `<->` operator returns results ordered by distance but doesn't give you the actual distance value. If you need both speed AND distance:
55
+
56
+
```ruby
57
+
# Get nearest ships with their distances
58
+
Starship
59
+
.select(
60
+
"*",
61
+
"ST_Distance(position, ST_GeomFromText('#{origin.as_text}', 4326)) as distance_meters"
62
+
)
63
+
.order(
64
+
arel_table[:position].distance_operator(origin)
65
+
)
66
+
.limit(10)
67
+
```
68
+
69
+
## 🎯 Standard Weapons Arsenal
70
+
11
71
### ST_Intersects - The Collision Detection Array
12
72
13
73
Every good pilot knows: space is big, but not big enough when two fleets converge on the same coordinates.
0 commit comments