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-sap

v2.0.0

Published

粗略碰撞检测,SAP(Sweep and Prune)正交分离轴算法,适用于基于AABB的 粗略检测 阶段

Readme

SAP 宽阶段空间索引

cj-sap 提供基于 AABB 的 Sweep and Prune(扫描与裁剪)宽阶段索引。包本身不依赖 Cocos 节点、ECS 实体或其它空间索引,可以在运行时公共层独立使用。

Body 协议

SAP 默认使用包内的 Body,也接受实现 ISpatialBody 的结构兼容对象。原有 IBody 继续只描述 AABB 数据,ISpatialBody 在此基础上增量定义:

  • 唯一 id、碰撞 group/mask
  • AABB 最小点、中点、最大点与尺寸;
  • 业务 data 和相交判断;
  • onAabbChanged/offAabbChanged 实例订阅方法。

因此同一个 Body 可以被不同空间索引复用,公共包之间无需互相依赖具体 Body 类。同一个 SAP 实例内不允许重复 id,重复插入会抛出 RangeError

示例

import { Body, SAP, SortType } from 'db://pkg/@icjhd/cj-sap';

const sap = new SAP<number>(SortType.XAxis);
const body = new Body<number>(1)
    .setData(1001)
    .setRect({ x: 0, y: 0, width: 32, height: 32 });

sap.insert(body);

console.log(sap.size());
sap.forEachBody((current) => {
    console.log(current.id, current.data);
});

forEachBody 不暴露内部数组,返回本次访问数量。遍历顺序可能随 SAP 重建而变化,业务层 不得把该顺序作为帧同步或优先级依据,也不得在访问回调中修改同一个 SAP。

insert 默认通过 onAabbChanged 自动标记排序为脏。高频同步路径可以传入 { autoRefresh: false },在批量更新 AABB 后显式调用 refreshBody(body)refreshById(id),下一次查询时再统一重建排序。

retrieve(query, out) 会继续向 out 追加结果,不会替调用方清空数组。热路径应复用数组并在 调用前显式设置 out.length = 0