From d9a5be34cf7e7fb0d3131de3e0226b7119bfada9 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Sun, 1 Sep 2019 12:30:21 +0300 Subject: [PATCH] add umd builds & API docs --- .gitignore | 1 + README.md | 16 ++++++++++++++-- package.json | 7 ++++++- predicates.c | 7 +------ rollup.config.js | 23 +++++++++++++++++++++++ 5 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 rollup.config.js diff --git a/.gitignore b/.gitignore index df38486..ce9e652 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules yarn.lock esm/ +umd/ diff --git a/README.md b/README.md index 715a31c..9710b4b 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,24 @@ Fast robust predicates for computational geometry in JavaScript. A modern port o - [ ] `orient3d` - [x] `incircle` - [ ] `insphere` -- [ ] API docs & demo -- [ ] minified UMD builds [![Build Status](https://travis-ci.com/mourner/robust-predicates.svg?branch=master)](https://travis-ci.com/mourner/robust-predicates) [![Simply Awesome](https://img.shields.io/badge/simply-awesome-brightgreen.svg)](https://github.com/mourner/projects) +## API + +### orient2d(ax, ay, bx, by, cx, cy) + +Return a positive value if the points `a`, `b`, and `c` occur in counterclockwise order; +a negative value if they occur in clockwise order; and zero if they are collinear. +The result is also a rough approximation of twice the signed area of the triangle defined by the three points. + +### incircle(ax, ay, bx, by, cx, cy, dx, dy) + +Return a positive value if the point `d` lies inside the circle passing through `a`, `b`, and `c`; +a negative value if it lies outside; and zero if the four points are cocircular. +The points `a`, `b`, and `c` must be in counterclockwise order, or the sign of the result will be reversed. + ## License Since the original code by J. Shewchuk is in the public domain, this port follows the same choice. See [Unlicense](https://unlicense.org) diff --git a/package.json b/package.json index c2afceb..2c49128 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,15 @@ ], "author": "Vladimir Agafonkin", "license": "Unlicense", + "main": "umd/predicates.js", + "unpkg": "umd/predicates.min.js", "module": "index.js", "scripts": { "build": "mkdirp esm && node compile.js", "lint": "eslint *.js esm src", "test": "npm run build && npm run lint && node -r esm test.js", - "bench": "node -r esm bench.js" + "bench": "node -r esm bench.js", + "prepublishOnly": "rollup -c" }, "devDependencies": { "eslint": "^6.3.0", @@ -22,6 +25,8 @@ "mkdirp": "^0.5.1", "nextafter": "^1.0.0", "robust-orientation": "^1.1.3", + "rollup": "^1.20.3", + "rollup-plugin-terser": "^5.1.1", "tape": "^4.11.0", "terser": "^4.2.1" }, diff --git a/predicates.c b/predicates.c index e251b55..a0d7d9c 100644 --- a/predicates.c +++ b/predicates.c @@ -1103,8 +1103,6 @@ REAL *pd; /*****************************************************************************/ /* */ /* incirclefast() Approximate 2D incircle test. Nonrobust. */ -/* incircleexact() Exact 2D incircle test. Robust. */ -/* incircleslow() Another exact 2D incircle test. Robust. */ /* incircle() Adaptive exact 2D incircle test. Robust. */ /* */ /* Return a positive value if the point pd lies inside the */ @@ -1113,10 +1111,7 @@ REAL *pd; /* The points pa, pb, and pc must be in counterclockwise */ /* order, or the sign of the result will be reversed. */ /* */ -/* Only the first and last routine should be used; the middle two are for */ -/* timings. */ -/* */ -/* The last three use exact arithmetic to ensure a correct answer. The */ +/* The second one uses exact arithmetic to ensure a correct answer. The */ /* result returned is the determinant of a matrix. In incircle() only, */ /* this determinant is computed adaptively, in the sense that exact */ /* arithmetic is used only to the degree it is needed to ensure that the */ diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..a84a436 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,23 @@ +import {terser} from 'rollup-plugin-terser'; + +const output = (input, file, plugins) => ({ + input, + output: { + name: 'predicates', + format: 'umd', + indent: false, + file, + }, + plugins +}); + +const builds = (input, name) => [ + output(input, `umd/${name}.js`, []), + output(input, `umd/${name}.min.js`, [terser()]) +]; + +export default [ + ...builds('index.js', 'predicates'), + ...builds('esm/orient2d.js', 'orient2d'), + ...builds('esm/incircle.js', 'incircle') +];