@@ -156,6 +156,11 @@ impl PhysicsWorld2D {
156156
157157 /// Returns all bodies whose colliders contain the provided point.
158158 ///
159+ /// Point queries are intended for gameplay checks that can be called freely
160+ /// during update code. Treating invalid floating-point input as a miss keeps
161+ /// the public API simple for callers and avoids forcing game code to thread
162+ /// backend validation errors through every query site.
163+ ///
159164 /// # Arguments
160165 /// - `point`: The world-space point to test.
161166 ///
@@ -166,12 +171,22 @@ impl PhysicsWorld2D {
166171 return Vec :: new ( ) ;
167172 }
168173
174+ // Backend queries operate in collider space, but the public API reports
175+ // owning bodies. Rebuild body handles and collapse duplicate hits from
176+ // compound colliders before returning the result.
169177 let body_slots = self . backend . query_point_2d ( point) ;
170178 return self . deduplicate_query_body_hits ( body_slots) ;
171179 }
172180
173181 /// Returns all bodies whose colliders overlap the provided axis-aligned box.
174182 ///
183+ /// AABB queries are meant to be tolerant of how gameplay code produces
184+ /// bounds. The world normalizes `min` and `max` before delegating so callers
185+ /// can pass corners in either order without adding their own pre-processing.
186+ /// Invalid floating-point inputs are treated as a miss for the same reason as
187+ /// `query_point()`: query call sites stay straightforward and do not need to
188+ /// handle backend-specific error types.
189+ ///
175190 /// # Arguments
176191 /// - `min`: The minimum world-space corner of the query box.
177192 /// - `max`: The maximum world-space corner of the query box.
@@ -183,6 +198,7 @@ impl PhysicsWorld2D {
183198 return Vec :: new ( ) ;
184199 }
185200
201+ // Normalize the query box so callers do not need to sort the bounds first.
186202 let normalized_min = [ min[ 0 ] . min ( max[ 0 ] ) , min[ 1 ] . min ( max[ 1 ] ) ] ;
187203 let normalized_max = [ min[ 0 ] . max ( max[ 0 ] ) , min[ 1 ] . max ( max[ 1 ] ) ] ;
188204 let body_slots = self . backend . query_aabb_2d ( normalized_min, normalized_max) ;
@@ -192,17 +208,19 @@ impl PhysicsWorld2D {
192208
193209 /// Returns the nearest rigid body hit by the provided ray.
194210 ///
211+ /// Raycasts are exposed as a lightweight gameplay query rather than a
212+ /// fallible backend operation. Inputs that cannot represent a meaningful
213+ /// finite segment are treated as a miss, and the backend hit is rebound to
214+ /// this world's public body handles before returning so the high-level API
215+ /// stays vendor-free.
216+ ///
195217 /// # Arguments
196218 /// - `origin`: The ray origin in world space.
197219 /// - `dir`: The ray direction in world space.
198220 /// - `max_dist`: The maximum query distance.
199221 ///
200222 /// # Returns
201223 /// Returns the nearest hit, if one exists.
202- ///
203- /// This method preserves an infallible query contract for games: invalid
204- /// inputs return `None` instead of surfacing backend-specific validation
205- /// errors through the high-level API.
206224 pub fn raycast (
207225 & self ,
208226 origin : [ f32 ; 2 ] ,
@@ -245,6 +263,8 @@ impl PhysicsWorld2D {
245263 slot_generation,
246264 ) ;
247265
266+ // Spatial queries match colliders internally, but the public surface is
267+ // body-oriented. Compound bodies therefore collapse to one handle.
248268 if seen_bodies. insert ( body) {
249269 bodies. push ( body) ;
250270 }
0 commit comments