npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@icjhd/cj-quadtree

v2.0.0

Published

四叉树碰撞检测模块

Downloads

166

Readme

四叉树碰撞检测模块

前置条件

游戏引擎 开发框架

使用案例

import { Body, QuadTree } from 'db://pkg/@icjhd/cj-quadtree';

const tree = new QuadTree<number>(0, 0, 1000, 1000, 6);
const body = new Body<number>(1)
    .setData(1001)
    .setRect({ x: 10, y: 20, width: 40, height: 60 });

tree.insert(body);
tree.forEachBody((item) => console.log(item.id, item.data));
tree.visitCellBounds((bounds) => console.log(bounds));

跨空间包复用 Body

QuadTree 的第二个泛型参数接受满足 ISpatialBody<T> 的纯结构对象,不要求继承本包的 Body。因此其它空间索引包的 Body 可以直接复用,cj-quadtree 不需要依赖这些包:

import { Body as SapBody } from 'db://pkg/@icjhd/cj-sap';
import { QuadTree } from 'db://pkg/@icjhd/cj-quadtree';

const tree = new QuadTree<number, SapBody<number>>(0, 0, 1000, 1000, 6);
const body = new SapBody<number>(1).setData(1001).setRect({ x: 10, y: 20, width: 40, height: 60 });

tree.insert(body); // 无需 any 转换,并继续自动监听 AABB 变化。

同一棵树内的 Body ID 必须唯一。重复插入相同 ID 会抛出 RangeError,避免旧节点残留为 无法移除的“幽灵节点”。

公共诊断能力

  • size():返回当前碰撞体数量。
  • forEachBody(visitor, target?):访问当前持有的碰撞体,不暴露内部容器。
  • visitCellBounds(visitor, limit?):访问已创建的树单元边界,供调试绘制使用,默认最多 4096 个。

这些遍历 API 不承诺可用于权威碰撞结果的稳定排序。帧同步业务应在消费候选集前按稳定业务键排序。