Skip to content

Commit

Permalink
- Enhancement: ESM distribution and point to source via `package.json…
Browse files Browse the repository at this point in the history
…` `module`

- Refactoring: ESM in source; change Bezier functions to individual exports
- Docs: Fix jsdoc item; Add jsdoc config
- npm: Add `rollup` script; add it and `eslint` to test script; add `jsdoc` script and
    scripts/server for opening docs; update deps
  • Loading branch information
brettz9 committed Apr 28, 2019
1 parent 24fd7a0 commit 519dfdc
Show file tree
Hide file tree
Showing 12 changed files with 2,082 additions and 67 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ lib-cov
pids
logs
results
dist
docs/jsdoc

npm-debug.log

node_modules/
node_modules
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ Installation
API
---

This module exports two functions:
This module exports two functions:

The `intersect` function takes two shapes as an input an returns an result
The `intersect` function takes two shapes as an input an returns an result
object providing a result status, and all intersection points of the two shapes.

```intersect (shape1, shape2)```


The `shape` function wraps the necessary input parameters for each of
the two shapes. It requires the SVG element name of the shape as a string
The `shape` function wraps the necessary input parameters for each of
the two shapes. It requires the SVG element name of the shape as a string
and an object of the SVG element's attributes.

```shape (svgElementName, svgAttributes)```
Expand All @@ -37,7 +37,7 @@ Usage example
![Example image](./images/UsageExample1.png)

```javascript

var svgIntersections = require('svg-intersections');
var intersect = svgIntersections.intersect;
var shape = svgIntersections.shape;
Expand All @@ -53,6 +53,6 @@ Usage example
Credits
-------

The implementation is based on the intersection procedures by Kevin Lindsey
([http://www.kevlindev.com](www.kevlindev.com)) with contributions by
Robert Benko ([http://www.quazistax.com](www.quazistax.com)).
The implementation is based on the intersection procedures by Kevin Lindsey
([http://www.kevlindev.com](www.kevlindev.com)) with contributions by
Robert Benko ([http://www.quazistax.com](www.quazistax.com)).
28 changes: 28 additions & 0 deletions docs/jsdoc-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-env node */
'use strict';

module.exports = {
plugins: [],
recurseDepth: 10,
source: {
exclude: [
'node_modules',
'dist',
'test'
],
excludePattern: 'rollup*'
},
sourceType: 'module',
tags: {
allowUnknownTags: false
},
templates: {
cleverLinks: true,
monospaceLinks: false
},
opts: {
recurse: true,
verbose: true,
destination: 'docs/jsdoc'
}
};
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// expose module classes
import IntersectionParams from './lib/IntersectionParams';

exports.intersect = require('./lib/intersect');
exports.shape = require('./lib/IntersectionParams').newShape;
export const shape = IntersectionParams.newShape;

export {default as intersect} from './lib/intersect';
2 changes: 1 addition & 1 deletion lib/Intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ Intersection.prototype.appendPoints = function(points) {
this.points = this.points.concat(points);
};

module.exports = Intersection;
export default Intersection;
6 changes: 3 additions & 3 deletions lib/IntersectionParams.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Point2D = require('kld-affine').Point2D;
import {Point2D} from 'kld-affine';


/**
Expand Down Expand Up @@ -77,7 +77,7 @@ function getArcParameters(startPoint, endPoint, rx, ry, angle, arcFlag, sweepFla
* IntersectionParams
*
* @param {String} name
* @param {Array<Point2D} params
* @param {Array<Point2D>} params
* @returns {IntersectionParams}
*/
function IntersectionParams(name, params) {
Expand Down Expand Up @@ -890,4 +890,4 @@ RelativeSmoothCurveto3.prototype.getIntersectionParams = function() {
};


module.exports = IntersectionParams;
export default IntersectionParams;
40 changes: 17 additions & 23 deletions lib/functions/bezier.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
var Intersection = require('../Intersection');

var affine = require('kld-affine');
var Point2D = affine.Point2D;
var Vector2D = affine.Vector2D;

var Polynomial = require('kld-polynomial').Polynomial;
import Intersection from '../Intersection';
import {Point2D, Vector2D} from 'kld-affine';
import {Polynomial} from 'kld-polynomial';

function removeMultipleRootsIn01(roots) {
var ZEROepsilon = 1e-15;
Expand All @@ -19,8 +15,6 @@ function removeMultipleRootsIn01(roots) {
}
}

module.exports = {};

/**
* intersectBezier2Bezier2
*
Expand All @@ -32,7 +26,7 @@ module.exports = {};
* @param {Point2D} b3
* @returns {Intersection}
*/
module.exports.intersectBezier2Bezier2 = function(a1, a2, a3, b1, b2, b3) {
export function intersectBezier2Bezier2(a1, a2, a3, b1, b2, b3) {
var a, b;
var c12, c11, c10;
var c22, c21, c20;
Expand Down Expand Up @@ -126,7 +120,7 @@ module.exports.intersectBezier2Bezier2 = function(a1, a2, a3, b1, b2, b3) {
}

return result;
};
}


/**
Expand All @@ -141,7 +135,7 @@ module.exports.intersectBezier2Bezier2 = function(a1, a2, a3, b1, b2, b3) {
* @param {Point2D} b4
* @returns {Intersection}
*/
module.exports.intersectBezier2Bezier3 = function(a1, a2, a3, b1, b2, b3, b4) {
export function intersectBezier2Bezier3(a1, a2, a3, b1, b2, b3, b4) {
var a, b,c, d;
var c12, c11, c10;
var c23, c22, c21, c20;
Expand Down Expand Up @@ -255,7 +249,7 @@ module.exports.intersectBezier2Bezier3 = function(a1, a2, a3, b1, b2, b3, b4) {

return result;

};
}

/**
* intersectBezier2Ellipse
Expand All @@ -268,7 +262,7 @@ module.exports.intersectBezier2Bezier3 = function(a1, a2, a3, b1, b2, b3, b4) {
* @param {Number} ry
* @returns {Intersection}
*/
module.exports.intersectBezier2Ellipse = function(p1, p2, p3, ec, rx, ry) {
export function intersectBezier2Ellipse(p1, p2, p3, ec, rx, ry) {
var a, b; // temporary variables
var c2, c1, c0; // coefficients of quadratic
var result = new Intersection();
Expand Down Expand Up @@ -302,7 +296,7 @@ module.exports.intersectBezier2Ellipse = function(p1, p2, p3, ec, rx, ry) {
}

return result;
};
}


/**
Expand All @@ -315,7 +309,7 @@ module.exports.intersectBezier2Ellipse = function(p1, p2, p3, ec, rx, ry) {
* @param {Point2D} a2
* @returns {Intersection}
*/
module.exports.intersectBezier2Line = function(p1, p2, p3, a1, a2) {
export function intersectBezier2Line(p1, p2, p3, a1, a2) {
var a, b; // temporary variables
var c2, c1, c0; // coefficients of quadratic
var cl; // c coefficient for normal form of line
Expand Down Expand Up @@ -380,7 +374,7 @@ module.exports.intersectBezier2Line = function(p1, p2, p3, a1, a2) {
}

return result;
};
}


/**
Expand All @@ -396,7 +390,7 @@ module.exports.intersectBezier2Line = function(p1, p2, p3, a1, a2) {
* @param {Point2D} b4
* @returns {Intersection}
*/
module.exports.intersectBezier3Bezier3 = function(a1, a2, a3, a4, b1, b2, b3, b4) {
export function intersectBezier3Bezier3(a1, a2, a3, a4, b1, b2, b3, b4) {
var a, b, c, d; // temporary variables
var c13, c12, c11, c10; // coefficients of cubic
var c23, c22, c21, c20; // coefficients of cubic
Expand Down Expand Up @@ -695,7 +689,7 @@ module.exports.intersectBezier3Bezier3 = function(a1, a2, a3, a4, b1, b2, b3, b4
}

return result;
};
}

/**
* intersectBezier3Ellipse
Expand All @@ -709,7 +703,7 @@ module.exports.intersectBezier3Bezier3 = function(a1, a2, a3, a4, b1, b2, b3, b4
* @param {Number} ry
* @returns {Intersection}
*/
module.exports.intersectBezier3Ellipse = function(p1, p2, p3, p4, ec, rx, ry) {
export function intersectBezier3Ellipse(p1, p2, p3, p4, ec, rx, ry) {
var a, b, c, d; // temporary variables
var c3, c2, c1, c0; // coefficients of cubic
var result = new Intersection();
Expand Down Expand Up @@ -758,7 +752,7 @@ module.exports.intersectBezier3Ellipse = function(p1, p2, p3, p4, ec, rx, ry) {
}

return result;
};
}


/**
Expand All @@ -776,7 +770,7 @@ module.exports.intersectBezier3Ellipse = function(p1, p2, p3, p4, ec, rx, ry) {
* @param {Point2D} a2
* @returns {Intersection}
*/
module.exports.intersectBezier3Line = function(p1, p2, p3, p4, a1, a2) {
export function intersectBezier3Line(p1, p2, p3, p4, a1, a2) {
var a, b, c, d; // temporary variables
var c3, c2, c1, c0; // coefficients of cubic
var cl; // c coefficient for normal form of line
Expand Down Expand Up @@ -867,4 +861,4 @@ module.exports.intersectBezier3Line = function(p1, p2, p3, p4, a1, a2) {
}

return result;
};
}
24 changes: 16 additions & 8 deletions lib/intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@
* @license MIT
*/

var Point2D = require('kld-affine').Point2D;
var Vector2D = require('kld-affine').Vector2D;
var Matrix2D = require('kld-affine').Matrix2D;
var Polynomial = require('kld-polynomial').Polynomial;
var IntersectionParams = require('./IntersectionParams');
var Intersection = require('./Intersection');
var bezierIntersectionFunctions = require('./functions/bezier')
import {Point2D, Vector2D, Matrix2D} from 'kld-affine';
import {Polynomial} from 'kld-polynomial';
import IntersectionParams from './IntersectionParams';
import Intersection from './Intersection';
import {
intersectBezier2Bezier2, intersectBezier2Bezier3, intersectBezier2Ellipse,
intersectBezier2Line, intersectBezier3Bezier3, intersectBezier3Ellipse,
intersectBezier3Line
} from './functions/bezier';

var bezierIntersectionFunctions = {
intersectBezier2Bezier2, intersectBezier2Bezier3, intersectBezier2Ellipse,
intersectBezier2Line, intersectBezier3Bezier3, intersectBezier3Ellipse,
intersectBezier3Line
};

var IPTYPE = IntersectionParams.TYPE;

Expand Down Expand Up @@ -695,4 +703,4 @@ for(var key in bezierIntersectionFunctions) {
}
}

module.exports = intersect;
export default intersect;
Loading

0 comments on commit 519dfdc

Please sign in to comment.