Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: monthly
# Nothing here is inherited by anyone using the library, so a pull
# request per transitive advisory in the docs toolchain is just
# noise. Only direct dependencies are actionable, and one grouped
# pull request a month is enough.
allow:
- dependency-type: direct
groups:
dependencies:
patterns:
- "*"
52 changes: 52 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: CI

on:
push:
branches: ["**"]
pull_request:
branches: [master]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [20, 22, 24]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm

# `npm ci` runs the `prepare` script, which builds the annotated docs,
# the library, and the example bundle. Installing is therefore also a
# build check.
- run: npm ci

- run: npm test

# The tests above check that the library works on several versions of Node.
# This job is a different question: whether the build output committed to
# the repository is what the build actually produces. It runs on a single
# version of Node, because that is the claim being made.
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm

- run: npm ci

- name: Check committed build output is current
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "Committed build output is stale."
echo "Run 'npm run build' and commit the result."
git status --short
exit 1
fi
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
JavaScript 2D Collision Detection [![Build Status][travis_image]][travis]
JavaScript 2D Collision Detection [![Build Status][ci_image]][ci]
=================================

Intersect is a collection of common 2D collision detection tests, written as a
Expand All @@ -20,10 +20,14 @@ portable to your language of choice. To get started, take a look at:
Note that the compiled JavaScript source is also available in the lib folder,
if you find TypeScript difficult to read.

If you'd rather use it than port it, it's on npm, with type declarations:

npm install @noonat/intersect

[annotated]: http://noonat.github.io/intersect
[examples]: https://github.com/noonat/intersect/blob/master/src/examples.ts
[intersect]: https://github.com/noonat/intersect/blob/master/src/intersect.ts
[rtcd]: http://realtimecollisiondetection.net/
[algorithms]: http://www.realtimerendering.com/intersections.html
[travis]: http://travis-ci.org/noonat/intersect
[travis_image]: https://secure.travis-ci.org/noonat/intersect.png?branch=master
[ci]: https://github.com/noonat/intersect/actions/workflows/ci.yml
[ci_image]: https://github.com/noonat/intersect/actions/workflows/ci.yml/badge.svg
120 changes: 75 additions & 45 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
const { execFile } = require("child_process");
const { readFile, rename, unlink, writeFile } = require("fs").promises;
const { readFile, unlink, writeFile } = require("fs").promises;
const { promisify } = require("util");
const esbuild = require("esbuild");
const md = require("markdown-it")();
const prettier = require("prettier");

async function compileHTML() {
execFile(
"docco",
[
"--css",
"template/docco.css",
"--template",
"template/docco.jst",
"src/intersect.ts.md"
],
async (err, stdout, stderr) => {
if (err) {
console.log("ERROR: docco failed");
console.log("docco stdout:", stdout);
console.log("docco stderr:", stderr);
throw err;
}
const data = await readFile("docs/src/intersect.ts.html", {
encoding: "utf-8"
});
const html = prettier.format(data, { parser: "html" });
await writeFile("index.html", html, { encoding: "utf-8" });
await unlink("docs/src/intersect.ts.html");
}
);
const isProduction = process.env.NODE_ENV === "production";

const execFileAsync = promisify(execFile);

// Each of these tools reports its own errors on stdout or stderr, and none of
// that is much use if it is thrown away, so print it before giving up.
async function run(command, args = []) {
try {
return await execFileAsync(command, args);
} catch (err) {
console.log(`ERROR: ${command} failed`);
console.log(`${command} stdout:`, err.stdout);
console.log(`${command} stderr:`, err.stderr);
throw err;
}
}

async function compileScript() {
// The literate source is the real source. Pull the code blocks back out of it
// to get something the compiler can read.
async function compileSource() {
const data = await readFile("src/intersect.ts.md");

let blocks = ['"use strict";\n\n'];
const blocks = ['"use strict";\n\n'];
md.renderer.rules = {
code_block(tokens, index) {
// We can't express empty lines for readability in Markdown, since most
Expand All @@ -47,28 +41,64 @@ async function compileScript() {
};
md.render(data.toString("UTF-8"));

const source = prettier.format(blocks.join(""), { parser: "typescript" });
const source = await prettier.format(blocks.join(""), {
parser: "typescript"
});
await writeFile("src/intersect.ts", source);
}

execFile("tsc", (err, stdout, stderr) => {
if (err) {
console.log("ERROR: tsc failed");
console.log("tsc stdout:", stdout);
console.log("tsc stderr:", stderr);
throw err;
}
async function compileHTML() {
await run("docco", [
"--css",
"template/docco.css",
"--template",
"template/docco.jst",
"src/intersect.ts.md"
]);
const data = await readFile("docs/src/intersect.ts.html", {
encoding: "utf-8"
});
const html = await prettier.format(data, { parser: "html" });
await writeFile("index.html", html, { encoding: "utf-8" });
await unlink("docs/src/intersect.ts.html");
}

execFile("webpack", (err, stdout, stderr) => {
if (err) {
console.log("ERROR: webpack failed");
console.log("webpack stdout", stdout);
console.log("webpack stderr", stderr);
throw err;
}
async function compileLibrary() {
await run("tsc");
}

async function compileExamples() {
// esbuild only strips the types off, so the examples are type checked
// separately. Without this they aren't checked by anything at all.
await run("tsc", ["--project", "tsconfig.examples.json"]);

// Importing the stylesheet writes docs/bundle.css, which the docs template
// links. Fonts larger than the inline limit are written next to it.
await esbuild.build({
assetNames: "[hash]",
bundle: true,
entryPoints: ["src/examples.ts"],
loader: {
".eot": "file",
".svg": "file",
".ttf": "file",
".woff": "file",
".woff2": "file"
},
minify: isProduction,
outfile: "docs/bundle.js",
sourcemap: !isProduction,
target: "es2015"
});
}

Promise.all([compileHTML(), compileScript()]).catch(err => {
throw err;
async function main() {
// Everything below reads src/intersect.ts, so it has to exist first.
await compileSource();
await Promise.all([compileHTML(), compileLibrary(), compileExamples()]);
}

main().catch(err => {
console.log(err.message);
process.exitCode = 1;
});
Binary file removed docs/021dd4dc61ee5f5cdf315f43b48c094b.ttf
Binary file not shown.
Binary file removed docs/1e802ca9dedc4ed4e3c6f645e4316128.woff
Binary file not shown.
Binary file removed docs/22086eb5d97009c3e99bcc1d16ce6865.woff
Binary file not shown.
Binary file added docs/222HN3GT.ttf
Binary file not shown.
Binary file removed docs/2555754a67062cac3a0913b715ab982f.woff
Binary file not shown.
Binary file removed docs/257023560753aeb0b89b7e434d3da17f.ttf
Binary file not shown.
Binary file removed docs/284a17fe5baf72ff8217d4c7e70c0f82.woff2
Binary file not shown.
Binary file removed docs/291e76b8871b84560701bd29f9d1dcc7.ttf
Binary file not shown.
Binary file removed docs/29c86397e75cdcb3135af8295f1c2e28.ttf
Binary file not shown.
Binary file added docs/2GA4IZIN.woff
Binary file not shown.
Binary file added docs/2PEIFJSJ.woff2
Binary file not shown.
Binary file added docs/2QVFK6NQ.woff2
Binary file not shown.
Binary file added docs/2TL3USAE.ttf
Binary file not shown.
Binary file removed docs/32a5339eb809f381a7357ba56f82aab3.woff2
Binary file not shown.
Binary file added docs/3F5K6SQ6.ttf
Binary file not shown.
Binary file added docs/3LKEU76G.woff
Binary file not shown.
Binary file removed docs/3fb419559955e3ce75619f1a5e8c6c84.woff
Binary file not shown.
Binary file removed docs/3fe216d2a5f736c560cde71984554b64.woff
Binary file not shown.
Binary file removed docs/4059868e460d2d2e6be18e180d20c43d.ttf
Binary file not shown.
Binary file added docs/4HRHTS65.woff
Binary file not shown.
Binary file added docs/4P4C7HJH.woff
Binary file not shown.
Binary file removed docs/4ad08b826b8065e1eab85324d726538c.woff2
Binary file not shown.
Binary file removed docs/4c57dbc44bfff1fdf08a59cf556fdab3.woff
Binary file not shown.
Binary file removed docs/4ec58befa687e9752c3c91cd9bcf1bcb.woff2
Binary file not shown.
Binary file added docs/5LRUTBFT.woff2
Binary file not shown.
Binary file added docs/5QL5CMTE.woff2
Binary file not shown.
Binary file added docs/5U4OPH2X.ttf
Binary file not shown.
Binary file removed docs/5c58d168c0b66d2c32234a6718e74dfb.ttf
Binary file not shown.
Binary file removed docs/5c734d78610fa35282f3379f866707f2.woff2
Binary file not shown.
Binary file removed docs/5c94aef490324b0925dbe5f643e8fd04.ttf
Binary file not shown.
Binary file added docs/6EBV3DK5.woff
Binary file not shown.
Binary file added docs/6KGCHLFN.woff2
Binary file not shown.
Binary file removed docs/6cc31ea5c223c88705a13727a71417fa.woff2
Binary file not shown.
Binary file removed docs/6e0830bee40435e72165345e0682fbfc.woff2
Binary file not shown.
Binary file removed docs/727a9b0d97d72d2fc0228fe4e07fb4d8.woff
Binary file not shown.
Binary file added docs/72OLXYNA.ttf
Binary file not shown.
Binary file removed docs/7342d45b052c3a2abc21049959fbab7f.ttf
Binary file not shown.
Binary file removed docs/755e2491f13b5269f0afd5a56f7aa692.woff2
Binary file not shown.
Binary file added docs/7K6AASVL.ttf
Binary file not shown.
Binary file added docs/7PGNVPQK.ttf
Binary file not shown.
Binary file removed docs/7dc027cba9f7b11ec92af4a311372a85.ttf
Binary file not shown.
Binary file removed docs/7edb53b6693d75b8a2232481eea1a52c.woff2
Binary file not shown.
Binary file removed docs/7f06b4e30317f784d61d26686aed0ab2.woff
Binary file not shown.
Binary file removed docs/8e1e01c4b1207c0a383d9a2b4f86e637.woff2
Binary file not shown.
Binary file removed docs/99be0e10c38cd42466e6fe1665ef9536.woff
Binary file not shown.
Binary file removed docs/9a2834a9ff8ab411153571e0e55ac693.ttf
Binary file not shown.
Binary file removed docs/9ceff51b3cb7ce6eb4e8efa8163a1472.ttf
Binary file not shown.
Binary file added docs/A5IFOEBS.woff
Binary file not shown.
Binary file added docs/A7XRTZ5Q.ttf
Binary file not shown.
Binary file added docs/APUWIHLP.woff2
Binary file not shown.
Binary file added docs/ARRPAO67.woff2
Binary file not shown.
Binary file added docs/CDMV7U5C.woff2
Binary file not shown.
Binary file added docs/CYEKBG2K.woff
Binary file not shown.
Binary file added docs/HMPFTM52.woff2
Binary file not shown.
Binary file added docs/I43T2HSR.ttf
Binary file not shown.
Binary file added docs/JKX5W2C4.ttf
Binary file not shown.
Binary file added docs/K4WTGH3J.woff2
Binary file not shown.
Binary file added docs/K5ZHAIS6.woff
Binary file not shown.
Binary file added docs/KKK3USB2.woff
Binary file not shown.
Binary file added docs/KX5MEWCF.woff2
Binary file not shown.
Binary file added docs/LELKET5D.woff2
Binary file not shown.
Binary file added docs/MJMFSK64.woff
Binary file not shown.
Binary file added docs/N4V3DX7S.woff2
Binary file not shown.
Binary file added docs/ODMLBJJQ.ttf
Binary file not shown.
Binary file added docs/OQCII6EP.woff
Binary file not shown.
Binary file added docs/P5I74A2A.woff
Binary file not shown.
Binary file added docs/PKMWZHNC.woff
Binary file not shown.
Binary file added docs/PQMHCIK6.woff
Binary file not shown.
Binary file added docs/PSN4QKYX.woff
Binary file not shown.
Binary file added docs/RELBIK7M.woff2
Binary file not shown.
Binary file added docs/RRNVJFFW.woff2
Binary file not shown.
Binary file added docs/SASNQFN2.woff
Binary file not shown.
Binary file added docs/SON4MRCA.ttf
Binary file not shown.
Binary file added docs/STQ6RXC7.ttf
Binary file not shown.
Binary file added docs/T4SWXBMT.woff
Binary file not shown.
Binary file added docs/TLFPAHDE.woff
Binary file not shown.
Binary file added docs/U6PRYMIZ.woff2
Binary file not shown.
Binary file added docs/UFCO6WCA.ttf
Binary file not shown.
Binary file added docs/VB447A4D.ttf
Binary file not shown.
Binary file added docs/VBYJ4NRC.woff2
Binary file not shown.
Binary file added docs/W5FBVCZM.ttf
Binary file not shown.
Binary file added docs/W74P5G27.ttf
Binary file not shown.
Binary file added docs/WGHVTYOR.ttf
Binary file not shown.
Binary file added docs/WQRQ47UD.woff2
Binary file not shown.
Binary file added docs/WTBAZBGY.ttf
Binary file not shown.
Binary file added docs/WZ3QSGD3.woff
Binary file not shown.
Binary file added docs/X5M5EMOD.woff
Binary file not shown.
Binary file added docs/XIQ62X4E.woff2
Binary file not shown.
Binary file added docs/YP5VVQRP.woff2
Binary file not shown.
Binary file added docs/ZTS3R3HK.ttf
Binary file not shown.
Binary file removed docs/a31e7cba7b7221ebf1a2ae545fb306b2.ttf
Binary file not shown.
Binary file removed docs/a48dad4f58c82e38a10da0ceebb86370.ttf
Binary file not shown.
Binary file removed docs/aaf4eee9fba9907d61c3935e0b6a54ae.ttf
Binary file not shown.
Binary file removed docs/ad7672524b64b730dfd176140a8945cb.ttf
Binary file not shown.
Binary file removed docs/b13731ef4e2bfc3d8d859271e39550fc.woff
Binary file not shown.
Binary file removed docs/b741441f6d71014d0453ca3ebc884dd4.woff
Binary file not shown.
Binary file removed docs/b7d9c46bff5d51da6209e355cc4a235d.woff
Binary file not shown.
Loading
Loading