Skip to content

[Feature] Allocation-sensitive 2D query APIs #210

@vmarcella

Description

@vmarcella

Overview

Add non-allocating or caller-owned-buffer variants of 2D spatial queries so
hot gameplay paths can avoid per-query heap allocations.

Current State

query_point() and query_aabb() return Vec<RigidBody2D>, which is simple
and appropriate for most users, but not ideal for performance-sensitive loops.

Scope

Goals:

  • Add query variants that write into caller-owned buffers or invoke callbacks
  • Preserve the existing ergonomic Vec-returning methods
  • Keep the public API body-oriented and backend-agnostic

Non-Goals:

  • Removing the current convenience APIs
  • Query-side filtering if handled in a separate issue
  • Unsafe APIs in the first iteration

Proposed API

impl PhysicsWorld2D {
  pub fn query_point_into(
    &self,
    point: [f32; 2],
    out: &mut Vec<RigidBody2D>,
  );

  pub fn query_aabb_into(
    &self,
    min: [f32; 2],
    max: [f32; 2],
    out: &mut Vec<RigidBody2D>,
  );

  pub fn query_point_each(
    &self,
    point: [f32; 2],
    visit: impl FnMut(RigidBody2D),
  );
}

Acceptance Criteria

  • Non-allocating query variants are added and documented
  • Existing query methods keep their current semantics
  • Compound-body deduplication is preserved in all variants
  • Benchmarks or profiling notes justify the added API surface
  • Tests cover equivalent results across allocating and non-allocating
    paths

Affected Crates

lambda-rs, lambda-rs-platform

Notes

  • A callback-based API may avoid exposing buffer management concerns.
  • This work should be driven by profiling.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestlambda-rsIssues pertaining to the core frameworklambda-rs-platformIssues pertaining to the dependency & platform wrappers

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions